blob: 9f97bf8001abcd0ea988ec5434cf8650281574c7 [file] [log] [blame]
Vidyashree Ramaa2f73982016-04-12 23:33:33 +05301/*
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +05302 * Copyright 2016-present Open Networking Laboratory
Vidyashree Ramaa2f73982016-04-12 23:33:33 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053016
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053017package org.onosproject.yangutils.datamodel.utils.builtindatatype;
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053018
Bharat saraswal96dfef02016-06-16 00:29:12 +053019import java.io.Serializable;
20
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053021import org.onosproject.yangutils.datamodel.YangDataTypes;
22
23/**
24 * Handles the YANG's int8 data type processing.
25 *
26 * int8 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.
27 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053028public class YangInt64 implements YangBuiltInDataTypeInfo<YangInt64>, Serializable {
29
30 private static final long serialVersionUID = 8006201665L;
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053031
32 /**
33 * YANG's min keyword.
34 */
35 private static final String MIN_KEYWORD = "min";
36
37 /**
38 * YANG's max keyword.
39 */
40 private static final String MAX_KEYWORD = "max";
41
42 /**
43 * Valid minimum value of YANG's int64.
44 */
45 public static final Long MIN_VALUE = 0x8000000000000000L;
46
47 /**
48 * Valid maximum value of YANG's int64.
49 */
50 public static final long MAX_VALUE = 0x7fffffffffffffffL;
51
52 /**
53 * The value of YANG's int64.
54 */
55 private final long value;
56
57 /**
58 * Creates an object with the value initialized with value represented in
59 * string.
60 *
61 * @param valueInString value of the object in string
62 */
63 public YangInt64(String valueInString) {
64
65 if (valueInString.matches(MIN_KEYWORD)) {
66 value = MIN_VALUE;
67 } else if (valueInString.matches(MAX_KEYWORD)) {
68 value = MAX_VALUE;
69 } else {
70 try {
71 value = Long.parseLong(valueInString);
72 } catch (Exception e) {
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053073 throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
74 "int64.");
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053075 }
76 }
77 }
78
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053079 /**
80 * Returns YANG's int64 value.
81 *
82 * @return value of YANG's int64
83 */
84 public long getValue() {
85 return value;
86 }
87
88 @Override
89 public int compareTo(YangInt64 anotherYangInt64) {
90 return Long.compare(value, anotherYangInt64.value);
91 }
92
93 @Override
94 public YangDataTypes getYangType() {
95 return YangDataTypes.INT64;
96 }
97
98}