Enable findbugs in more artifacts
[yangtools.git] / yang / yang-xpath-api / src / main / java / org / opendaylight / yangtools / yang / xpath / api / YangNaryOperator.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 com.google.common.collect.ImmutableSet;
14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15 import java.util.Collection;
16 import java.util.Set;
17
18 /**
19  * YANG XPath binary operator.
20  *
21  * @author Robert Varga
22  */
23 @Beta
24 public enum YangNaryOperator {
25     /**
26      * Logical 'and' operator on operands.
27      *
28      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-AndExpr">AndExpr</a>
29      */
30     AND("and"),
31     /**
32      * Logical 'or' operator on operands.
33      *
34      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-OrExpr">OrExpr</a>
35      */
36     OR("or"),
37     /**
38      * Set union operator on operands.
39      *
40      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-UnionExpr">UnionExpr</a>
41      */
42     UNION("|");
43
44     @SuppressFBWarnings(value = "SE_INNER_CLASS", justification = "Outer class is a retained enumeration")
45     private final class Expr extends YangNaryExpr {
46         private static final long serialVersionUID = 1L;
47
48         Expr(final Set<YangExpr> exprs) {
49             super(exprs);
50         }
51
52         @Override
53         public YangNaryOperator getOperator() {
54             return YangNaryOperator.this;
55         }
56     }
57
58     private final String str;
59
60     YangNaryOperator(final String str) {
61         this.str = requireNonNull(str);
62     }
63
64     @Override
65     public String toString() {
66         return str;
67     }
68
69     public YangExpr exprWith(final Collection<YangExpr> exprs) {
70         final Set<YangExpr> set = ImmutableSet.copyOf(exprs);
71         return set.size() == 1 ? set.iterator().next() : new Expr(set);
72     }
73 }