2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
3 * Copyright (c) 2020 PANTHEON.tech, s.r.o
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.yangtools.yang.data.spi.node;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.concepts.AbstractIdentifiable;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.concepts.PrettyTree;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 * Abstract base class for {@link NormalizedNode} implementations.
23 * @param <I> Identifier type
24 * @param <T> Implemented {@link NormalizedNode} specialization type
27 public abstract class AbstractNormalizedNode<I extends PathArgument, T extends NormalizedNode>
28 extends AbstractIdentifiable<PathArgument, I> implements NormalizedNode, Immutable {
29 protected AbstractNormalizedNode(final I identifier) {
34 public final PrettyTree prettyTree() {
35 return new NormalizedNodePrettyTree(this);
39 public final boolean equals(final Object obj) {
43 final Class<T> clazz = implementedType();
44 if (!clazz.isInstance(obj)) {
47 final T other = clazz.cast(obj);
48 return getIdentifier().equals(other.getIdentifier()) && valueEquals(other);
52 public final int hashCode() {
53 return 31 * getIdentifier().hashCode() + valueHashCode();
57 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
58 return super.addToStringAttributes(toStringHelper).add("body", body());
61 protected abstract @NonNull Class<T> implementedType();
63 protected abstract int valueHashCode();
65 protected abstract boolean valueEquals(@NonNull T other);