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.ToStringHelper;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.concepts.AbstractIdentifiable;
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 public abstract class AbstractImmutableNormalizedNode<K extends PathArgument, N extends NormalizedNode>
18 extends AbstractIdentifiable<PathArgument, K> implements NormalizedNode, Immutable {
19 protected AbstractImmutableNormalizedNode(final K nodeIdentifier) {
20 super(nodeIdentifier);
24 public final boolean equals(final Object obj) {
28 final Class<N> clazz = implementedType();
29 if (!clazz.isInstance(obj)) {
32 final N other = clazz.cast(obj);
33 return getIdentifier().equals(other.getIdentifier()) && valueEquals(other);
37 public final int hashCode() {
38 return 31 * getIdentifier().hashCode() + valueHashCode();
42 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
43 return super.addToStringAttributes(toStringHelper).add("body", body());
46 protected abstract @NonNull Class<N> implementedType();
48 protected abstract int valueHashCode();
50 protected abstract boolean valueEquals(@NonNull N other);