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