Add YangXPathAxis.asStep() methods without predicates 19/81019/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Mar 2019 07:40:02 +0000 (08:40 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Mar 2019 07:48:11 +0000 (08:48 +0100)
In some contexts we know we do not not have any predicates, add
convenience functions for instantiating such steps.

Change-Id: I141053c041095add35590b6ff77440036450cb58
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-xpath-api/src/main/java/org/opendaylight/yangtools/yang/xpath/api/YangFilterExpr.java
yang/yang-xpath-api/src/main/java/org/opendaylight/yangtools/yang/xpath/api/YangXPathAxis.java

index 8b1291bc7e86c4e66ccbade03334236f85dec726..a0a8ce3f7e9a1ab8f2d13d2b66df404e66fc8c70 100644 (file)
@@ -52,8 +52,7 @@ public class YangFilterExpr implements YangExpr, YangPredicateAware {
     }
 
     public static YangFilterExpr of(final YangExpr expr, final Collection<YangExpr> predicates) {
-        return predicates.isEmpty() ? new YangFilterExpr(expr)
-                : new WithPredicates(expr, ImmutableSet.copyOf(predicates));
+        return predicates.isEmpty() ? of(expr) : new WithPredicates(expr, ImmutableSet.copyOf(predicates));
     }
 
     public final YangExpr getExpr() {
index 452102c2c056ef8cce0abe292b1883c18f2e3cdd..5d2473dee4f8dd8076d2621faa250b4189cf61d1 100644 (file)
@@ -109,20 +109,31 @@ public enum YangXPathAxis {
         return set.isEmpty() ? step : new AxisStepWithPredicates(this, set);
     }
 
+    public final QNameStep asStep(final QName qname) {
+        return new QNameStep(this, qname);
+    }
+
     public final QNameStep asStep(final QName qname, final Collection<YangExpr> predicates) {
         final ImmutableSet<YangExpr> set = ImmutableSet.copyOf(predicates);
-        return set.isEmpty() ? new QNameStep(this, qname) : new QNameStepWithPredicates(this, qname, set);
+        return set.isEmpty() ? asStep(qname) : new QNameStepWithPredicates(this, qname, set);
+    }
+
+    public final NodeTypeStep asStep(final YangXPathNodeType type) {
+        return new NodeTypeStep(this, type);
     }
 
     public final NodeTypeStep asStep(final YangXPathNodeType type, final Collection<YangExpr> predicates) {
         final ImmutableSet<YangExpr> set = ImmutableSet.copyOf(predicates);
-        return set.isEmpty() ? new NodeTypeStep(this, type) : new NodeTypeStepWithPredicates(this, type, set);
+        return set.isEmpty() ? asStep(type) : new NodeTypeStepWithPredicates(this, type, set);
+    }
+
+    public final ProcessingInstructionStep asStep(final String name) {
+        return new ProcessingInstructionStep(this, name);
     }
 
     public final ProcessingInstructionStep asStep(final String name, final Collection<YangExpr> predicates) {
         final ImmutableSet<YangExpr> set = ImmutableSet.copyOf(predicates);
-        return set.isEmpty() ? new ProcessingInstructionStep(this, name)
-                : new ProcessingInstructionStepWithPredicates(this, name, set);
+        return set.isEmpty() ? asStep(name) : new ProcessingInstructionStepWithPredicates(this, name, set);
     }
 
     @Override