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