BUG-2304 Fix SchemaContextUtil for augmented nodes.
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / UnionType.java
index 81bda38776c8dca0e6758336644aa19c7caf5800..ec8edd3411763f3f14ac18885fdd70aced4c8fab 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
 import java.util.Collections;
 import java.util.List;
 
@@ -18,23 +21,24 @@ 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 = 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 static final SchemaPath PATH = SchemaPath.create(true, BaseTypes.UNION_QNAME);
+    private static final String DESCRIPTION = "The union built-in type represents a value that corresponds to one of its member types.";
+    private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.12";
     private final 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.types = types;
+    @Deprecated
+    public UnionType(final List<TypeDefinition<?>> types) {
+        Preconditions.checkNotNull(types,"When the type is 'union', the 'type' statement MUST be present.");
+        this.types = ImmutableList.copyOf(types);
+    }
+
+    public static UnionType create(final List<TypeDefinition<?>> types) {
+        return new UnionType(types);
     }
 
     @Override
     public UnionTypeDefinition getBaseType() {
-        return this;
+        return null;
     }
 
     @Override
@@ -49,22 +53,22 @@ public final class UnionType implements UnionTypeDefinition {
 
     @Override
     public QName getQName() {
-        return name;
+        return BaseTypes.UNION_QNAME;
     }
 
     @Override
     public SchemaPath getPath() {
-        return path;
+        return PATH;
     }
 
     @Override
     public String getDescription() {
-        return description;
+        return DESCRIPTION;
     }
 
     @Override
     public String getReference() {
-        return reference;
+        return REFERENCE;
     }
 
     @Override
@@ -86,12 +90,12 @@ public final class UnionType implements UnionTypeDefinition {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((types == null) ? 0 : types.hashCode());
+        result = prime * result + types.hashCode();
         return result;
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -112,12 +116,12 @@ public final class UnionType implements UnionTypeDefinition {
     public String toString() {
         StringBuilder builder = new StringBuilder();
         builder.append("type ");
-        builder.append(name);
+        builder.append(BaseTypes.UNION_QNAME);
         builder.append(" (types=[");
         for (TypeDefinition<?> td : types) {
-            builder.append(", " td.getQName().getLocalName());
+            builder.append(", " ).append(td.getQName().getLocalName());
         }
-        builder.append("]");
+        builder.append(']');
         return builder.toString();
     }