Vidyashree Rama | a2f7398 | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 1 | /* |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vidyashree Rama | a2f7398 | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 3 | * |
| 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 Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 16 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 17 | package org.onosproject.yangutils.datamodel.utils.builtindatatype; |
Vidyashree Rama | a2f7398 | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 18 | |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame^] | 19 | import java.io.Serializable; |
| 20 | |
Vidyashree Rama | a2f7398 | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 21 | import 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 saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame^] | 28 | public class YangInt64 implements YangBuiltInDataTypeInfo<YangInt64>, Serializable { |
| 29 | |
| 30 | private static final long serialVersionUID = 8006201665L; |
Vidyashree Rama | a2f7398 | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 31 | |
| 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 Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 73 | throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " + |
| 74 | "int64."); |
Vidyashree Rama | a2f7398 | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
Vidyashree Rama | a2f7398 | 2016-04-12 23:33:33 +0530 | [diff] [blame] | 79 | /** |
| 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 | } |