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