Skip to content

Commit

Permalink
Modernize and reflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Nov 20, 2024
1 parent 21dfc9f commit 55191a2
Showing 1 changed file with 28 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ConfigurationPropertyImpl> properties;
private Map<String, ConfigurationPropertyImpl> 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<ConfigurationPropertyImpl>, Serializable {
public void setProperties(final Collection<ConfigurationPropertyImpl> in) {
List<ConfigurationPropertyImpl> 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<ConfigurationPropertyImpl> COMPARATOR =
new PropertyComparator();

public void setProperties(Collection<ConfigurationPropertyImpl> in) {
List<ConfigurationPropertyImpl> properties = new ArrayList<ConfigurationPropertyImpl>(in);
Collections.sort(properties, COMPARATOR);
LinkedHashMap<String, ConfigurationPropertyImpl> temp =
new LinkedHashMap<String, ConfigurationPropertyImpl>();
for (ConfigurationPropertyImpl property : properties) {
temp.put(property.getName(), property);
property.setParent(this);
}
Map<String, ConfigurationPropertyImpl> temp = new LinkedHashMap<>();
props.forEach(prop -> {
temp.put(prop.getName(), prop);
prop.setParent(this);
});
this.properties = temp;
}

Expand All @@ -102,7 +90,7 @@ public Collection<ConfigurationPropertyImpl> getProperties() {
* {@inheritDoc}
*/
@Override
public ConfigurationProperty getProperty(String name) {
public ConfigurationProperty getProperty(final String name) {
return properties.get(name);
}

Expand All @@ -111,41 +99,34 @@ public ConfigurationProperty getProperty(String name) {
*/
@Override
public List<String> getPropertyNames() {
List<String> names = new ArrayList<String>(properties.keySet());
List<String> 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<ConfigurationPropertyImpl> set1 =
new HashSet<ConfigurationPropertyImpl>(properties.values());
HashSet<ConfigurationPropertyImpl> set2 =
new HashSet<ConfigurationPropertyImpl>(other.properties.values());
Set<ConfigurationPropertyImpl> set1 = new HashSet<>(properties.values());
Set<ConfigurationPropertyImpl> set2 = new HashSet<>(other.properties.values());
return set1.equals(set2);
}
return false;
}

@Override
public int hashCode() {
HashSet<ConfigurationPropertyImpl> set1 =
new HashSet<ConfigurationPropertyImpl>(properties.values());
Set<ConfigurationPropertyImpl> set1 = new HashSet<>(properties.values());
return set1.hashCode();
}
}

0 comments on commit 55191a2

Please sign in to comment.