From 55191a2ee38b9ad86ae7eb954e0c0878b3554708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Wed, 20 Nov 2024 16:09:02 +0100 Subject: [PATCH] Modernize and reflow --- .../impl/api/ConfigurationPropertiesImpl.java | 75 +++++++------------ 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/java/connector-framework-internal/src/main/java/org/identityconnectors/framework/impl/api/ConfigurationPropertiesImpl.java b/java/connector-framework-internal/src/main/java/org/identityconnectors/framework/impl/api/ConfigurationPropertiesImpl.java index 3bee3ee9..351a2262 100644 --- a/java/connector-framework-internal/src/main/java/org/identityconnectors/framework/impl/api/ConfigurationPropertiesImpl.java +++ b/java/connector-framework-internal/src/main/java/org/identityconnectors/framework/impl/api/ConfigurationPropertiesImpl.java @@ -19,75 +19,63 @@ * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * ==================== + * Portions Copyrighted 2024 ConnId */ package org.identityconnectors.framework.impl.api; -import java.io.Serializable; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; - +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import org.identityconnectors.common.CollectionUtil; import org.identityconnectors.framework.api.ConfigurationProperties; import org.identityconnectors.framework.api.ConfigurationProperty; public class ConfigurationPropertiesImpl implements ConfigurationProperties { + private static final String MSG = "Property ''{0}'' does not exist."; + // ======================================================================= // Fields // ======================================================================= /** * Properties, listed in order by their "order" attribute */ - LinkedHashMap properties; + private Map properties; /** - * The container. Not serialized in this object. Set when this property is - * added to parent + * The container. Not serialized in this object. Set when this property is added to parent */ private transient APIConfigurationImpl parent; // ======================================================================= // Internal Methods // ======================================================================= - public APIConfigurationImpl getParent() { return parent; } - public void setParent(APIConfigurationImpl parent) { + public void setParent(final APIConfigurationImpl parent) { this.parent = parent; } - private static class PropertyComparator implements Comparator, Serializable { + public void setProperties(final Collection in) { + List props = in.stream(). + sorted(Comparator.comparing(ConfigurationPropertyImpl::getOrder)). + collect(Collectors.toList()); - private static final long serialVersionUID = 1L; - - @Override - public int compare(final ConfigurationPropertyImpl o1, final ConfigurationPropertyImpl o2) { - int or1 = o1.getOrder(); - int or2 = o2.getOrder(); - return or1 < or2 ? -1 : or1 > or2 ? 1 : 0; - } - } - - private static final Comparator COMPARATOR = - new PropertyComparator(); - - public void setProperties(Collection in) { - List properties = new ArrayList(in); - Collections.sort(properties, COMPARATOR); - LinkedHashMap temp = - new LinkedHashMap(); - for (ConfigurationPropertyImpl property : properties) { - temp.put(property.getName(), property); - property.setParent(this); - } + Map temp = new LinkedHashMap<>(); + props.forEach(prop -> { + temp.put(prop.getName(), prop); + prop.setParent(this); + }); this.properties = temp; } @@ -102,7 +90,7 @@ public Collection getProperties() { * {@inheritDoc} */ @Override - public ConfigurationProperty getProperty(String name) { + public ConfigurationProperty getProperty(final String name) { return properties.get(name); } @@ -111,32 +99,26 @@ public ConfigurationProperty getProperty(String name) { */ @Override public List getPropertyNames() { - List names = new ArrayList(properties.keySet()); + List names = new ArrayList<>(properties.keySet()); return CollectionUtil.newReadOnlyList(names); } - private static final String MSG = "Property ''{0}'' does not exist."; - /** * {@inheritDoc} */ @Override - public void setPropertyValue(String name, Object value) { - ConfigurationPropertyImpl property = properties.get(name); - if (property == null) { - throw new IllegalArgumentException(MessageFormat.format(MSG, name)); - } + public void setPropertyValue(final String name, final Object value) { + ConfigurationPropertyImpl property = Optional.ofNullable(properties.get(name)). + orElseThrow(() -> new IllegalArgumentException(MessageFormat.format(MSG, name))); property.setValue(value); } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (o instanceof ConfigurationPropertiesImpl) { ConfigurationPropertiesImpl other = (ConfigurationPropertiesImpl) o; - HashSet set1 = - new HashSet(properties.values()); - HashSet set2 = - new HashSet(other.properties.values()); + Set set1 = new HashSet<>(properties.values()); + Set set2 = new HashSet<>(other.properties.values()); return set1.equals(set2); } return false; @@ -144,8 +126,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - HashSet set1 = - new HashSet(properties.values()); + Set set1 = new HashSet<>(properties.values()); return set1.hashCode(); } }