Populate model/ hierarchy
[yangtools.git] / xpath / 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 java.util.Collection;
15
16 /**
17  * YANG XPath binary operator.
18  *
19  * @author Robert Varga
20  */
21 @Beta
22 public enum YangNaryOperator {
23     /**
24      * Logical 'and' operator on operands.
25      *
26      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-AndExpr">AndExpr</a>
27      */
28     AND("and"),
29     /**
30      * Logical 'or' operator on operands.
31      *
32      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-OrExpr">OrExpr</a>
33      */
34     OR("or"),
35     /**
36      * Set union operator on operands.
37      *
38      * @see <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-UnionExpr">UnionExpr</a>
39      */
40     UNION("|");
41
42     private final String str;
43
44     YangNaryOperator(final String str) {
45         this.str = requireNonNull(str);
46     }
47
48     @Override
49     public String toString() {
50         return str;
51     }
52
53     public YangExpr exprWith(final Collection<YangExpr> exprs) {
54         final ImmutableSet<YangExpr> set = ImmutableSet.copyOf(exprs);
55         return set.size() == 1 ? set.iterator().next() : new YangNaryExpr(this, set);
56     }
57 }