Define OpaqueData/OpaqueObject hashCode/equals
[mdsal.git] / binding / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / OpaqueData.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.yang.binding;
9
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.concepts.Immutable;
13
14 /**
15  * An immutable view of data. Data representation identity is available through {@link #getObjectModel()} and the actual
16  * data is available through {@link #getData()}.
17  *
18  * @param <T> Data object model type
19  */
20 @Beta
21 public interface OpaqueData<T> extends Immutable {
22     /**
23      * Return the object model class, which identifies it.
24      *
25      * @return Object model class
26      */
27     @NonNull Class<T> getObjectModel();
28
29     /**
30      * Return the data in associated object model.
31      *
32      * @return Data held in this object.
33      */
34     @NonNull T getData();
35
36     /**
37      * The hash code of any {@link OpaqueData} instance is defined by the combination of its object model and the data
38      * it holds. This is inherently object-model-specific hence different OpaqueData defined by distinct object models
39      * will result in differing hash codes. This implies that node with differing object models cannot compare as equal.
40      * See {@link AbstractOpaqueData#hashCode()} for canonical implementation.
41      *
42      * @return a hash code value for this object.
43      */
44     @Override
45     int hashCode();
46
47     /**
48      * Compare this object to another object. The comparison needs to take into account {@link #getObjectModel()}
49      * first and then follow comparison on {@link #getData()}. For canonical algorithm please refer to
50      * {@link AbstractOpaqueData#equals(Object)}.
51      *
52      * @param obj the reference object with which to compare.
53      * @return {@code true} if this object is the same as the obj argument; {@code false} otherwise.
54      */
55     @Override
56     boolean equals(Object obj);
57 }