Fix modifier ordering
[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 com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableList;
12 import java.util.Collections;
13 import java.util.List;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
19
20 /**
21  * The <code>default</code> implementation of Bits Type Definition interface.
22  *
23  * @see BitsTypeDefinition
24  */
25 public final class BitsType implements BitsTypeDefinition {
26     private static final QName NAME = BaseTypes.BITS_QNAME;
27     private static 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 static final String UNITS = "";
33     private final SchemaPath path;
34     private final List<Bit> bits;
35
36     /**
37      * Default constructor. <br>
38      * Instantiates Bits type as empty bits list.
39      *
40      * @param path
41      * @deprecated Use static factory method {@link #create(SchemaPath, List)} instead.
42      */
43     @Deprecated
44     public BitsType(final SchemaPath path) {
45         super();
46         this.bits = Collections.emptyList();
47         this.path = Preconditions.checkNotNull(path,"path must not be null");
48     }
49
50     /**
51      * Constructor with explicit definition of bits assigned to BitsType.
52      *
53      * @param path
54      * @param bits
55      * @deprecated Use static factory method {@link #create(SchemaPath, List)} instead.
56      */
57     @Deprecated
58     public BitsType(final SchemaPath path, final List<Bit> bits) {
59         super();
60         this.bits = ImmutableList.copyOf(bits);
61         this.path = Preconditions.checkNotNull(path,"path must not be null");
62     }
63
64     public static BitsType create(final SchemaPath path, final List<Bit> bits) {
65         return new BitsType(path,bits);
66     }
67
68     /*
69      * (non-Javadoc)
70      *
71      * @see
72      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
73      */
74     @Override
75     public BitsTypeDefinition getBaseType() {
76         return null;
77     }
78
79     /*
80      * (non-Javadoc)
81      *
82      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
83      */
84     @Override
85     public String getUnits() {
86         return UNITS;
87     }
88
89     /*
90      * (non-Javadoc)
91      *
92      * @see
93      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
94      * ()
95      */
96     @Override
97     public Object getDefaultValue() {
98         return bits;
99     }
100
101     /*
102      * (non-Javadoc)
103      *
104      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
105      */
106     @Override
107     public QName getQName() {
108         return NAME;
109     }
110
111     /*
112      * (non-Javadoc)
113      *
114      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
115      */
116     @Override
117     public SchemaPath getPath() {
118         return path;
119     }
120
121     /*
122      * (non-Javadoc)
123      *
124      * @see
125      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
126      */
127     @Override
128     public String getDescription() {
129         return DESCRIPTION;
130     }
131
132     /*
133      * (non-Javadoc)
134      *
135      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
136      */
137     @Override
138     public String getReference() {
139         return REFERENCE;
140     }
141
142     /*
143      * (non-Javadoc)
144      *
145      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
146      */
147     @Override
148     public Status getStatus() {
149         return Status.CURRENT;
150     }
151
152     @Override
153     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
154         return Collections.emptyList();
155     }
156
157     @Override
158     public List<Bit> getBits() {
159         return bits;
160     }
161
162     @Override
163     public int hashCode() {
164         final int prime = 31;
165         int result = 1;
166         result = prime * result + ((bits == null) ? 0 : bits.hashCode());
167         result = prime * result + NAME.hashCode();
168         result = prime * result + path.hashCode();
169         return result;
170     }
171
172     @Override
173     public boolean equals(final 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 (path == null) {
192             if (other.path != null) {
193                 return false;
194             }
195         } else if (!path.equals(other.path)) {
196             return false;
197         }
198         return true;
199     }
200
201     @Override
202     public String toString() {
203         StringBuilder builder = new StringBuilder();
204         builder.append("BitsType [name=");
205         builder.append(NAME);
206         builder.append(", path=");
207         builder.append(path);
208         builder.append(", description=");
209         builder.append(DESCRIPTION);
210         builder.append(", reference=");
211         builder.append(REFERENCE);
212         builder.append(", bits=");
213         builder.append(bits);
214         builder.append(", units=");
215         builder.append(UNITS);
216         builder.append("]");
217         return builder.toString();
218     }
219 }