Modified construction of built-in yang types.
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / 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.controller.yang.model.util;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.controller.yang.common.QName;
14 import org.opendaylight.controller.yang.model.api.SchemaPath;
15 import org.opendaylight.controller.yang.model.api.Status;
16 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.controller.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 final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7";
32     private final BitsTypeDefinition baseType;
33     private final List<Bit> bits;
34     private final String units = "";
35
36     /**
37      * Default constructor. <br>
38      * Instantiates Bits type as empty bits list.
39      */
40     public BitsType(final SchemaPath path) {
41         super();
42         this.bits = Collections.emptyList();
43         this.path = path;
44         this.baseType = this;
45     }
46
47     /**
48      * Constructor with explicit definition of bits assigned to BitsType.
49      *
50      * @param actualPath
51      * @param namespace
52      * @param revision
53      * @param bits
54      *            The bits assigned for Bits Type
55      */
56     public BitsType(final SchemaPath path, final List<Bit> bits) {
57         super();
58         this.bits = Collections.unmodifiableList(bits);
59         this.path = path;
60         this.baseType = this;
61     }
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see
67      * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
68      */
69     @Override
70     public BitsTypeDefinition getBaseType() {
71         return baseType;
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
78      */
79     @Override
80     public String getUnits() {
81         return units;
82     }
83
84     /*
85      * (non-Javadoc)
86      *
87      * @see
88      * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
89      * ()
90      */
91     @Override
92     public Object getDefaultValue() {
93         return bits;
94     }
95
96     /*
97      * (non-Javadoc)
98      *
99      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
100      */
101     @Override
102     public QName getQName() {
103         return name;
104     }
105
106     /*
107      * (non-Javadoc)
108      *
109      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
110      */
111     @Override
112     public SchemaPath getPath() {
113         return path;
114     }
115
116     /*
117      * (non-Javadoc)
118      *
119      * @see
120      * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
121      */
122     @Override
123     public String getDescription() {
124         return description;
125     }
126
127     /*
128      * (non-Javadoc)
129      *
130      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
131      */
132     @Override
133     public String getReference() {
134         return reference;
135     }
136
137     /*
138      * (non-Javadoc)
139      *
140      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
141      */
142     @Override
143     public Status getStatus() {
144         return Status.CURRENT;
145     }
146
147     @Override
148     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
149         return Collections.emptyList();
150     }
151
152     @Override
153     public List<Bit> getBits() {
154         return bits;
155     }
156
157     @Override
158     public int hashCode() {
159         final int prime = 31;
160         int result = 1;
161         result = prime * result + ((bits == null) ? 0 : bits.hashCode());
162         result = prime * result
163                 + ((description == null) ? 0 : description.hashCode());
164         result = prime * result + ((name == null) ? 0 : name.hashCode());
165         result = prime * result + ((path == null) ? 0 : path.hashCode());
166         result = prime * result
167                 + ((reference == null) ? 0 : reference.hashCode());
168         result = prime * result + ((units == null) ? 0 : units.hashCode());
169         return result;
170     }
171
172     @Override
173     public boolean equals(Object obj) {
174         if (this == obj) {
175             return true;
176         }
177         if (obj == null) {
178             return false;
179         }
180         if (getClass() != obj.getClass()) {
181             return false;
182         }
183         BitsType other = (BitsType) obj;
184         if (bits == null) {
185             if (other.bits != null) {
186                 return false;
187             }
188         } else if (!bits.equals(other.bits)) {
189             return false;
190         }
191         if (description == null) {
192             if (other.description != null) {
193                 return false;
194             }
195         } else if (!description.equals(other.description)) {
196             return false;
197         }
198         if (name == null) {
199             if (other.name != null) {
200                 return false;
201             }
202         } else if (!name.equals(other.name)) {
203             return false;
204         }
205         if (path == null) {
206             if (other.path != null) {
207                 return false;
208             }
209         } else if (!path.equals(other.path)) {
210             return false;
211         }
212         if (reference == null) {
213             if (other.reference != null) {
214                 return false;
215             }
216         } else if (!reference.equals(other.reference)) {
217             return false;
218         }
219         if (units == null) {
220             if (other.units != null) {
221                 return false;
222             }
223         } else if (!units.equals(other.units)) {
224             return false;
225         }
226         return true;
227     }
228
229     @Override
230     public String toString() {
231         StringBuilder builder = new StringBuilder();
232         builder.append("BitsType [name=");
233         builder.append(name);
234         builder.append(", path=");
235         builder.append(path);
236         builder.append(", description=");
237         builder.append(description);
238         builder.append(", reference=");
239         builder.append(reference);
240         builder.append(", bits=");
241         builder.append(bits);
242         builder.append(", units=");
243         builder.append(units);
244         builder.append("]");
245         return builder.toString();
246     }
247 }