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