com.regnosys.rosetta.translate.synonymmap.Element Maven / Gradle / Ivy
package com.regnosys.rosetta.translate.synonymmap;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import com.regnosys.rosetta.translate.datamodel.Cardinality;
import com.regnosys.rosetta.translate.datamodel.Entity;
/**
* @author TomForwood
* This class represents the link between a name in a synonym - the name and the input schema entity that it links to
* used when building the synonym map
*
*/
public class Element {
private final String name;
private Entity entity;
private Cardinality cardinality;
public Element(String name, Entity entity) {
this(name);
this.entity = entity;
}
public Element(String name) {
this.name = name;
}
public Entity getEntity() {
return entity;
}
public Cardinality getCardinality() {
return cardinality;
}
public void setEntity(Entity entity, Cardinality cardinality) {
this.entity = entity;
this.cardinality = cardinality;
}
public String getName() {
return name;
}
public static List toElementList(String path) {
if(path.contains("."))
throw new RuntimeException("Path may not contain dot chars: " + path);
return Arrays.stream(path.split(SynonymTest.PATH_SEPARATOR)).map(s->new Element (s)).collect(Collectors.toList());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((entity == null) ? 0 : entity.hashCode());
result = prime * result + ((name == null) ? 0 : name.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;
Element other = (Element) obj;
if (entity == null) {
if (other.entity != null)
return false;
} else if (!entity.equals(other.entity))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
String ent = entity==null?"null":entity.getName().toString();
return "Element [name=" + name + ", entity=" + ent + "]";
}
}