Merge "Bug 2157 - Race condition when adding a RPC implementation with an output"
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / BinaryType.java
index de7a3058ea437413e48ef2bc082551a9d2abd387..9d93f745f3d8675bca3315c21dcdfd8afb7d7ee4 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -18,39 +17,33 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 
+import com.google.common.base.Optional;
+
 /**
  * The <code>default</code> implementation of Binary Type Definition interface.
  *
  * @see BinaryTypeDefinition
  */
 public final class BinaryType implements BinaryTypeDefinition {
-    private final QName name = BaseTypes.constructQName("binary");
-    private final SchemaPath path;
-    private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
-    private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8";
-    private final BinaryTypeDefinition baseType;
-    private final List<Byte> bytes;
+    private static final String DESCRIPTION = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
+    private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.8";
+    private static final String UNITS = "";
+
+    private final static QName QNAME = BaseTypes.BINARY_QNAME;
+
+    private static final BinaryType INSTANCE = new BinaryType();
+
+    private final static SchemaPath PATH = SchemaPath.create(Collections.singletonList(QNAME), true);
+    private final List<Byte> bytes = Collections.emptyList();
     private final List<LengthConstraint> lengthConstraints;
-    private final String units = "";
 
-    public BinaryType(final SchemaPath path) {
-        final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-        constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
-                ""));
-        this.lengthConstraints = Collections.unmodifiableList(constraints);
-        this.bytes = Collections.emptyList();
-        this.path = path;
-        this.baseType = this;
+    private BinaryType() {
+        this.lengthConstraints = Collections.singletonList(
+                BaseConstraints.newLengthConstraint(0, Long.MAX_VALUE, Optional.of(""), Optional.of("")));
     }
 
-    public BinaryType(final SchemaPath path, final List<Byte> bytes) {
-        final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
-        constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
-                ""));
-        this.lengthConstraints = Collections.unmodifiableList(constraints);
-        this.bytes = Collections.unmodifiableList(bytes);
-        this.path = path;
-        this.baseType = this;
+    public static BinaryType getInstance() {
+        return INSTANCE;
     }
 
     /*
@@ -61,7 +54,7 @@ public final class BinaryType implements BinaryTypeDefinition {
      */
     @Override
     public BinaryTypeDefinition getBaseType() {
-        return baseType;
+        return null;
     }
 
     /*
@@ -71,7 +64,7 @@ public final class BinaryType implements BinaryTypeDefinition {
      */
     @Override
     public String getUnits() {
-        return units;
+        return UNITS;
     }
 
     /*
@@ -93,7 +86,7 @@ public final class BinaryType implements BinaryTypeDefinition {
      */
     @Override
     public QName getQName() {
-        return name;
+        return QNAME;
     }
 
     /*
@@ -103,7 +96,7 @@ public final class BinaryType implements BinaryTypeDefinition {
      */
     @Override
     public SchemaPath getPath() {
-        return path;
+        return PATH;
     }
 
     /*
@@ -114,7 +107,7 @@ public final class BinaryType implements BinaryTypeDefinition {
      */
     @Override
     public String getDescription() {
-        return description;
+        return DESCRIPTION;
     }
 
     /*
@@ -124,7 +117,7 @@ public final class BinaryType implements BinaryTypeDefinition {
      */
     @Override
     public String getReference() {
-        return reference;
+        return REFERENCE;
     }
 
     /*
@@ -159,22 +152,14 @@ public final class BinaryType implements BinaryTypeDefinition {
         final int prime = 31;
         int result = 1;
         result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
-        result = prime * result
-                + ((description == null) ? 0 : description.hashCode());
-        result = prime
-                * result
-                + ((lengthConstraints == null) ? 0 : lengthConstraints
-                        .hashCode());
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result + ((path == null) ? 0 : path.hashCode());
-        result = prime * result
-                + ((reference == null) ? 0 : reference.hashCode());
-        result = prime * result + ((units == null) ? 0 : units.hashCode());
+        result = prime * result + ((lengthConstraints == null) ? 0 : lengthConstraints.hashCode());
+        result = prime * result + QNAME.hashCode();
+        result = prime * result + PATH.hashCode();
         return result;
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -192,13 +177,6 @@ public final class BinaryType implements BinaryTypeDefinition {
         } else if (!bytes.equals(other.bytes)) {
             return false;
         }
-        if (description == null) {
-            if (other.description != null) {
-                return false;
-            }
-        } else if (!description.equals(other.description)) {
-            return false;
-        }
         if (lengthConstraints == null) {
             if (other.lengthConstraints != null) {
                 return false;
@@ -206,34 +184,6 @@ public final class BinaryType implements BinaryTypeDefinition {
         } else if (!lengthConstraints.equals(other.lengthConstraints)) {
             return false;
         }
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
-            return false;
-        }
-        if (reference == null) {
-            if (other.reference != null) {
-                return false;
-            }
-        } else if (!reference.equals(other.reference)) {
-            return false;
-        }
-        if (units == null) {
-            if (other.units != null) {
-                return false;
-            }
-        } else if (!units.equals(other.units)) {
-            return false;
-        }
         return true;
     }
 
@@ -241,19 +191,17 @@ public final class BinaryType implements BinaryTypeDefinition {
     public String toString() {
         StringBuilder builder = new StringBuilder();
         builder.append("BinaryType [name=");
-        builder.append(name);
-        builder.append(", path=");
-        builder.append(path);
+        builder.append(QNAME);
         builder.append(", description=");
-        builder.append(description);
+        builder.append(DESCRIPTION);
         builder.append(", reference=");
-        builder.append(reference);
+        builder.append(REFERENCE);
         builder.append(", bytes=");
         builder.append(bytes);
         builder.append(", lengthConstraints=");
         builder.append(lengthConstraints);
         builder.append(", units=");
-        builder.append(units);
+        builder.append(UNITS);
         builder.append("]");
         return builder.toString();
     }