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 import java.math.BigDecimal;
12 final class BigDecimalXPathMathSupport extends AbstractYangXPathMathSupport<BigDecimalNumberExpr> {
13 static final BigDecimalXPathMathSupport INSTANCE = new BigDecimalXPathMathSupport();
15 private static final long serialVersionUID = 1L;
16 private static final BigDecimalNumberExpr ZERO = BigDecimalNumberExpr.of(BigDecimal.ZERO);
17 private static final BigDecimalNumberExpr ONE = BigDecimalNumberExpr.of(BigDecimal.ONE);
18 private static final BigDecimalNumberExpr TEN = BigDecimalNumberExpr.of(BigDecimal.TEN);
20 private BigDecimalXPathMathSupport() {
21 super(BigDecimalNumberExpr.class);
25 public BigDecimalNumberExpr createNumber(final String str) {
34 return BigDecimalNumberExpr.of(new BigDecimal(str));
39 public BigDecimalNumberExpr createNumber(final int value) {
48 return BigDecimalNumberExpr.of(BigDecimal.valueOf(value));
53 protected BigDecimalNumberExpr doNegateNumber(final BigDecimalNumberExpr number) {
54 return BigDecimalNumberExpr.of(number.getNumber().negate());
58 protected YangExpr doEvaluate(final YangBinaryOperator operator, final BigDecimalNumberExpr left,
59 final BigDecimalNumberExpr right) {
60 final BigDecimal l = left.getNumber();
61 final BigDecimal r = right.getNumber();
63 final BigDecimal result;
69 return YangBooleanConstantExpr.of(l.equals(r));
71 return YangBooleanConstantExpr.of(l.compareTo(r) > 0);
73 return YangBooleanConstantExpr.of(l.compareTo(r) >= 0);
75 return YangBooleanConstantExpr.of(l.compareTo(r) < 0);
77 return YangBooleanConstantExpr.of(l.compareTo(r) <= 0);
79 result = l.subtract(r);
82 result = l.remainder(r);
85 result = l.multiply(r);
88 return YangBooleanConstantExpr.of(!l.equals(r));
93 throw new IllegalStateException("Unhandled operator " + operator);
96 return BigDecimalNumberExpr.of(result);
100 protected Object readResolve() {