Refactored base yang-java types.
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / InstanceIdentifier.java
index 608c35c891ef8691e717d3ab373af1d222faa903..1af0fb8ff04cea9d35f28ce77f8397bd1dac403d 100644 (file)
@@ -25,29 +25,22 @@ import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefi
  */
 public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
     private static final QName name = BaseTypes.constructQName("instance-identifier");
+    private static final SchemaPath path = new SchemaPath(Collections.singletonList(name), true);
     private static final String description = "The instance-identifier built-in type is used to "
             + "uniquely identify a particular instance node in the data tree.";
     private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.13";
 
-    private final transient SchemaPath path;
     private final RevisionAwareXPath xpath;
-    private final String units = "";
-    private final InstanceIdentifierTypeDefinition baseType;
+    private static final String units = "";
     private boolean requireInstance = true;
 
-    public InstanceIdentifier(final SchemaPath path, final RevisionAwareXPath xpath) {
-        super();
-        this.path = path;
+    public InstanceIdentifier(final RevisionAwareXPath xpath) {
         this.xpath = xpath;
-        this.baseType = this;
     }
 
-    public InstanceIdentifier(final SchemaPath path, final RevisionAwareXPath xpath, final boolean requireInstance) {
-        super();
-        this.path = path;
+    public InstanceIdentifier(final RevisionAwareXPath xpath, final boolean requireInstance) {
         this.xpath = xpath;
         this.requireInstance = requireInstance;
-        this.baseType = this;
     }
 
     /*
@@ -58,7 +51,7 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
      */
     @Override
     public InstanceIdentifierTypeDefinition getBaseType() {
-        return baseType;
+        return this;
     }
 
     /*
@@ -168,4 +161,32 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
         return requireInstance;
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (requireInstance ? 1231 : 1237);
+        result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        InstanceIdentifier other = (InstanceIdentifier) obj;
+        if (requireInstance != other.requireInstance)
+            return false;
+        if (xpath == null) {
+            if (other.xpath != null)
+                return false;
+        } else if (!xpath.equals(other.xpath))
+            return false;
+        return true;
+    }
+
 }