2 * Copyright (c) 2018 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.impl;
10 import java.util.Optional;
11 import java.util.function.Function;
12 import org.opendaylight.yangtools.yang.common.QNameModule;
13 import org.opendaylight.yangtools.yang.xpath.api.YangBinaryOperator;
14 import org.opendaylight.yangtools.yang.xpath.api.YangBooleanConstantExpr;
15 import org.opendaylight.yangtools.yang.xpath.api.YangExpr;
16 import org.opendaylight.yangtools.yang.xpath.api.YangNumberExpr.YangDouble;
18 final class DoubleXPathParser extends XPathParser<YangDouble> {
20 DoubleXPathParser(final QNameModule implicitNamespace, final Function<String, QNameModule> prefixes) {
21 super(implicitNamespace, prefixes);
25 YangDouble createNumber(final String str) {
26 return YangDouble.of(Double.parseDouble(str));
30 YangDouble negateNumber(final YangDouble number) {
31 return YangDouble.of(-number.getValue());
35 Optional<YangExpr> simplifyNumbers(final YangBinaryOperator operator, final YangDouble left,
36 final YangDouble right) {
37 final double l = left.getValue();
38 final double r = right.getValue();
70 throw new IllegalStateException("Unhandled operator " + operator);
73 return Optional.of(YangDouble.of(result));
76 private static Optional<YangExpr> of(final boolean value) {
77 return Optional.of(YangBooleanConstantExpr.of(value));