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