blob: ca45073915f750e86630fec4df8fb656e93e6b57 [file] [log] [blame]
Bharat saraswal33dfa012016-05-17 19:59:16 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
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 */
16
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053017package org.onosproject.yangutils.datamodel.utils.builtindatatype;
Bharat saraswal33dfa012016-05-17 19:59:16 +053018
19import java.util.Objects;
Bharat saraswal33dfa012016-05-17 19:59:16 +053020import com.google.common.base.MoreObjects;
21
22/**
23 * Represents YANG decimal 64.
24 */
25public class YangDecimal64 {
26
27 private int fractionDigit;
28
29 /**
30 * Creates an instance of YANG decimal64.
31 */
32 public YangDecimal64() {
33 }
34
35 /**
36 * Creates an instance of of YANG decimal64.
37 *
38 * @param fractionDigit fraction digit
39 */
40 public YangDecimal64(int fractionDigit) {
41 this.setFractionDigit(fractionDigit);
42 }
43
44 /**
45 * Returns fraction digit.
46 *
47 * @return the fractionDigit
48 */
49 public int getFractionDigit() {
50 return fractionDigit;
51 }
52
53 /**
54 * Sets fraction digit.
55 *
56 * @param fractionDigit fraction digits.
57 */
58 public void setFractionDigit(int fractionDigit) {
59 this.fractionDigit = fractionDigit;
60 }
61
62 /**
63 * Returns object of YANG decimal64.
64 *
65 * @param value fraction digit
66 * @return YANG decimal64
67 */
68 public static YangDecimal64 of(int value) {
69 return new YangDecimal64(value);
70 }
71
72 @Override
73 public int hashCode() {
74 return Objects.hash(fractionDigit);
75 }
76
77 @Override
78 public boolean equals(Object obj) {
79 if (this == obj) {
80 return true;
81 }
82 if (obj instanceof YangDecimal64) {
83 YangDecimal64 other = (YangDecimal64) obj;
84 return Objects.equals(fractionDigit, other.fractionDigit);
85 }
86 return false;
87 }
88
89 @Override
90 public String toString() {
91 return MoreObjects.toStringHelper(getClass())
92 .omitNullValues()
93 .add("fractionDigit", fractionDigit)
94 .toString();
95 }
96
97 /**
98 * Returns the object of YANG decimal64 fromString input String.
99 *
100 * @param valInString input String
101 * @return Object of YANG decimal64
102 */
103 public static YangDecimal64 fromString(String valInString) {
104 try {
105 int tmpVal = Integer.parseInt(valInString);
106 return of(tmpVal);
107 } catch (Exception e) {
108 }
109 return null;
110 }
111}