Populate model/ hierarchy
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / EnumTypeDefinition.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.List;
11 import java.util.Objects;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
15 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
16
17 /**
18  * Makes is possible to access to the individual enumeration values of this type.
19  */
20 public interface EnumTypeDefinition extends TypeDefinition<EnumTypeDefinition> {
21     /**
22      * Contains the methods for accessing the data about the concrete enumeration item which represents {@code enum}
23      * YANG type.
24      */
25     interface EnumPair extends DocumentedNode.WithStatus {
26         /**
27          * The name to specify each assigned name of an enumeration type.
28          *
29          * @return name of each assigned name of an enumeration type.
30          */
31         String getName();
32
33         /**
34          * The "value" statement, which is optional, is used to associate an integer value with the assigned name
35          * for the enum. This integer value MUST be unique within the enumeration type.
36          *
37          * @return integer value assigned to enumeration
38          */
39         int getValue();
40     }
41
42     /**
43      * Returns all enumeration values.
44      *
45      * @return list of {@code EnumPair} type instances which contain the data about all individual enumeration pairs
46      *         of {@code enumeration} YANG built-in type
47      */
48     @NonNull List<EnumPair> getValues();
49
50     static boolean equals(final @NonNull EnumTypeDefinition type, final @Nullable Object obj) {
51         if (type == obj) {
52             return true;
53         }
54
55         final EnumTypeDefinition other = TypeDefinitions.castIfEquals(EnumTypeDefinition.class, type, obj);
56         return other != null && type.getValues().equals(other.getValues());
57     }
58
59     static int hashCode(final @NonNull EnumTypeDefinition type) {
60         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
61             type.getUnits().orElse(null),
62             type.getDefaultValue(), type.getValues());
63     }
64
65     static String toString(final @NonNull EnumTypeDefinition type) {
66         return TypeDefinitions.toStringHelper(type).add("values", type.getValues()).toString();
67     }
68 }