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