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