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