0e100dc79077d846d2f0ae83ce3dd4768cefdcec
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / Int16.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.net.URI;
11 import java.util.Date;
12 import java.util.List;
13
14 import org.opendaylight.controller.yang.common.QName;
15 import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
16 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
17
18 /**
19  * Implementation of Yang int16 built-in type. <br>
20  * int16 represents integer values between -32768 and 32767, inclusively. The
21  * Java counterpart of Yang int16 built-in type is {@link Short}.
22  *
23  * @see AbstractSignedInteger
24  */
25 public class Int16 extends AbstractSignedInteger {
26
27     private static final QName name = BaseTypes.constructQName("int16");
28     private Short defaultValue = null;
29     private static final String description =
30             "int16  represents integer values between -32768 and 32767, inclusively.";
31     private final IntegerTypeDefinition baseType;
32
33     private Int16() {
34         super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
35         this.baseType = this;
36     }
37
38     public Int16(final List<String> actualPath, final URI namespace,
39             final Date revision) {
40         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
41         this.baseType = new Int16();
42
43     }
44
45     public Int16(final List<String> actualPath, final URI namespace,
46             final Date revision, final List<RangeConstraint> rangeStatements,
47             final String units, final Short defaultValue) {
48         super(actualPath, namespace, revision, name, description, rangeStatements, units);
49         this.defaultValue = defaultValue;
50         this.baseType = new Int16();
51     }
52
53     @Override
54     public IntegerTypeDefinition getBaseType() {
55         return baseType;
56     }
57
58     @Override
59     public Object getDefaultValue() {
60         return defaultValue;
61     }
62
63     @Override
64     public int hashCode() {
65         final int prime = 31;
66         int result = super.hashCode();
67         result = prime * result
68                 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
69         return result;
70     }
71
72     @Override
73     public boolean equals(Object obj) {
74         if (this == obj) {
75             return true;
76         }
77         if (!super.equals(obj)) {
78             return false;
79         }
80         if (getClass() != obj.getClass()) {
81             return false;
82         }
83         Int16 other = (Int16) obj;
84         if (defaultValue == null) {
85             if (other.defaultValue != null) {
86                 return false;
87             }
88         } else if (!defaultValue.equals(other.defaultValue)) {
89             return false;
90         }
91         return true;
92     }
93
94     @Override
95     public String toString() {
96         StringBuilder builder = new StringBuilder();
97         builder.append("Int16 [defaultValue=");
98         builder.append(defaultValue);
99         builder.append(", AbstractInteger=");
100         builder.append(super.toString());
101         builder.append("]");
102         return builder.toString();
103     }
104 }