blob: 6b0b685a108ed678627d9a7a40bdb9278d460194 [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
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053017package org.onosproject.yangutils.utils.builtindatatype;
18
19import org.onosproject.yangutils.datamodel.YangDataTypes;
20
21/**
22 * Handles the YANG's int8 data type processing.
23 *
24 * int8 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.
25 */
26public class YangInt64 implements YangBuiltInDataTypeInfo<YangInt64> {
27
28 /**
29 * YANG's min keyword.
30 */
31 private static final String MIN_KEYWORD = "min";
32
33 /**
34 * YANG's max keyword.
35 */
36 private static final String MAX_KEYWORD = "max";
37
38 /**
39 * Valid minimum value of YANG's int64.
40 */
41 public static final Long MIN_VALUE = 0x8000000000000000L;
42
43 /**
44 * Valid maximum value of YANG's int64.
45 */
46 public static final long MAX_VALUE = 0x7fffffffffffffffL;
47
48 /**
49 * The value of YANG's int64.
50 */
51 private final long value;
52
53 /**
54 * Creates an object with the value initialized with value represented in
55 * string.
56 *
57 * @param valueInString value of the object in string
58 */
59 public YangInt64(String valueInString) {
60
61 if (valueInString.matches(MIN_KEYWORD)) {
62 value = MIN_VALUE;
63 } else if (valueInString.matches(MAX_KEYWORD)) {
64 value = MAX_VALUE;
65 } else {
66 try {
67 value = Long.parseLong(valueInString);
68 } catch (Exception e) {
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053069 throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
70 "int64.");
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053071 }
72 }
73 }
74
75
76 /**
77 * Returns YANG's int64 value.
78 *
79 * @return value of YANG's int64
80 */
81 public long getValue() {
82 return value;
83 }
84
85 @Override
86 public int compareTo(YangInt64 anotherYangInt64) {
87 return Long.compare(value, anotherYangInt64.value);
88 }
89
90 @Override
91 public YangDataTypes getYangType() {
92 return YangDataTypes.INT64;
93 }
94
95}