Refactored base yang-java types.
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / BinaryType.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.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
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.BinaryTypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
20
21 /**
22  * The <code>default</code> implementation of Binary Type Definition interface.
23  *
24  * @see BinaryTypeDefinition
25  */
26 public final class BinaryType implements BinaryTypeDefinition {
27     private static final BinaryType INSTANCE = new BinaryType();
28     private final QName name = BaseTypes.constructQName("binary");
29     private final SchemaPath path = new SchemaPath(Collections.singletonList(name), true);
30     private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
31     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8";
32     private final List<Byte> bytes;
33     private final List<LengthConstraint> lengthConstraints;
34     private final String units = "";
35
36     private BinaryType() {
37         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
38         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
39         this.lengthConstraints = Collections.unmodifiableList(constraints);
40         this.bytes = Collections.emptyList();
41     }
42
43     public static BinaryType getInstance() {
44         return INSTANCE;
45     }
46
47     /*
48      * (non-Javadoc)
49      *
50      * @see
51      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
52      */
53     @Override
54     public BinaryTypeDefinition getBaseType() {
55         return this;
56     }
57
58     /*
59      * (non-Javadoc)
60      *
61      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
62      */
63     @Override
64     public String getUnits() {
65         return units;
66     }
67
68     /*
69      * (non-Javadoc)
70      *
71      * @see
72      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
73      * ()
74      */
75     @Override
76     public Object getDefaultValue() {
77         return bytes;
78     }
79
80     /*
81      * (non-Javadoc)
82      *
83      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
84      */
85     @Override
86     public QName getQName() {
87         return name;
88     }
89
90     /*
91      * (non-Javadoc)
92      *
93      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
94      */
95     @Override
96     public SchemaPath getPath() {
97         return path;
98     }
99
100     /*
101      * (non-Javadoc)
102      *
103      * @see
104      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
105      */
106     @Override
107     public String getDescription() {
108         return description;
109     }
110
111     /*
112      * (non-Javadoc)
113      *
114      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
115      */
116     @Override
117     public String getReference() {
118         return reference;
119     }
120
121     /*
122      * (non-Javadoc)
123      *
124      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
125      */
126     @Override
127     public Status getStatus() {
128         return Status.CURRENT;
129     }
130
131     /*
132      * (non-Javadoc)
133      *
134      * @see
135      * org.opendaylight.yangtools.yang.model.base.type.api.BinaryTypeDefinition
136      * #getLengthConstraint ()
137      */
138     @Override
139     public List<LengthConstraint> getLengthConstraints() {
140         return lengthConstraints;
141     }
142
143     @Override
144     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
145         return Collections.emptyList();
146     }
147
148     @Override
149     public int hashCode() {
150         final int prime = 31;
151         int result = 1;
152         result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
153         result = prime * result + ((description == null) ? 0 : description.hashCode());
154         result = prime * result + ((lengthConstraints == null) ? 0 : lengthConstraints.hashCode());
155         result = prime * result + ((name == null) ? 0 : name.hashCode());
156         result = prime * result + ((path == null) ? 0 : path.hashCode());
157         result = prime * result + ((reference == null) ? 0 : reference.hashCode());
158         result = prime * result + ((units == null) ? 0 : units.hashCode());
159         return result;
160     }
161
162     @Override
163     public boolean equals(Object obj) {
164         if (this == obj) {
165             return true;
166         }
167         if (obj == null) {
168             return false;
169         }
170         if (getClass() != obj.getClass()) {
171             return false;
172         }
173         BinaryType other = (BinaryType) obj;
174         if (bytes == null) {
175             if (other.bytes != null) {
176                 return false;
177             }
178         } else if (!bytes.equals(other.bytes)) {
179             return false;
180         }
181         if (description == null) {
182             if (other.description != null) {
183                 return false;
184             }
185         } else if (!description.equals(other.description)) {
186             return false;
187         }
188         if (lengthConstraints == null) {
189             if (other.lengthConstraints != null) {
190                 return false;
191             }
192         } else if (!lengthConstraints.equals(other.lengthConstraints)) {
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("BinaryType [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(", bytes=");
238         builder.append(bytes);
239         builder.append(", lengthConstraints=");
240         builder.append(lengthConstraints);
241         builder.append(", units=");
242         builder.append(units);
243         builder.append("]");
244         return builder.toString();
245     }
246 }