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 static final long serialVersionUID = 1L;
15 private DoubleXPathMathSupport() {
16 super(DoubleNumberExpr.class);
20 public DoubleNumberExpr createNumber(final String str) {
21 return DoubleNumberExpr.of(Double.parseDouble(str));
25 public DoubleNumberExpr createNumber(final int value) {
26 return DoubleNumberExpr.of(value);
30 protected DoubleNumberExpr doNegateNumber(final DoubleNumberExpr number) {
31 return DoubleNumberExpr.of(-number.getValue());
35 protected YangExpr doEvaluate(final YangBinaryOperator operator, final DoubleNumberExpr left,
36 final DoubleNumberExpr right) {
37 final double l = left.getValue();
38 final double r = right.getValue();
40 return switch (operator) {
41 case DIV -> DoubleNumberExpr.of(l / r);
42 case EQUALS -> YangBooleanConstantExpr.of(left.equals(right));
43 case GT -> YangBooleanConstantExpr.of(l > r);
44 case GTE -> YangBooleanConstantExpr.of(l >= r);
45 case LT -> YangBooleanConstantExpr.of(l < r);
46 case LTE -> YangBooleanConstantExpr.of(l <= r);
47 case MINUS -> DoubleNumberExpr.of(l - r);
48 case MOD -> DoubleNumberExpr.of(l % r);
49 case MUL -> DoubleNumberExpr.of(l * r);
50 case NOT_EQUALS -> YangBooleanConstantExpr.of(!left.equals(right));
51 case PLUS -> DoubleNumberExpr.of(l + r);
56 protected Object readResolve() {