com.regnosys.rosetta.translate.datamodel.json.SimpleJsonEntity Maven / Gradle / Ivy
package com.regnosys.rosetta.translate.datamodel.json;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import com.regnosys.rosetta.translate.datamodel.Attribute;
import com.regnosys.rosetta.translate.datamodel.BasicType;
import com.regnosys.rosetta.translate.datamodel.Entity;
import com.regnosys.rosetta.translate.datamodel.NamespaceName;
/**
*
* Currently only string.
* To be extended with the rest of JSON simple types: boolean, number, null, (array?)
*
* @author nikos
*
*/
public class SimpleJsonEntity implements Entity {
private final NamespaceName name;
private final BasicType type;
//
// private final static Map simpleTypes = new HashMap<>();
private SimpleJsonEntity(String name, BasicType type) {
this.name = new NamespaceName("", name);
this.type = type;
// simpleTypes.put(name, this);
}
public static Entity stringType(String name) {
return new SimpleJsonEntity(name, BasicType.STRING);
}
@Override
public NamespaceName getName() {
return name;
}
@Override
public List getAttributes() {
return Collections.emptyList();
}
@Override
public void addAttribute(Attribute att) {
throw new UnsupportedOperationException("N/A");
}
@Override
public Entity getExtendedEntity() {
throw new UnsupportedOperationException("N/A");
}
@Override
public List getKnownExtendingEntities() {
return Collections.emptyList();
}
@Override
public boolean hasChild() {
return false;
}
@Override
public boolean hasData() {
return true;
}
public BasicType getType() {
return type;
}
@Override
public String toString() {
return name + "(" + type + ")";
}
@Override
public boolean equals(final Object other) {
if (other == this) {
return true;
}
if (!(other instanceof SimpleJsonEntity)) {
return false;
}
SimpleJsonEntity otherP = (SimpleJsonEntity) other;
return Objects.equals(name, otherP.name) && Objects.equals(type, otherP.type);
}
@Override
public int hashCode() {
return Objects.hash(name, type);
}
@Override
public String toString(Set alreadyWritten) {
return toString();
}
}