Fix DataObjectReference javadoc
[yangtools.git] / binding / binding-spec / src / main / java / org / opendaylight / yangtools / binding / AbstractOpaqueObject.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.binding;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import org.eclipse.jdt.annotation.NonNull;
14
15 /**
16  * Utility base class for {@link OpaqueObject} implementations. This class provides baseline implementation of
17  * {@link #hashCode()} and {@link #equals(Object)} as specified by {@link OpaqueObject}.
18  *
19  * @param <T> Implemented OpaqueObject type
20  */
21 @Beta
22 public abstract class AbstractOpaqueObject<T extends OpaqueObject<T>> implements OpaqueObject<T> {
23     @Override
24     public final int hashCode() {
25         return 31 * implementedInterface().hashCode() + valueHashCode();
26     }
27
28     @Override
29     public final boolean equals(final Object obj) {
30         return this == obj || obj instanceof OpaqueObject<?> other
31             && implementedInterface().equals(other.implementedInterface()) && valueEquals(other.getValue());
32     }
33
34     @Override
35     public final String toString() {
36         return addToStringAttributes(MoreObjects.toStringHelper(this)
37             .add("implementedInterface", implementedInterface())).toString();
38     }
39
40     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
41         return helper.add("value", getValue());
42     }
43
44     protected boolean valueEquals(final @NonNull OpaqueData<?> otherValue) {
45         return getValue().equals(otherValue);
46     }
47
48     protected int valueHashCode() {
49         return getValue().hashCode();
50     }
51 }