Merge "Test for class RefineHolder.java"
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / EnumerationType.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.util;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.Status;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
18
19 /**
20  * The <code>default</code> implementation of Enumertaion Type Definition
21  * interface.
22  *
23  * @see EnumTypeDefinition
24  */
25 public final class EnumerationType implements EnumTypeDefinition {
26     private final QName name = BaseTypes.constructQName("enumeration");
27     private final SchemaPath path;
28     private static final String DESCRIPTION = "The enumeration built-in type represents values from a set of assigned names.";
29     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.6";
30
31     private final EnumPair defaultEnum;
32     private final List<EnumPair> enums;
33     private static final String UNITS = "";
34
35     public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
36         super();
37         this.path = path;
38         this.enums = Collections.unmodifiableList(enums);
39         this.defaultEnum = null;
40     }
41
42     public EnumerationType(final SchemaPath path, final EnumPair defaultEnum, final List<EnumPair> enums) {
43         super();
44         this.path = path;
45         this.defaultEnum = defaultEnum;
46         this.enums = Collections.unmodifiableList(enums);
47     }
48
49     /*
50      * (non-Javadoc)
51      *
52      * @see
53      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
54      */
55     @Override
56     public EnumTypeDefinition getBaseType() {
57         return null;
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
64      */
65     @Override
66     public String getUnits() {
67         return UNITS;
68     }
69
70     /*
71      * (non-Javadoc)
72      *
73      * @see
74      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
75      * ()
76      */
77     @Override
78     public Object getDefaultValue() {
79         return defaultEnum;
80     }
81
82     /*
83      * (non-Javadoc)
84      *
85      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
86      */
87     @Override
88     public QName getQName() {
89         return name;
90     }
91
92     /*
93      * (non-Javadoc)
94      *
95      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
96      */
97     @Override
98     public SchemaPath getPath() {
99         return path;
100     }
101
102     /*
103      * (non-Javadoc)
104      *
105      * @see
106      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
107      */
108     @Override
109     public String getDescription() {
110         return DESCRIPTION;
111     }
112
113     /*
114      * (non-Javadoc)
115      *
116      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
117      */
118     @Override
119     public String getReference() {
120         return REFERENCE;
121     }
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
127      */
128     @Override
129     public Status getStatus() {
130         return Status.CURRENT;
131     }
132
133     /*
134      * (non-Javadoc)
135      *
136      * @see
137      * org.opendaylight.yangtools.yang.model.base.type.api.EnumTypeDefinition
138      * #getValues()
139      */
140     @Override
141     public List<EnumPair> getValues() {
142         return enums;
143     }
144
145     @Override
146     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
147         return Collections.emptyList();
148     }
149
150     @Override
151     public int hashCode() {
152         final int prime = 31;
153         int result = 1;
154         result = prime * result + ((defaultEnum == null) ? 0 : defaultEnum.hashCode());
155         result = prime * result + ((enums == null) ? 0 : enums.hashCode());
156         result = prime * result + ((name == null) ? 0 : name.hashCode());
157         result = prime * result + ((path == null) ? 0 : path.hashCode());
158         return result;
159     }
160
161     @Override
162     public boolean equals(Object obj) {
163         if (this == obj) {
164             return true;
165         }
166         if (obj == null) {
167             return false;
168         }
169         if (getClass() != obj.getClass()) {
170             return false;
171         }
172         EnumerationType other = (EnumerationType) obj;
173         if (defaultEnum == null) {
174             if (other.defaultEnum != null) {
175                 return false;
176             }
177         } else if (!defaultEnum.equals(other.defaultEnum)) {
178             return false;
179         }
180         if (enums == null) {
181             if (other.enums != null) {
182                 return false;
183             }
184         } else if (!enums.equals(other.enums)) {
185             return false;
186         }
187         if (name == null) {
188             if (other.name != null) {
189                 return false;
190             }
191         } else if (!name.equals(other.name)) {
192             return false;
193         }
194         if (path == null) {
195             if (other.path != null) {
196                 return false;
197             }
198         } else if (!path.equals(other.path)) {
199             return false;
200         }
201         return true;
202     }
203
204     @Override
205     public String toString() {
206         StringBuilder builder = new StringBuilder();
207         builder.append("EnumerationType [name=");
208         builder.append(name);
209         builder.append(", path=");
210         builder.append(path);
211         builder.append(", description=");
212         builder.append(DESCRIPTION);
213         builder.append(", reference=");
214         builder.append(REFERENCE);
215         builder.append(", defaultEnum=");
216         builder.append(defaultEnum);
217         builder.append(", enums=");
218         builder.append(enums);
219         builder.append(", units=");
220         builder.append(UNITS);
221         builder.append("]");
222         return builder.toString();
223     }
224 }