Refactored base yang-java types.
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / UnionType.java
index 470e904b9d4e5d7f07e438c7bccc036d7fbce1c7..81bda38776c8dca0e6758336644aa19c7caf5800 100644 (file)
@@ -18,37 +18,23 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 
 public final class UnionType implements UnionTypeDefinition {
-
     private final QName name = BaseTypes.constructQName("union");
-    private final SchemaPath path;
+    private final SchemaPath path = BaseTypes.schemaPath(name);
     private final String description = "The union built-in type represents a value that corresponds to one of its member types.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.12";
-    private final UnionTypeDefinition baseType;
     private final List<TypeDefinition<?>> types;
 
-    private UnionType(List<TypeDefinition<?>> types) {
-        if (types == null) {
-            throw new NullPointerException(
-                    "When the type is 'union', the 'type' statement MUST be present.");
-        }
-        path = BaseTypes.schemaPath(name);
-        this.types = types;
-        this.baseType = this;
-    }
-
-    public UnionType(final SchemaPath path, List<TypeDefinition<?>> types) {
+    public UnionType(List<TypeDefinition<?>> types) {
         if (types == null) {
             throw new NullPointerException(
                     "When the type is 'union', the 'type' statement MUST be present.");
         }
-        this.path = path;
         this.types = types;
-        this.baseType = new UnionType(types);
     }
 
     @Override
     public UnionTypeDefinition getBaseType() {
-        return baseType;
+        return this;
     }
 
     @Override
@@ -100,8 +86,6 @@ public final class UnionType implements UnionTypeDefinition {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result + ((path == null) ? 0 : path.hashCode());
         result = prime * result + ((types == null) ? 0 : types.hashCode());
         return result;
     }
@@ -118,11 +102,7 @@ public final class UnionType implements UnionTypeDefinition {
             return false;
         }
         UnionType other = (UnionType) obj;
-        if (types == null) {
-            if (other.types != null) {
-                return false;
-            }
-        } else if (!types.equals(other.types)) {
+        if (!types.equals(other.types)) {
             return false;
         }
         return true;
@@ -131,14 +111,13 @@ public final class UnionType implements UnionTypeDefinition {
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
-        builder.append("UnionType [name=");
+        builder.append("type ");
         builder.append(name);
-        builder.append("types=[");
+        builder.append(" (types=[");
         for (TypeDefinition<?> td : types) {
             builder.append(", " + td.getQName().getLocalName());
         }
         builder.append("]");
-        builder.append("]");
         return builder.toString();
     }