cc54a44a14828ce4ebb797c9c6acd8c39cb8b289
[yangtools.git] / xpath / yang-xpath-api / src / main / java / org / opendaylight / yangtools / yang / xpath / api / BigDecimalNumberExpr.java
1 /*
2  * Copyright (c) 2019 Pantheon Technologies, s.r.o.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.xpath.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.math.BigDecimal;
13 import org.eclipse.jdt.annotation.Nullable;
14
15 final class BigDecimalNumberExpr extends YangNumberExpr {
16     private static final long serialVersionUID = 1L;
17
18     private final BigDecimal number;
19
20     private BigDecimalNumberExpr(final BigDecimal number) {
21         this.number = requireNonNull(number);
22     }
23
24     static BigDecimalNumberExpr of(final BigDecimal number) {
25         return new BigDecimalNumberExpr(number);
26     }
27
28     @Override
29     public BigDecimal getNumber() {
30         return number;
31     }
32
33     @Override
34     public BigDecimalXPathMathSupport getSupport() {
35         return BigDecimalXPathMathSupport.INSTANCE;
36     }
37
38     @Override
39     public int hashCode() {
40         return number.hashCode();
41     }
42
43     @Override
44     public boolean equals(final @Nullable Object obj) {
45         return this == obj || obj instanceof BigDecimalNumberExpr
46                 && number.equals(((BigDecimalNumberExpr) obj).number);
47     }
48
49     @Override
50     public String toString() {
51         return number.toString();
52     }
53 }