Populate model/ hierarchy
[yangtools.git] / xpath / yang-xpath-api / src / main / java / org / opendaylight / yangtools / yang / xpath / api / DoubleNumberExpr.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 org.eclipse.jdt.annotation.Nullable;
11
12 final class DoubleNumberExpr extends YangNumberExpr {
13     private static final long serialVersionUID = 1L;
14
15     private final double value;
16
17     private DoubleNumberExpr(final double value) {
18         this.value = value;
19     }
20
21     static DoubleNumberExpr of(final double value) {
22         return new DoubleNumberExpr(value);
23     }
24
25     double getValue() {
26         return value;
27     }
28
29     @Override
30     public Double getNumber() {
31         return value;
32     }
33
34     @Override
35     public DoubleXPathMathSupport getSupport() {
36         return DoubleXPathMathSupport.INSTANCE;
37     }
38
39     @Override
40     public int hashCode() {
41         return Double.hashCode(value);
42     }
43
44     @Override
45     public boolean equals(final @Nullable Object obj) {
46         return this == obj || obj instanceof DoubleNumberExpr && bitEqual(((DoubleNumberExpr) obj).value);
47     }
48
49     private boolean bitEqual(final double other) {
50         return Double.doubleToLongBits(value) == Double.doubleToLongBits(other);
51     }
52
53     @Override
54     public String toString() {
55         return String.valueOf(value);
56     }
57 }