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 / 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 org.opendaylight.controller.yang.common.QName;
11 import org.opendaylight.controller.yang.model.api.SchemaPath;
12 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
13
14 /**
15  * Implementation of Yang uint8 built-in type.
16  * <br>
17  * uint8 represents integer values between 0 and 255, inclusively. The Java counterpart of
18  * Yang uint8 built-in type is {@link Short}.
19  *
20  * @see AbstractUnsignedInteger
21  */
22 public final class Uint8 extends AbstractUnsignedInteger {
23
24     private static final QName name = BaseTypes.constructQName("uint8");
25     private final Short defaultValue = null;
26     private static final String description =
27             "uint8  represents integer values between 0 and 255, inclusively.";
28     private final UnsignedIntegerTypeDefinition baseType;
29
30     public Uint8(final SchemaPath path) {
31         super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
32         this.baseType = this;
33     }
34
35     /*
36      * (non-Javadoc)
37      *
38      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
39      */
40     @Override
41     public UnsignedIntegerTypeDefinition getBaseType() {
42         return baseType;
43     }
44
45     /*
46      * (non-Javadoc)
47      *
48      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
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         Uint8 other = (Uint8) 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("Uint8 [defaultValue=");
90         builder.append(defaultValue);
91         builder.append(", AbstractInteger=");
92         builder.append(super.toString());
93         builder.append("]");
94         return builder.toString();
95     }
96 }