Expand CompatUtils to handle leaf-lists 23/74623/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Jul 2018 05:21:55 +0000 (07:21 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Jul 2018 05:34:25 +0000 (07:34 +0200)
The rules outlined in compatLeafType are applicable to leaf-lists,
too. Allow leaf-list types to be queried by adding a TypedDataSchemaNode
variant as compatType().

Change-Id: Ia6a3e4cf198069137c470008fde934de64b96996
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/CompatUtils.java

index bdf41b76cdcac72a1d0290a798613f643e643e57..552fc93b383c8df5bd45b003e459f3a560b5f93c 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Optional;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
@@ -118,7 +119,7 @@ public final class CompatUtils {
      * @param leaf Leaf for which we are acquiring the type
      * @return Potentially base type of the leaf type.
      */
-    @Nonnull public static TypeDefinition<?> compatLeafType(@Nonnull final LeafSchemaNode leaf) {
+    @Nonnull public static TypeDefinition<?> compatType(@Nonnull final TypedDataSchemaNode leaf) {
         final TypeDefinition<?> leafType = leaf.getType();
         Preconditions.checkNotNull(leafType);
 
@@ -168,6 +169,11 @@ public final class CompatUtils {
         }
     }
 
+    // FIXME: 3.0.0: remove this method
+    @Nonnull public static TypeDefinition<?> compatLeafType(@Nonnull final LeafSchemaNode leaf) {
+        return compatType(leaf);
+    }
+
     private static BinaryTypeDefinition baseTypeIfNotConstrained(final BinaryTypeDefinition type) {
         return baseTypeIfNotConstrained(type, type.getBaseType());
     }