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