com.regnosys.rosetta.translate.synonymmap.AttributeGroup Maven / Gradle / Ivy
The newest version!
package com.regnosys.rosetta.translate.synonymmap;
import java.util.*;
import java.util.stream.Collectors;
import com.google.common.collect.Ordering;
import com.regnosys.rosetta.generator.object.ExpandedAttribute;
public class AttributeGroup implements Comparable {
/**
* Single path, defined as a list of attributes
*/
private final List attributePath;
/**
* List of synonym groups. Each attribute can have multiple synonym rows
* associated with it
*/
private final List synonymGroups;
public AttributeGroup(List synonymGroups, List attributePath) {
//this.synonymGroups = synonymGroups;
this.attributePath = attributePath;
Set sgSet = new LinkedHashSet<>(synonymGroups);//pass the groups through a set in order to remove duplicates
this.synonymGroups = new ArrayList<>(sgSet);
}
public List getSynonymGroups() {
return synonymGroups;
}
public List getAttributePath() {
return attributePath;
}
public String attsToString() {
return attributePath.stream().map(att -> attToString(att)).collect(Collectors.joining(", "));
}
private String attToString(ExpandedAttribute att) {
return att.getName() + (att.getSup() > 1 ? "*" : "");
}
public static String attributeName(ExpandedAttribute att) {
String name = att.getName();
return name;
}
@Override
public String toString() {
String atts = attsToString();
return synonymGroups + "[" + atts + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((attributePath == null) ? 0 : attributePath.hashCode());
result = prime * result + ((synonymGroups == null) ? 0 : synonymGroups.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AttributeGroup other = (AttributeGroup) obj;
if (attributePath == null) {
if (other.attributePath != null)
return false;
} else if (!attributePath.equals(other.attributePath))
return false;
if (synonymGroups == null) {
if (other.synonymGroups != null)
return false;
} else if (!synonymGroups.equals(other.synonymGroups))
return false;
return true;
}
private static final Comparator COMPARATOR =
Comparator
.comparing(
AttributeGroup::getAttributePath,
Ordering.from(Comparator.comparing(ExpandedAttribute::getName)).lexicographical())
.thenComparing(
AttributeGroup::getSynonymGroups,
Ordering.from(Comparator.comparing(SynonymGroup::toString)).lexicographical());
@Override
public int compareTo(AttributeGroup l2) {
return COMPARATOR.compare(this, l2);
}
public boolean startsWith(String string) {
return attributePath.size() > 0 && attributePath.get(0).getName().equals(string);
}
public long hashForGeneration() {
long result = 0;
for (ExpandedAttribute expandedAttribute : attributePath) {
result += expandedAttribute.getName().hashCode();
String enclosingType = expandedAttribute.getEnclosingType();
if (enclosingType!=null) {
result += enclosingType.hashCode();
}
}
result *= 8191;
for (SynonymGroup sg : synonymGroups) {
result += sg.hashForGeneration();
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy