*/
package org.opendaylight.yangtools.yang.model.util.type;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
-import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-abstract class AbstractBaseType<T extends TypeDefinition<T>> implements Immutable, TypeDefinition<T> {
- private final List<UnknownSchemaNode> unknownSchemaNodes;
- private final SchemaPath path;
-
+abstract class AbstractBaseType<T extends TypeDefinition<T>> extends AbstractTypeDefinition<T> {
AbstractBaseType(final QName qname) {
this(SchemaPath.create(true, qname), ImmutableList.<UnknownSchemaNode>of());
}
AbstractBaseType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes) {
- this.path = Preconditions.checkNotNull(path);
- this.unknownSchemaNodes = Preconditions.checkNotNull(unknownSchemaNodes);
+ super(path, unknownSchemaNodes);
}
@Override
return null;
}
- @Override
- public final QName getQName() {
- return path.getLastComponent();
- }
-
- @Override
- public final SchemaPath getPath() {
- return path;
- }
-
@Override
public final String getDescription() {
return null;
public final Status getStatus() {
return Status.CURRENT;
}
-
- @Override
- public final List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownSchemaNodes;
- }
-
- @Override
- public final String toString() {
- return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
- }
-
- protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return toStringHelper.add("path", path);
- }
}
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
import java.util.Collection;
-import java.util.List;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-abstract class AbstractDerivedType<T extends TypeDefinition<T>> implements Immutable, TypeDefinition<T> {
- private final SchemaPath path;
+abstract class AbstractDerivedType<T extends TypeDefinition<T>> extends AbstractTypeDefinition<T> {
private final T baseType;
private final Object defaultValue;
private final String description;
private final String reference;
private final Status status;
private final String units;
- private final List<UnknownSchemaNode> unknownSchemNodes;
AbstractDerivedType(final T baseType, final SchemaPath path, final Object defaultValue, final String description,
final String reference, final Status status, final String units, final Collection<UnknownSchemaNode> unknownSchemNodes) {
+ super(path, unknownSchemNodes);
this.baseType = Preconditions.checkNotNull(baseType);
- this.path = Preconditions.checkNotNull(path);
this.status = Preconditions.checkNotNull(status);
this.defaultValue = defaultValue;
this.description = description;
this.reference = reference;
this.units = units;
- this.unknownSchemNodes = ImmutableList.copyOf(unknownSchemNodes);
}
@Override
return defaultValue != null ? defaultValue : baseType.getDefaultValue();
}
- @Override
- public final QName getQName() {
- return path.getLastComponent();
- }
-
- @Override
- public final SchemaPath getPath() {
- return path;
- }
-
- @Override
- public final List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownSchemNodes;
- }
-
@Override
public final String getDescription() {
return description;
@Override
public final String toString() {
- return MoreObjects.toStringHelper(this).omitNullValues().add("baseType", baseType).add("default", defaultValue)
- .add("description", description).add("path", path).add("reference", reference).add("status", status)
+ return MoreObjects.toStringHelper(this).omitNullValues()
+ .add("baseType", baseType)
+ .add("default", defaultValue)
+ .add("description", description)
+ .add("path", getPath())
+ .add("reference", reference)
+ .add("status", status)
.add("units", units).toString();
}
}
AbstractIntegerBaseType(final QName qname, final Number minValue, final Number maxValue) {
super(qname, minValue, maxValue);
}
+
+ @Override
+ public final int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public final boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public final String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
*/
package org.opendaylight.yangtools.yang.model.util.type;
-import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import java.util.List;
public final List<RangeConstraint> getRangeConstraints() {
return rangeConstraints;
}
-
- @Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return super.addToStringAttributes(toStringHelper).add("range", rangeConstraints);
- }
}
package org.opendaylight.yangtools.yang.model.util.type;
import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
import java.util.Collection;
-import java.util.List;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-abstract class AbstractRestrictedType<T extends TypeDefinition<T>> implements Immutable, TypeDefinition<T> {
- private final List<UnknownSchemaNode> unknownSchemaNodes;
+abstract class AbstractRestrictedType<T extends TypeDefinition<T>> extends AbstractTypeDefinition<T> {
private final T baseType;
- private final SchemaPath path;
AbstractRestrictedType(final T baseType, final SchemaPath path, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+ super(path, unknownSchemaNodes);
this.baseType = Preconditions.checkNotNull(baseType);
- this.path = Preconditions.checkNotNull(path);
- this.unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodes);
}
@Override
return baseType.getDefaultValue();
}
- @Override
- public final QName getQName() {
- return path.getLastComponent();
- }
-
- @Override
- public final SchemaPath getPath() {
- return path;
- }
-
- @Override
- public final List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownSchemaNodes;
- }
-
@Override
public final String getDescription() {
return baseType.getDescription();
--- /dev/null
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util.type;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+
+abstract class AbstractTypeDefinition<T extends TypeDefinition<T>> implements Immutable, TypeDefinition<T> {
+ private final List<UnknownSchemaNode> unknownSchemaNodes;
+ private final SchemaPath path;
+
+ AbstractTypeDefinition(final SchemaPath path, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+ this.path = Preconditions.checkNotNull(path);
+ this.unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodes);
+ }
+
+ @Override
+ public final QName getQName() {
+ return path.getLastComponent();
+ }
+
+ @Override
+ public final SchemaPath getPath() {
+ return path;
+ }
+
+ @Override
+ public final List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownSchemaNodes;
+ }
+
+ @Override
+ public abstract String toString();
+
+ @Override
+ public abstract int hashCode();
+
+ @Override
+ public abstract boolean equals(final Object obj);
+}
AbstractUnsignedBaseType(final QName qname, final Number minValue, final Number maxValue) {
super(qname, minValue, maxValue);
}
+
+ @Override
+ public final int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public final boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public final String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<LengthConstraint> getLengthConstraints() {
return ImmutableList.of();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<Bit> getBits() {
return bits;
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
private BaseBooleanType() {
super(BaseTypes.BINARY_QNAME);
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
*/
package org.opendaylight.yangtools.yang.model.util.type;
-import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
}
@Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return super.addToStringAttributes(toStringHelper).add("fractionDigits", fractionDigits);
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
}
}
private BaseEmptyType() {
super(BaseTypes.EMPTY_QNAME);
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<EnumPair> getValues() {
return values;
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public IdentitySchemaNode getIdentity() {
return identity;
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public boolean requireInstance() {
return false;
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public RevisionAwareXPath getPathStatement() {
return pathStatement;
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<PatternConstraint> getPatternConstraints() {
return ImmutableList.of();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<TypeDefinition<?>> getTypes() {
return types;
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<LengthConstraint> getLengthConstraints() {
return getBaseType().getLengthConstraints();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
public List<Bit> getBits() {
return getBaseType().getBits();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
final Collection<UnknownSchemaNode> unknownSchemNodes) {
super(baseType, path, defaultValue, description, reference, status, units, unknownSchemNodes);
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
public List<RangeConstraint> getRangeConstraints() {
return getBaseType().getRangeConstraints();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
final Collection<UnknownSchemaNode> unknownSchemNodes) {
super(baseType, path, defaultValue, description, reference, status, units, unknownSchemNodes);
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
public List<EnumPair> getValues() {
return getBaseType().getValues();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
public IdentitySchemaNode getIdentity() {
return getBaseType().getIdentity();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
public boolean requireInstance() {
return requireInstance;
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
public List<RangeConstraint> getRangeConstraints() {
return getBaseType().getRangeConstraints();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
public RevisionAwareXPath getPathStatement() {
return getBaseType().getPathStatement();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
public List<LengthConstraint> getLengthConstraints() {
return getBaseType().getLengthConstraints();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
public List<TypeDefinition<?>> getTypes() {
return getBaseType().getTypes();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
public List<RangeConstraint> getRangeConstraints() {
return getBaseType().getRangeConstraints();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
}
final Collection<LengthConstraint> lengthConstraints) {
super(baseType, path, unknownSchemaNodes, lengthConstraints);
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<Bit> getBits() {
return getBaseType().getBits();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
final Collection<UnknownSchemaNode> unknownSchemaNodes) {
super(baseType, path, unknownSchemaNodes);
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public Integer getFractionDigits() {
return getBaseType().getFractionDigits();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
final Collection<UnknownSchemaNode> unknownSchemaNodes) {
super(baseType, path, unknownSchemaNodes);
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<EnumPair> getValues() {
return getBaseType().getValues();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public IdentitySchemaNode getIdentity() {
return getBaseType().getIdentity();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public boolean requireInstance() {
return requireInstance;
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
final Collection<UnknownSchemaNode> unknownSchemaNodes, final Collection<RangeConstraint> rangeConstraints) {
super(baseType, path, unknownSchemaNodes, rangeConstraints);
}
+
+ @Override
+ public final int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public final boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public RevisionAwareXPath getPathStatement() {
return getBaseType().getPathStatement();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<PatternConstraint> getPatternConstraints() {
return patternConstraints;
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<TypeDefinition<?>> getTypes() {
return getBaseType().getTypes();
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
public List<RangeConstraint> getRangeConstraints() {
return rangeConstraints;
}
+
+ @Override
+ public int hashCode() {
+ return TypeDefinitions.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return TypeDefinitions.equals(this, obj);
+ }
+
+ @Override
+ public String toString() {
+ return TypeDefinitions.toString(this);
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util.type;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import java.util.Objects;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+
+// TODO: this should be in the API package, as it defines equality for TypeDefinitions
+final class TypeDefinitions {
+ private TypeDefinitions() {
+ throw new UnsupportedOperationException();
+ }
+
+ private static int basicHashCode(final TypeDefinition<?> type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue());
+ }
+
+ private static <T extends TypeDefinition<T>> T castIfEquals(final Class<T> clazz, final T type, final Object obj) {
+ if (!clazz.isInstance(obj)) {
+ return null;
+ }
+
+ final T other = clazz.cast(obj);
+ return Objects.equals(type.getPath(), other.getPath())
+ && Objects.equals(type.getBaseType(), other.getBaseType())
+ && Objects.equals(type.getDefaultValue(), other.getDefaultValue())
+ && Objects.equals(type.getUnknownSchemaNodes(), other.getUnknownSchemaNodes())
+ && Objects.equals(type.getUnits(), other.getUnits()) ? other : null;
+ }
+
+ private static ToStringHelper toStringHelper(final TypeDefinition<?> type) {
+ return MoreObjects.toStringHelper(type).omitNullValues()
+ .add("baseType", type.getBaseType())
+ .add("default", type.getDefaultValue())
+ .add("description", type.getDescription())
+ .add("path", type.getPath())
+ .add("reference", type.getReference())
+ .add("status", type.getStatus())
+ .add("units", type.getUnits());
+ }
+
+ static int hashCode(final BinaryTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.getLengthConstraints());
+ }
+
+ static boolean equals(final BinaryTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final BinaryTypeDefinition other = castIfEquals(BinaryTypeDefinition.class, type, obj);
+ return other != null && type.getLengthConstraints().equals(other.getLengthConstraints());
+ }
+
+ static String toString(final BinaryTypeDefinition type) {
+ return toStringHelper(type).add("length", type.getLengthConstraints()).toString();
+ }
+
+ static int hashCode(final BitsTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.getBits());
+ }
+
+ static boolean equals(final BitsTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final BitsTypeDefinition other = castIfEquals(BitsTypeDefinition.class, type, obj);
+ return other != null && type.getBits().equals(other.getBits());
+ }
+
+ static String toString(final BitsTypeDefinition type) {
+ return toStringHelper(type).add("bits", type.getBits()).toString();
+ }
+
+ static int hashCode(final BooleanTypeDefinition type) {
+ return basicHashCode(type);
+ }
+
+ static boolean equals(final BooleanTypeDefinition type, final Object obj) {
+ return type == obj || castIfEquals(BooleanTypeDefinition.class, type, obj) != null;
+ }
+
+ static String toString(final BooleanTypeDefinition type) {
+ return toStringHelper(type).toString();
+ }
+
+ static int hashCode(final DecimalTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.getFractionDigits(), type.getRangeConstraints());
+ }
+
+ static boolean equals(final DecimalTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final DecimalTypeDefinition other = castIfEquals(DecimalTypeDefinition.class, type, obj);
+ return other != null && type.getFractionDigits().equals(other.getFractionDigits())
+ && type.getRangeConstraints().equals(other.getRangeConstraints());
+ }
+
+ static String toString(final DecimalTypeDefinition type) {
+ return toStringHelper(type).add("fractionDigits", type.getFractionDigits())
+ .add("range", type.getRangeConstraints()).toString();
+ }
+
+ static int hashCode(final EmptyTypeDefinition type) {
+ return basicHashCode(type);
+ }
+
+ static boolean equals(final EmptyTypeDefinition type, final Object obj) {
+ return type == obj || castIfEquals(EmptyTypeDefinition.class, type, obj) != null;
+ }
+
+ static String toString(final EmptyTypeDefinition type) {
+ return toStringHelper(type).toString();
+ }
+
+ static int hashCode(final EnumTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.getValues());
+ }
+
+ static boolean equals(final EnumTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final EnumTypeDefinition other = castIfEquals(EnumTypeDefinition.class, type, obj);
+ return other != null && type.getValues().equals(other.getValues());
+ }
+
+ static String toString(final EnumTypeDefinition type) {
+ return toStringHelper(type).add("values", type.getValues()).toString();
+ }
+
+ static int hashCode(final IdentityrefTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.getIdentity());
+ }
+
+ static boolean equals(final IdentityrefTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final IdentityrefTypeDefinition other = castIfEquals(IdentityrefTypeDefinition.class, type, obj);
+ return other != null && type.getIdentity().equals(other.getIdentity());
+ }
+
+ static String toString(final IdentityrefTypeDefinition type) {
+ return toStringHelper(type).add("identity", type.getIdentity()).toString();
+ }
+
+ static int hashCode(final InstanceIdentifierTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.requireInstance());
+ }
+
+ static boolean equals(final InstanceIdentifierTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final InstanceIdentifierTypeDefinition other = castIfEquals(InstanceIdentifierTypeDefinition.class, type, obj);
+ return other != null && type.requireInstance() == other.requireInstance();
+ }
+
+ static String toString(final InstanceIdentifierTypeDefinition type) {
+ return toStringHelper(type).add("requireInstance", type.requireInstance()).toString();
+ }
+
+ static int hashCode(final IntegerTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.getRangeConstraints());
+ }
+
+ static boolean equals(final IntegerTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final IntegerTypeDefinition other = castIfEquals(IntegerTypeDefinition.class, type, obj);
+ return other != null && type.getRangeConstraints().equals(other.getRangeConstraints());
+ }
+
+ static String toString(final IntegerTypeDefinition type) {
+ return toStringHelper(type).add("range", type.getRangeConstraints()).toString();
+ }
+
+ static int hashCode(final LeafrefTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.getPathStatement());
+ }
+
+ static boolean equals(final LeafrefTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final LeafrefTypeDefinition other =castIfEquals(LeafrefTypeDefinition.class, type, obj);
+ return other != null && type.getPathStatement().equals(other.getPathStatement());
+ }
+
+ static String toString(final LeafrefTypeDefinition type) {
+ return toStringHelper(type).add("pathStatement", type.getPathStatement()).toString();
+ }
+
+ static int hashCode(final StringTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.getLengthConstraints(), type.getPatternConstraints());
+ }
+
+ static boolean equals(final StringTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final StringTypeDefinition other = castIfEquals(StringTypeDefinition.class, type, obj);
+ return other != null && type.getLengthConstraints().equals(other.getLengthConstraints())
+ && type.getPatternConstraints().equals(other.getPatternConstraints());
+ }
+
+ static String toString(final StringTypeDefinition type) {
+ return toStringHelper(type).add("length", type.getLengthConstraints())
+ .add("patterns", type.getPatternConstraints()).toString();
+ }
+
+ static int hashCode(final UnionTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.getTypes());
+ }
+
+ static boolean equals(final UnionTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final UnionTypeDefinition other = castIfEquals(UnionTypeDefinition.class, type, obj);
+ return other != null && type.getTypes().equals(other.getTypes());
+ }
+
+ static String toString(final UnionTypeDefinition type) {
+ return toStringHelper(type).add("types", type.getTypes()).toString();
+ }
+
+ static int hashCode(final UnsignedIntegerTypeDefinition type) {
+ return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(),
+ type.getDefaultValue(), type.getRangeConstraints());
+ }
+
+ static boolean equals(final UnsignedIntegerTypeDefinition type, final Object obj) {
+ if (type == obj) {
+ return true;
+ }
+
+ final UnsignedIntegerTypeDefinition other = castIfEquals(UnsignedIntegerTypeDefinition.class, type, obj);
+ return other != null && type.getRangeConstraints().equals(other.getRangeConstraints());
+ }
+
+ static String toString(final UnsignedIntegerTypeDefinition type) {
+ return toStringHelper(type).add("range", type.getRangeConstraints()).toString();
+ }
+}