fc58ecb5d0bc18498022f63df06363414fd47448
[mdsal.git] / binding / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / OpaqueObject.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
12 /**
13  * An opaque object. This interface supports code generation for both {@code anyxml} and {@code anydata}. Both of these
14  * statements essentially share the same characteristic of storing data whose actual schema and representation is not
15  * known at compile-time. Schema may be unknown even at runtime, and furthermore the representation may vary during
16  * run-time, based on source of the data.
17  *
18  * <p>
19  * The code generation is therefore limited to a single interface, which only provides the default implementation
20  * of {@link #implementedInterface()} bound to itself. The value is communicated through {@link #getValue()}, which
21  * is only an encapsulation holding information about the object model and the data in that object model.
22  *
23  * <p>
24  * Implementations are strongly encouraged to use {@link AbstractOpaqueObject} as their base implementation class.
25  *
26  * @param <T> Generated interface
27  */
28 @Beta
29 public interface OpaqueObject<T extends OpaqueObject<T>> extends BindingObject, DataContainer,
30         ValueAware<OpaqueData<?>> {
31     @Override
32     Class<T> implementedInterface();
33
34     /**
35      * Hash code value of this object. This is a combination of {@link #implementedInterface()} and the value being
36      * held. The canonical computation algorithm is defined in {@link AbstractOpaqueObject#hashCode()}.
37      *
38      * @return a hash code value for this object.
39      */
40     @Override
41     int hashCode();
42
43     /**
44      * Compare this object to another object. The comparison needs to take into account {@link #implementedInterface()}
45      * first and then follow comparison on {@link #getValue()}. For canonical algorithm please refer to
46      * {@link AbstractOpaqueObject#equals(Object)}.
47      *
48      * @param obj the reference object with which to compare.
49      * @return {@code true} if this object is the same as the obj argument; {@code false} otherwise.
50      */
51     @Override
52     boolean equals(Object obj);
53 }