blob: 74c657b01b13750438c419768221aa1d33a24d81 [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
Bharat saraswal96dfef02016-06-16 00:29:12 +053019import java.io.Serializable;
Bharat saraswal33dfa012016-05-17 19:59:16 +053020import java.util.Objects;
Bharat saraswal96dfef02016-06-16 00:29:12 +053021
Bharat saraswal33dfa012016-05-17 19:59:16 +053022import com.google.common.base.MoreObjects;
23
24/**
25 * Represents YANG decimal 64.
26 */
Bharat saraswal96dfef02016-06-16 00:29:12 +053027public class YangDecimal64 implements Serializable {
28
29 private static final long serialVersionUID = 8006201668L;
Bharat saraswal33dfa012016-05-17 19:59:16 +053030
31 private int fractionDigit;
32
33 /**
34 * Creates an instance of YANG decimal64.
35 */
36 public YangDecimal64() {
37 }
38
39 /**
40 * Creates an instance of of YANG decimal64.
41 *
42 * @param fractionDigit fraction digit
43 */
44 public YangDecimal64(int fractionDigit) {
Bharat saraswal96dfef02016-06-16 00:29:12 +053045 setFractionDigit(fractionDigit);
Bharat saraswal33dfa012016-05-17 19:59:16 +053046 }
47
48 /**
49 * Returns fraction digit.
50 *
51 * @return the fractionDigit
52 */
53 public int getFractionDigit() {
54 return fractionDigit;
55 }
56
57 /**
58 * Sets fraction digit.
59 *
60 * @param fractionDigit fraction digits.
61 */
62 public void setFractionDigit(int fractionDigit) {
63 this.fractionDigit = fractionDigit;
64 }
65
66 /**
67 * Returns object of YANG decimal64.
68 *
69 * @param value fraction digit
70 * @return YANG decimal64
71 */
72 public static YangDecimal64 of(int value) {
73 return new YangDecimal64(value);
74 }
75
76 @Override
77 public int hashCode() {
78 return Objects.hash(fractionDigit);
79 }
80
81 @Override
82 public boolean equals(Object obj) {
83 if (this == obj) {
84 return true;
85 }
86 if (obj instanceof YangDecimal64) {
87 YangDecimal64 other = (YangDecimal64) obj;
88 return Objects.equals(fractionDigit, other.fractionDigit);
89 }
90 return false;
91 }
92
93 @Override
94 public String toString() {
95 return MoreObjects.toStringHelper(getClass())
96 .omitNullValues()
97 .add("fractionDigit", fractionDigit)
98 .toString();
99 }
100
101 /**
102 * Returns the object of YANG decimal64 fromString input String.
103 *
104 * @param valInString input String
105 * @return Object of YANG decimal64
106 */
107 public static YangDecimal64 fromString(String valInString) {
108 try {
109 int tmpVal = Integer.parseInt(valInString);
110 return of(tmpVal);
111 } catch (Exception e) {
112 }
113 return null;
114 }
115}