package org.ntlab.rdlcanvas.models;
public class RDLSpecResourceDeclaration implements RDLSpecStatement {
private RDLSpecResource resource;
private RDLSpecResource primedResource;
public RDLSpecResourceDeclaration(String name, int order, StructuralType structuralType, ValueType valueType) {
resource = new RDLSpecResource(name, order, structuralType, valueType);
if (structuralType == StructuralType.id) {
primedResource = new RDLSpecResource(name + "'", order, structuralType, valueType);
} else {
primedResource = null;
}
}
public RDLSpecResourceDeclaration(String name, int order, ValueType valueType) {
resource = new RDLSpecResource(name, order, valueType);
primedResource = null;
}
public RDLSpecResource getResource() {
return resource;
}
public RDLSpecResource getPrimedResource() {
return primedResource;
}
@Override
public boolean isRDLSpecInitialization() {
return false;
}
@Override
public boolean isRDLSpecResourceDeclaration() {
return true;
}
@Override
public boolean equals(Object another) {
if (!(another instanceof RDLSpecResourceDeclaration rdlSpecResourceDeclaration)) {
return false;
}
if (rdlSpecResourceDeclaration.getResource().equals(resource) && ((rdlSpecResourceDeclaration.getPrimedResource() == null && primedResource == null) || rdlSpecResourceDeclaration.getPrimedResource().equals(primedResource))) {
return true;
} else {
return false;
}
}
@Override
public int hashCode() {
return toString().hashCode();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(resource).append("(").append(resource.getOrder()).append("):: ");
if (resource.getStructuralType() == StructuralType.primitive) {
sb.append(resource.getValueType().getName());
return sb.toString();
}
if (resource.getValueType() == null) {
sb.append(resource.getStructuralType());
return sb.toString();
} else {
sb.append(resource.getStructuralType());
sb.append(", ").append(resource.getValueType().getName());
return sb.toString();
}
}
}