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