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