*/
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;
}
}