0f572d22b1075f2d9698f42de80a1a8db6d6b831
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / IdentityrefTypeDefinition.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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.model.api.type;
9
10 import java.util.Objects;
11 import java.util.Set;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
16
17 /**
18  * Contains method for getting data from <code>identityref</code> built-in YANG type.
19  */
20 public interface IdentityrefTypeDefinition extends TypeDefinition<IdentityrefTypeDefinition> {
21     /**
22      * Returns the set of identities this reference points to.
23      *
24      * @return set of identities to which the instance of this type refers (in YANG 1.1 models) or a set containing
25      *         just one identity (in YANG 1.0 models)
26      */
27     @NonNull Set<? extends IdentitySchemaNode> getIdentities();
28
29     static int hashCode(final @NonNull IdentityrefTypeDefinition type) {
30         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
31             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getIdentities());
32     }
33
34     static boolean equals(final @NonNull IdentityrefTypeDefinition type, final @Nullable Object obj) {
35         if (type == obj) {
36             return true;
37         }
38
39         final IdentityrefTypeDefinition other = TypeDefinitions.castIfEquals(IdentityrefTypeDefinition.class, type,
40             obj);
41         return other != null && type.getIdentities().equals(other.getIdentities());
42     }
43
44     static String toString(final @NonNull IdentityrefTypeDefinition type) {
45         return TypeDefinitions.toStringHelper(type).add("identities", type.getIdentities()).toString();
46     }
47 }