BUG-865: Remove deprecated methods in yang.model.util
[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      * Constructor with explicit definition of bits assigned to BitsType.
38      *
39      * @param path
40      * @param bits
41      */
42     private BitsType(final SchemaPath path, final List<Bit> bits) {
43         super();
44         this.bits = ImmutableList.copyOf(bits);
45         this.path = Preconditions.checkNotNull(path, "path must not be null");
46     }
47
48     public static BitsType create(final SchemaPath path, final List<Bit> bits) {
49         return new BitsType(path,bits);
50     }
51
52     /*
53      * (non-Javadoc)
54      *
55      * @see
56      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
57      */
58     @Override
59     public BitsTypeDefinition getBaseType() {
60         return null;
61     }
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
67      */
68     @Override
69     public String getUnits() {
70         return UNITS;
71     }
72
73     /*
74      * (non-Javadoc)
75      *
76      * @see
77      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
78      * ()
79      */
80     @Override
81     public Object getDefaultValue() {
82         return bits;
83     }
84
85     /*
86      * (non-Javadoc)
87      *
88      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
89      */
90     @Override
91     public QName getQName() {
92         return NAME;
93     }
94
95     /*
96      * (non-Javadoc)
97      *
98      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
99      */
100     @Override
101     public SchemaPath getPath() {
102         return path;
103     }
104
105     /*
106      * (non-Javadoc)
107      *
108      * @see
109      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
110      */
111     @Override
112     public String getDescription() {
113         return DESCRIPTION;
114     }
115
116     /*
117      * (non-Javadoc)
118      *
119      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
120      */
121     @Override
122     public String getReference() {
123         return REFERENCE;
124     }
125
126     /*
127      * (non-Javadoc)
128      *
129      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
130      */
131     @Override
132     public Status getStatus() {
133         return Status.CURRENT;
134     }
135
136     @Override
137     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
138         return Collections.emptyList();
139     }
140
141     @Override
142     public List<Bit> getBits() {
143         return bits;
144     }
145
146     @Override
147     public int hashCode() {
148         final int prime = 31;
149         int result = 1;
150         result = prime * result + ((bits == null) ? 0 : bits.hashCode());
151         result = prime * result + NAME.hashCode();
152         result = prime * result + path.hashCode();
153         return result;
154     }
155
156     @Override
157     public boolean equals(final Object obj) {
158         if (this == obj) {
159             return true;
160         }
161         if (obj == null) {
162             return false;
163         }
164         if (getClass() != obj.getClass()) {
165             return false;
166         }
167         BitsType other = (BitsType) obj;
168         if (bits == null) {
169             if (other.bits != null) {
170                 return false;
171             }
172         } else if (!bits.equals(other.bits)) {
173             return false;
174         }
175         if (path == null) {
176             if (other.path != null) {
177                 return false;
178             }
179         } else if (!path.equals(other.path)) {
180             return false;
181         }
182         return true;
183     }
184
185     @Override
186     public String toString() {
187         StringBuilder builder = new StringBuilder();
188         builder.append("BitsType [name=");
189         builder.append(NAME);
190         builder.append(", path=");
191         builder.append(path);
192         builder.append(", description=");
193         builder.append(DESCRIPTION);
194         builder.append(", reference=");
195         builder.append(REFERENCE);
196         builder.append(", bits=");
197         builder.append(bits);
198         builder.append(", units=");
199         builder.append(UNITS);
200         builder.append("]");
201         return builder.toString();
202     }
203 }