BUG-1092: rename data.api.InstanceIdentifier to YangInstanceIdentifier
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / nodes / AbstractImmutableNormalizedNode.java
index ceb20124c81f709faf28cf6c647fac50be52e464..ac9b03065559b861d481626256b6b02e4fcfa5b3 100644 (file)
@@ -7,72 +7,68 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
 
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.base.Preconditions;
+
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
-import com.google.common.base.Preconditions;
-
-public abstract class AbstractImmutableNormalizedNode<K extends InstanceIdentifier.PathArgument,V>
-        implements NormalizedNode<K, V>, Immutable {
+public abstract class AbstractImmutableNormalizedNode<K extends YangInstanceIdentifier.PathArgument,V> implements NormalizedNode<K, V>, Immutable {
+    private final K nodeIdentifier;
 
-    protected final K nodeIdentifier;
-    protected V value;
-
-    protected AbstractImmutableNormalizedNode(K nodeIdentifier, V value) {
+    protected AbstractImmutableNormalizedNode(final K nodeIdentifier) {
         this.nodeIdentifier = Preconditions.checkNotNull(nodeIdentifier, "nodeIdentifier");
-        this.value = Preconditions.checkNotNull(value, "value");
     }
 
     @Override
-    public QName getNodeType() {
+    public final QName getNodeType() {
         return getIdentifier().getNodeType();
     }
 
     @Override
-    public K getIdentifier() {
+    public final K getIdentifier() {
         return nodeIdentifier;
     }
 
     @Override
-    public CompositeNode getParent() {
-        throw new UnsupportedOperationException("Deprecated");
-    }
-
-    @Override
-    public QName getKey() {
-        return getNodeType();
+    public final String toString() {
+        return addToStringAttributes(Objects.toStringHelper(this)).toString();
     }
 
-    @Override
-    public V getValue() {
-        return value;
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return toStringHelper.add("nodeIdentifier", nodeIdentifier).add("value", getValue());
     }
 
-    @Override
-    public V setValue(V value) {
-        throw new UnsupportedOperationException("Immutable");
-    }
+    protected abstract boolean valueEquals(AbstractImmutableNormalizedNode<?, ?> other);
+    protected abstract int valueHashCode();
 
     @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (!(o instanceof AbstractImmutableNormalizedNode)) return false;
-
-        AbstractImmutableNormalizedNode that = (AbstractImmutableNormalizedNode) o;
-
-        if (!nodeIdentifier.equals(that.nodeIdentifier)) return false;
-        if (!value.equals(that.value)) return false;
-
-        return true;
+    public final boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (this.getClass() != obj.getClass()) {
+            return false;
+        }
+
+        final AbstractImmutableNormalizedNode<?, ?> other = (AbstractImmutableNormalizedNode<?, ?>)obj;
+        if (!nodeIdentifier.equals(other.nodeIdentifier)) {
+            return false;
+        }
+
+        return valueEquals(other);
     }
 
     @Override
-    public int hashCode() {
+    public final int hashCode() {
         int result = nodeIdentifier.hashCode();
-        result = 31 * result + value.hashCode();
+        result = 31 * result + valueHashCode();
         return result;
     }
 }