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 private static final DoubleXPathMathSupport INSTANCE = new DoubleXPathMathSupport();
13 private DoubleXPathMathSupport() {
14 super(DoubleNumberExpr.class);
17 static DoubleXPathMathSupport getInstance() {
22 public DoubleNumberExpr createNumber(final String str) {
23 return DoubleNumberExpr.of(Double.parseDouble(str));
27 DoubleNumberExpr doNegate(final DoubleNumberExpr number) {
28 return DoubleNumberExpr.of(-number.getValue());
32 YangExpr evaluate(final YangBinaryOperator operator, final DoubleNumberExpr left, final DoubleNumberExpr right) {
33 final double l = left.getValue();
34 final double r = right.getValue();
42 return YangBooleanConstantExpr.of(left.equals(right));
44 return YangBooleanConstantExpr.of(l > r);
46 return YangBooleanConstantExpr.of(l >= r);
48 return YangBooleanConstantExpr.of(l < r);
50 return YangBooleanConstantExpr.of(l <= r);
61 return YangBooleanConstantExpr.of(!left.equals(right));
66 throw new IllegalStateException("Unhandled operator " + operator);
69 return DoubleNumberExpr.of(result);