*/
package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
+import com.google.common.base.MoreObjects.ToStringHelper;
+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.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-
-public abstract class AbstractImmutableNormalizedNode<K extends InstanceIdentifier.PathArgument,V>
+public abstract class AbstractImmutableNormalizedNode<K extends PathArgument, V> extends AbstractIdentifiable<K>
implements NormalizedNode<K, V>, Immutable {
-
- protected final K nodeIdentifier;
- protected final V value;
-
- protected AbstractImmutableNormalizedNode(K nodeIdentifier, V value) {
- this.nodeIdentifier = Preconditions.checkNotNull(nodeIdentifier, "nodeIdentifier");
- this.value = Preconditions.checkNotNull(value, "value");
+ protected AbstractImmutableNormalizedNode(final K nodeIdentifier) {
+ super(nodeIdentifier);
}
@Override
}
@Override
- public final K getIdentifier() {
- return nodeIdentifier;
- }
-
- @Override
- public final CompositeNode getParent() {
- throw new UnsupportedOperationException("Deprecated");
- }
-
- @Override
- public final QName getKey() {
- return getNodeType();
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return super.addToStringAttributes(toStringHelper).add("value", getValue());
}
- @Override
- public final V getValue() {
- return value;
- }
+ protected abstract boolean valueEquals(AbstractImmutableNormalizedNode<?, ?> other);
- @Override
- public final V setValue(V value) {
- throw new UnsupportedOperationException("Immutable");
- }
+ protected abstract int valueHashCode();
@Override
- public final String toString() {
- return Objects.toStringHelper(this)
- .add("nodeIdentifier", nodeIdentifier)
- .add("value", value)
- .toString();
- }
-
- @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;
+ public final boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || this.getClass() != obj.getClass()) {
+ return false;
+ }
- return true;
+ final AbstractImmutableNormalizedNode<?, ?> other = (AbstractImmutableNormalizedNode<?, ?>)obj;
+ return getIdentifier().equals(other.getIdentifier()) && valueEquals(other);
}
@Override
- public int hashCode() {
- int result = nodeIdentifier.hashCode();
- result = 31 * result + value.hashCode();
- return result;
+ public final int hashCode() {
+ return 31 * getIdentifier().hashCode() + valueHashCode();
}
}