Add MatchBuilderPath.BooleanLeafReference 44/94744/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 22 Jan 2021 21:12:12 +0000 (22:12 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 23 Jan 2021 07:25:14 +0000 (08:25 +0100)
This is a notable omission from the interface, allow users to
target Boolean types.

JIRA: MDSAL-652
Change-Id: Ie62f6419bf3db57887797f7bc88f7ec5dfd5f203
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/query/MatchBuilderPath.java
binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/query/QueryBuilderExamples.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/query/DefaultMatchBuilderPath.java

index abace24cea3d0f722756933e7a0cd453c383ebd4..11943c867ec850eafcc4bdfa75725cdc109adab7 100644 (file)
@@ -62,6 +62,15 @@ public interface MatchBuilderPath<O extends DataObject, T extends DataObject> ex
     <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>>
         @NonNull MatchBuilderPath<O, N> extractChild(Class<@NonNull N> listItem, K listKey);
 
+    /**
+     * Match an {@code boolean} leaf's value.
+     *
+     * @param methodRef method reference to the getter method
+     * @return A {@link ValueMatchBuilder}
+     * @throws NullPointerException if methodRef is null
+     */
+    @NonNull ValueMatchBuilder<O, Boolean> leaf(BooleanLeafReference<T> methodRef);
+
     /**
      * Match an {@code empty} leaf's value.
      *
@@ -198,6 +207,11 @@ public interface MatchBuilderPath<O extends DataObject, T extends DataObject> ex
         C dummyMethod(P parent);
     }
 
+    @FunctionalInterface
+    public interface BooleanLeafReference<P> extends LeafReference<P, Boolean> {
+
+    }
+
     @FunctionalInterface
     public interface EmptyLeafReference<P> extends LeafReference<P, Empty> {
 
index bded32f5f1312054bfe18932ad8d698a3efd7673..00792ac40f4e9dab1c2005e8ec99d07aa5f6121b 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.System;
 import org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.SystemKey;
 import org.opendaylight.yang.gen.v1.mdsal.query.norev.second.grp.Alarms;
 import org.opendaylight.yang.gen.v1.mdsal.query.norev.third.grp.AffectedUsers;
+import org.opendaylight.yang.gen.v1.mdsal426.norev.BooleanCont;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.Uint64;
 
@@ -132,4 +133,13 @@ public class QueryBuilderExamples {
                     .greaterThan(Uint64.TEN)
                 .build();
     }
+
+    public QueryExpression<BooleanCont> selectBoolean() {
+        return factory
+                .querySubtree(InstanceIdentifier.create(BooleanCont.class))
+                .matching()
+                    .leaf(BooleanCont::getIsFoo)
+                    .valueEquals(true)
+                .build();
+    }
 }
index 226e1df337982de15afd2a95bf4b5e93bb534deb..cadd5b32d09e1e04bd85435817166d9bdc3cd603 100644 (file)
@@ -64,6 +64,11 @@ final class DefaultMatchBuilderPath<O extends DataObject, T extends DataObject>
         return (MatchBuilderPath<O, N>) this;
     }
 
+    @Override
+    public ValueMatchBuilder<O, Boolean> leaf(final BooleanLeafReference<T> methodRef) {
+        return defaultFor(methodRef);
+    }
+
     @Override
     public ValueMatchBuilder<O, Empty> leaf(final EmptyLeafReference<T> methodRef) {
         return defaultFor(methodRef);