2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 public abstract class AbstractImmutableNormalizedNode<K extends PathArgument,V> implements NormalizedNode<K, V>,
20 private final K nodeIdentifier;
22 protected AbstractImmutableNormalizedNode(final K nodeIdentifier) {
23 this.nodeIdentifier = Preconditions.checkNotNull(nodeIdentifier, "nodeIdentifier");
27 public final QName getNodeType() {
28 return getIdentifier().getNodeType();
32 public final K getIdentifier() {
33 return nodeIdentifier;
37 public final String toString() {
38 return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
41 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
42 return toStringHelper.add("nodeIdentifier", nodeIdentifier).add("value", getValue());
45 protected abstract boolean valueEquals(AbstractImmutableNormalizedNode<?, ?> other);
47 protected abstract int valueHashCode();
50 public final boolean equals(final Object obj) {
57 if (this.getClass() != obj.getClass()) {
61 final AbstractImmutableNormalizedNode<?, ?> other = (AbstractImmutableNormalizedNode<?, ?>)obj;
62 if (!nodeIdentifier.equals(other.nodeIdentifier)) {
66 return valueEquals(other);
70 public final int hashCode() {
71 int result = nodeIdentifier.hashCode();
72 result = 31 * result + valueHashCode();