From b8e4909d7723ad4bffcae324ade14d94d837e6da Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Thu, 9 Jan 2020 15:27:17 +0200 Subject: [PATCH] Implement equals/hashCode for PropertyInfo gitlab #442 Change-Id: I6f6d2fc1f7266dbdd7bacf24751d9ab6b9dd94ac --- .../db/layer0/request/PropertyInfo.java | 238 ++++++++++++------ 1 file changed, 165 insertions(+), 73 deletions(-) diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java index 4d208b457..6ecfb8ead 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java @@ -28,79 +28,171 @@ import org.simantics.layer0.Layer0; import org.simantics.utils.datastructures.Pair; public class PropertyInfo { - public final Resource predicate; - public final String name; - public final boolean isHasProperty; - public final boolean isFunctional; - public final Set classifications; - public final VariableBuilder builder; - public final Resource literalRange; - public final Datatype requiredDatatype; - public final String requiredValueType; - public final String definedUnit; - public final Binding defaultBinding; - public final Map> subliteralPredicates; - public final ValueAccessor valueAccessor; - public final boolean hasEnumerationRange; - public PropertyInfo(Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) { - this.predicate = predicate; - this.name = name; - this.isFunctional = isFunctional; - this.isHasProperty = isHasProperty; - this.classifications = classifications; - this.builder = builder; - this.literalRange = literalRange; - this.requiredDatatype = requiredDatatype; - this.definedUnit = definedUnit; - this.requiredValueType = requiredValueType; - this.defaultBinding = defaultBinding; - this.subliteralPredicates = subliteralPredicates; - this.valueAccessor = valueAccessor; - this.hasEnumerationRange = hasEnumerationRange; - } - public static PropertyInfo make(ReadGraph graph, Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) throws DatabaseException { + public final Resource predicate; + public final String name; + public final boolean isHasProperty; + public final boolean isFunctional; + public final Set classifications; + public final VariableBuilder builder; + public final Resource literalRange; + public final Datatype requiredDatatype; + public final String requiredValueType; + public final String definedUnit; + public final Binding defaultBinding; + public final Map> subliteralPredicates; + public final ValueAccessor valueAccessor; + public final boolean hasEnumerationRange; + public PropertyInfo(Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) { + this.predicate = predicate; + this.name = name; + this.isFunctional = isFunctional; + this.isHasProperty = isHasProperty; + this.classifications = classifications; + this.builder = builder; + this.literalRange = literalRange; + this.requiredDatatype = requiredDatatype; + this.definedUnit = definedUnit; + this.requiredValueType = requiredValueType; + this.defaultBinding = defaultBinding; + this.subliteralPredicates = subliteralPredicates; + this.valueAccessor = valueAccessor; + this.hasEnumerationRange = hasEnumerationRange; + } + public static PropertyInfo make(ReadGraph graph, Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - if(literalRange != null) { - Collection dts = graph.getAssertedObjects(literalRange, L0.HasDataType); - if(dts.size() == 1) { - Datatype dt = graph.getPossibleValue(dts.iterator().next(), Bindings.DATATYPE); - if(requiredDatatype == null) requiredDatatype = dt; - } - } - - Binding defaultBinding = requiredDatatype != null ? Bindings.getBinding(requiredDatatype) : null; - - return new PropertyInfo(predicate, name, isFunctional, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange); + Layer0 L0 = Layer0.getInstance(graph); + if(literalRange != null) { + Collection dts = graph.getAssertedObjects(literalRange, L0.HasDataType); + if(dts.size() == 1) { + Datatype dt = graph.getPossibleValue(dts.iterator().next(), Bindings.DATATYPE); + if(requiredDatatype == null) requiredDatatype = dt; + } + } + + Binding defaultBinding = requiredDatatype != null ? Bindings.getBinding(requiredDatatype) : null; + + return new PropertyInfo(predicate, name, isFunctional, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange); - } - public boolean hasClassification(String classification) { - return classifications.contains(classification); - } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("PropertyInfo [") - .append(name) - .append(" : ") - .append(requiredDatatype) - .append(" :: ") - .append(requiredValueType) - .append(", predicate=") - .append(predicate) - .append(", isFunctional=") - .append(isFunctional) - .append(", isHasProperty=") - .append(isHasProperty) - .append(", hasEnumerationRange=") - .append(hasEnumerationRange) - .append(", definedUnit=") - .append(definedUnit != null ? definedUnit : "") - .append(", defaultBinding=") - .append(defaultBinding) - .append(", valueAccessor=") - .append(valueAccessor) - .append("]"); - return sb.toString(); - } + } + public boolean hasClassification(String classification) { + return classifications.contains(classification); + } + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("PropertyInfo [") + .append(name) + .append(" : ") + .append(requiredDatatype) + .append(" :: ") + .append(requiredValueType) + .append(", predicate=") + .append(predicate) + .append(", isFunctional=") + .append(isFunctional) + .append(", isHasProperty=") + .append(isHasProperty) + .append(", hasEnumerationRange=") + .append(hasEnumerationRange) + .append(", definedUnit=") + .append(definedUnit != null ? definedUnit : "") + .append(", defaultBinding=") + .append(defaultBinding) + .append(", valueAccessor=") + .append(valueAccessor) + .append("]"); + return sb.toString(); + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((builder == null) ? 0 : builder.hashCode()); + result = prime * result + ((classifications == null) ? 0 : classifications.hashCode()); + result = prime * result + ((defaultBinding == null) ? 0 : defaultBinding.hashCode()); + result = prime * result + ((definedUnit == null) ? 0 : definedUnit.hashCode()); + result = prime * result + (hasEnumerationRange ? 1231 : 1237); + result = prime * result + (isFunctional ? 1231 : 1237); + result = prime * result + (isHasProperty ? 1231 : 1237); + result = prime * result + ((literalRange == null) ? 0 : literalRange.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((predicate == null) ? 0 : predicate.hashCode()); + result = prime * result + ((requiredDatatype == null) ? 0 : requiredDatatype.hashCode()); + result = prime * result + ((requiredValueType == null) ? 0 : requiredValueType.hashCode()); + result = prime * result + ((subliteralPredicates == null) ? 0 : subliteralPredicates.hashCode()); + result = prime * result + ((valueAccessor == null) ? 0 : valueAccessor.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; + PropertyInfo other = (PropertyInfo) obj; + if (builder == null) { + if (other.builder != null) + return false; + } else if (!builder.equals(other.builder)) + return false; + if (classifications == null) { + if (other.classifications != null) + return false; + } else if (!classifications.equals(other.classifications)) + return false; + if (defaultBinding == null) { + if (other.defaultBinding != null) + return false; + } else if (!defaultBinding.equals(other.defaultBinding)) + return false; + if (definedUnit == null) { + if (other.definedUnit != null) + return false; + } else if (!definedUnit.equals(other.definedUnit)) + return false; + if (hasEnumerationRange != other.hasEnumerationRange) + return false; + if (isFunctional != other.isFunctional) + return false; + if (isHasProperty != other.isHasProperty) + return false; + if (literalRange == null) { + if (other.literalRange != null) + return false; + } else if (!literalRange.equals(other.literalRange)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (predicate == null) { + if (other.predicate != null) + return false; + } else if (!predicate.equals(other.predicate)) + return false; + if (requiredDatatype == null) { + if (other.requiredDatatype != null) + return false; + } else if (!requiredDatatype.equals(other.requiredDatatype)) + return false; + if (requiredValueType == null) { + if (other.requiredValueType != null) + return false; + } else if (!requiredValueType.equals(other.requiredValueType)) + return false; + if (subliteralPredicates == null) { + if (other.subliteralPredicates != null) + return false; + } else if (!subliteralPredicates.equals(other.subliteralPredicates)) + return false; + if (valueAccessor == null) { + if (other.valueAccessor != null) + return false; + } else if (!valueAccessor.equals(other.valueAccessor)) + return false; + return true; + } } -- 2.43.2