2 * Copyright (c) 2019 Pantheon Technologies, s.r.o. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.xpath.api;
10 final class DoubleXPathMathSupport extends AbstractYangXPathMathSupport<DoubleNumberExpr> {
11 static final DoubleXPathMathSupport INSTANCE = new DoubleXPathMathSupport();
13 private DoubleXPathMathSupport() {
14 super(DoubleNumberExpr.class);
18 public DoubleNumberExpr createNumber(final String str) {
19 return DoubleNumberExpr.of(Double.parseDouble(str));
23 public DoubleNumberExpr createNumber(final int value) {
24 return DoubleNumberExpr.of(value);
28 protected DoubleNumberExpr doNegateNumber(final DoubleNumberExpr number) {
29 return DoubleNumberExpr.of(-number.getValue());
33 protected YangExpr doEvaluate(final YangBinaryOperator operator, final DoubleNumberExpr left,
34 final DoubleNumberExpr right) {
35 final double l = left.getValue();
36 final double r = right.getValue();
44 return YangBooleanConstantExpr.of(left.equals(right));
46 return YangBooleanConstantExpr.of(l > r);
48 return YangBooleanConstantExpr.of(l >= r);
50 return YangBooleanConstantExpr.of(l < r);
52 return YangBooleanConstantExpr.of(l <= r);
63 return YangBooleanConstantExpr.of(!left.equals(right));
68 throw new IllegalStateException("Unhandled operator " + operator);
71 return DoubleNumberExpr.of(result);