import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Preconditions;
public abstract class AbstractImmutableNormalizedNode<K extends InstanceIdentifier.PathArgument,V>
implements NormalizedNode<K, V>, Immutable {
- protected final K nodeIdentifier;
- protected final V value;
+ private final K nodeIdentifier;
+ private final V value;
- protected AbstractImmutableNormalizedNode(K nodeIdentifier, V value) {
+ protected AbstractImmutableNormalizedNode(final K nodeIdentifier, final V value) {
this.nodeIdentifier = Preconditions.checkNotNull(nodeIdentifier, "nodeIdentifier");
this.value = Preconditions.checkNotNull(value, "value");
}
}
@Override
- public final V setValue(V value) {
+ public final V setValue(final V value) {
throw new UnsupportedOperationException("Immutable");
}
@Override
public final String toString() {
- return Objects.toStringHelper(this)
- .add("nodeIdentifier", nodeIdentifier)
- .add("value", value)
- .toString();
+ return addToStringAttributes(Objects.toStringHelper(this)).toString();
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof AbstractImmutableNormalizedNode)) return false;
-
- AbstractImmutableNormalizedNode<?, ?> that = (AbstractImmutableNormalizedNode<?, ?>) o;
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return toStringHelper.add("nodeIdentifier", nodeIdentifier).add("value", getValue());
+ }
- if (!nodeIdentifier.equals(that.nodeIdentifier)) return false;
- if (!value.equals(that.value)) return false;
+ protected abstract boolean valueEquals(AbstractImmutableNormalizedNode<?, ?> other);
+ protected abstract int valueHashCode();
- return true;
+ @Override
+ 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;
}
}