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.yang.data.api.YangInstanceIdentifier.PathArgument;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 * Abstract base class for {@link NormalizedNode} implementations.
22 * @param <I> Identifier type
23 * @param <T> Implemented {@link NormalizedNode} specialization type
26 public abstract class AbstractNormalizedNode<I extends PathArgument, T extends NormalizedNode>
27 extends AbstractIdentifiable<PathArgument, I> implements NormalizedNode, Immutable {
28 protected AbstractNormalizedNode(final I identifier) {
33 public final boolean equals(final Object obj) {
37 final Class<T> clazz = implementedType();
38 if (!clazz.isInstance(obj)) {
41 final T other = clazz.cast(obj);
42 return getIdentifier().equals(other.getIdentifier()) && valueEquals(other);
46 public final int hashCode() {
47 return 31 * getIdentifier().hashCode() + valueHashCode();
51 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
52 return super.addToStringAttributes(toStringHelper).add("body", body());
55 protected abstract @NonNull Class<T> implementedType();
57 protected abstract int valueHashCode();
59 protected abstract boolean valueEquals(@NonNull T other);