Add yang-xpath-api
[yangtools.git] / yang / yang-xpath-api / src / main / java / org / opendaylight / yangtools / yang / xpath / api / YangBinaryOperator.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  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 static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13
14 /**
15  * YANG XPath binary operator.
16  *
17  * @author Robert Varga
18  */
19 @Beta
20 public enum YangBinaryOperator {
21     /**
22      * Operands are equal.
23      *
24      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-EqualityExpr">EqualityExpr</a>
25      */
26     EQUALS("="),
27     /**
28      * Operands do not equal.
29      *
30      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-EqualityExpr">EqualityExpr</a>
31      */
32     NOT_EQUALS("!="),
33
34     /**
35      * Left-hand operand is greater than right-hand operand.
36      *
37      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-RelationalExpr">RelationalExpr</a>
38      */
39     GT(">"),
40     /**
41      * Left-hand operand is greater than or equal to right-hand operand.
42      *
43      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-RelationalExpr">RelationalExpr</a>
44      */
45     GTE(">="),
46     /**
47      * Left-hand operand is less than right-hand operand.
48      *
49      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-RelationalExpr">RelationalExpr</a>
50      */
51     LT("<"),
52     /**
53       * Left-hand operand is less than or equal to right-hand operand.
54      *
55      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-RelationalExpr">RelationalExpr</a>
56      */
57     LTE("<="),
58
59     /**
60      * Arithmetic addition.
61      *
62      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-AdditiveExpr">AdditiveExpr</a>
63      */
64     PLUS("+"),
65     /**
66      * Arithmetic subtraction.
67      *
68      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-AdditiveExpr">AdditiveExpr</a>
69      */
70     MINUS("-"),
71
72     /**
73      * Arithmetic multiplication.
74      *
75      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-MultiplicativeExpr">MultiplicativeExpr</a>
76      */
77     MUL("*"),
78     /**
79      * Arithmetic division.
80      *
81      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-MultiplicativeExpr">MultiplicativeExpr</a>
82      */
83     DIV("div"),
84     /**
85      * Arithmetic modulus after truncating division.
86      *
87      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-MultiplicativeExpr">MultiplicativeExpr</a>
88      */
89     MOD("mod");
90
91     private final class Expr extends YangBinaryExpr {
92         private static final long serialVersionUID = 1L;
93
94         Expr(final YangExpr leftExpr, final YangExpr rightExpr) {
95             super(leftExpr, rightExpr);
96         }
97
98         @Override
99         public YangBinaryOperator getOperator() {
100             return YangBinaryOperator.this;
101         }
102     }
103
104     private final String str;
105
106     YangBinaryOperator(final String str) {
107         this.str = requireNonNull(str);
108     }
109
110     @Override
111     public String toString() {
112         return str;
113     }
114
115     public YangBinaryExpr exprWith(final YangExpr leftExpr, final YangExpr rightExpr) {
116         return new Expr(leftExpr, rightExpr);
117     }
118 }