Update yang-xpath-api design
[yangtools.git] / yang / yang-xpath-api / src / main / java / org / opendaylight / yangtools / yang / xpath / api / YangXPathMathSupport.java
1 /*
2  * Copyright (c) 2019 Pantheon Technologies, s.r.o.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.xpath.api;
9
10 import com.google.common.annotations.Beta;
11 import java.util.Optional;
12
13 @Beta
14 public interface YangXPathMathSupport<N extends YangNumberExpr<N, ?>> {
15     /**
16      * Create a {@link YangNumberExpr} backed by specified string.
17      *
18      * @param str String
19      * @return number expression
20      * @throws NullPointerException if {@code str} is null
21      * @throws NumberFormatException if the string does not represent a valid number
22      */
23     N createNumber(String str);
24
25     /**
26      * Create a {@link YangNumberExpr} representing the negated value of a number.
27      *
28      * @param number input number
29      * @return negated number expression
30      * @throws NullPointerException if {@code number} is null
31      * @throws IllegalArgumentException if {@code number} has unrecognized type
32      */
33     N negateNumber(YangNumberExpr<?, ?> number);
34
35     /**
36      * Attempt to evaluate an  operator and its left- and right-handside.
37      *
38      * @param operator Operator to apply
39      * @param left Left hand-side
40      * @param right Right hand-side
41      * @return Evaluation result, if evaluation succeeded
42      * @throws NullPointerException if any of the arguments is null
43      */
44     Optional<YangExpr> tryEvaluate(YangBinaryOperator operator, YangNumberExpr<?, ?> left, YangNumberExpr<?, ?> right);
45 }