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