blob: 16576c977f0bfc48447f78eaf1e1c88be0945d5b [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;
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053020import java.math.BigInteger;
Bharat saraswal96dfef02016-06-16 00:29:12 +053021
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053022/**
23 * Handles the YANG's Uint16 data type processing.
24 *
25 * Uint64 represents integer values between 0 and 18446744073709551615, inclusively.
26 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053027public class YangUint64 implements YangBuiltInDataTypeInfo<YangUint64>, Serializable {
28
29 private static final long serialVersionUID = 8006201661L;
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053030
31 /**
32 * YANG's min keyword.
33 */
34 private static final String MIN_KEYWORD = "min";
35
36 /**
37 * YANG's max keyword.
38 */
39 private static final String MAX_KEYWORD = "max";
40
41 /**
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053042 * Valid minimum value of YANG's Uint64.
43 */
44 public static final BigInteger MIN_VALUE = BigInteger.valueOf(0);
45
46 /**
47 * Valid maximum value of YANG's Uint64.
48 */
49 public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
50
51 /**
52 * Value of the object.
53 */
54 private BigInteger value;
55
56 /**
57 * Creates an object with the value initialized with value represented in
58 * string.
59 *
60 * @param valueInString value of the object in string
61 */
Gaurav Agrawal72cd1b72016-06-30 13:28:14 +053062 public YangUint64(String valueInString) {
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053063
64 if (valueInString.matches(MIN_KEYWORD)) {
65 value = MIN_VALUE;
66 } else if (valueInString.matches(MAX_KEYWORD)) {
67 value = MAX_VALUE;
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053068 } else {
Mahesh Poojary S98675a92016-07-27 15:36:42 +053069 try {
70 value = new BigInteger(valueInString);
71 } catch (Exception e) {
72 throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
73 "uint64.");
74 }
Vidyashree Ramaa2f73982016-04-12 23:33:33 +053075 }
76
77 if (value.compareTo(MIN_VALUE) < 0) {
78 throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
79 + MIN_VALUE + ".");
80 } else if (value.compareTo(MAX_VALUE) > 0) {
81 throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
82 + MAX_VALUE + ".");
83 }
84 }
85
86 /**
87 * Returns YANG's uint64 value.
88 *
89 * @return value of YANG's uint64
90 */
91 public BigInteger getValue() {
92 return value;
93 }
94
95 @Override
96 public int compareTo(YangUint64 another) {
97 return value.compareTo(another.value);
98 }
99
100 @Override
101 public YangDataTypes getYangType() {
102 return YangDataTypes.UINT64;
103 }
Vidyashree Ramaa2f73982016-04-12 23:33:33 +0530104}