Add YangError.getErrorTag()
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / nodes / AbstractImmutableNormalizedNode.java
index 13ef48fc1267426450a4aeb31af57824ce21995a..848982521b507a3ff62d9bf0606fd6bb4ff530dc 100644 (file)
@@ -7,20 +7,17 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
 
-import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
+import org.opendaylight.yangtools.concepts.AbstractIdentifiable;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
-public abstract class AbstractImmutableNormalizedNode<K extends PathArgument,V> implements NormalizedNode<K, V>,
-        Immutable {
-    private final K nodeIdentifier;
-
+public abstract class AbstractImmutableNormalizedNode<K extends PathArgument, V> extends AbstractIdentifiable<K>
+        implements NormalizedNode<K, V>, Immutable {
     protected AbstractImmutableNormalizedNode(final K nodeIdentifier) {
-        this.nodeIdentifier = Preconditions.checkNotNull(nodeIdentifier, "nodeIdentifier");
+        super(nodeIdentifier);
     }
 
     @Override
@@ -29,17 +26,8 @@ public abstract class AbstractImmutableNormalizedNode<K extends PathArgument,V>
     }
 
     @Override
-    public final K getIdentifier() {
-        return nodeIdentifier;
-    }
-
-    @Override
-    public final String toString() {
-        return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
-    }
-
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-        return toStringHelper.add("nodeIdentifier", nodeIdentifier).add("value", getValue());
+        return super.addToStringAttributes(toStringHelper).add("value", getValue());
     }
 
     protected abstract boolean valueEquals(AbstractImmutableNormalizedNode<?, ?> other);
@@ -51,25 +39,16 @@ public abstract class AbstractImmutableNormalizedNode<K extends PathArgument,V>
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (this.getClass() != obj.getClass()) {
+        if (obj == null || this.getClass() != obj.getClass()) {
             return false;
         }
 
         final AbstractImmutableNormalizedNode<?, ?> other = (AbstractImmutableNormalizedNode<?, ?>)obj;
-        if (!nodeIdentifier.equals(other.nodeIdentifier)) {
-            return false;
-        }
-
-        return valueEquals(other);
+        return getIdentifier().equals(other.getIdentifier()) && valueEquals(other);
     }
 
     @Override
     public final int hashCode() {
-        int result = nodeIdentifier.hashCode();
-        result = 31 * result + valueHashCode();
-        return result;
+        return 31 * getIdentifier().hashCode() + valueHashCode();
     }
 }