Remove yang.model.util.BaseTypes
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / UnionTypeDefinition.java
index 04903c0b03154f612ee92fd269c9d268c7b1dbb1..8c88c70cca72d39217422b83260485df2170638f 100644 (file)
@@ -8,21 +8,43 @@
 package org.opendaylight.yangtools.yang.model.api.type;
 
 import java.util.List;
-
+import java.util.Objects;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
 /**
  * Contains the method which access union item in the union type.
- * 
  */
 public interface UnionTypeDefinition extends TypeDefinition<UnionTypeDefinition> {
+    /**
+     * Well-known QName of the {@code union} built-in type.
+     */
+    QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, "union").intern();
 
     /**
-     * Returns type definitions which represent the values of the arguments for
-     * all YANG <code>type</code> substatement in the main <code>union</code>
-     * statement.
-     * 
+     * Returns type definitions which represent the values of the arguments for all YANG {@code type} substatement in
+     * the main {@code union} statement.
+     *
      * @return list of the type definition which contains the union items.
      */
-    public List<TypeDefinition<?>> getTypes();
+    List<TypeDefinition<?>> getTypes();
+
+    static int hashCode(final UnionTypeDefinition type) {
+        return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
+            type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getTypes());
+    }
+
+    static boolean equals(final UnionTypeDefinition type, final Object obj) {
+        if (type == obj) {
+            return true;
+        }
+
+        final UnionTypeDefinition other = TypeDefinitions.castIfEquals(UnionTypeDefinition.class, type, obj);
+        return other != null && type.getTypes().equals(other.getTypes());
+    }
+
+    static String toString(final UnionTypeDefinition type) {
+        return TypeDefinitions.toStringHelper(type).add("types", type.getTypes()).toString();
+    }
 }