Cleanup unchecked casts in InstanceIdentifier 08/72208/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 23 May 2018 20:05:16 +0000 (22:05 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 23 May 2018 20:05:16 +0000 (22:05 +0200)
Using AbstractPathArgument allows us to retain the required type
capture, allowing us to eliminate a couple of SuppressWarnings.

Change-Id: I73748c7f4a3348a6a1d2961e9377a8740d427e32
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/InstanceIdentifier.java

index 058ec5d7db6fc5c3720b4841e34a8025aecf221b..3c62f6e6f4deda596b0a26cfabbf8b53c003cb8e 100644 (file)
@@ -336,29 +336,23 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
         return true;
     }
 
-    private InstanceIdentifier<?> childIdentifier(final PathArgument arg) {
+    private <N extends DataObject> InstanceIdentifier<N> childIdentifier(final AbstractPathArgument<N> arg) {
         return trustedCreate(arg, Iterables.concat(pathArguments, Collections.singleton(arg)),
             HashCodeBuilder.nextHashCode(hash, arg), isWildcarded());
     }
 
-    @SuppressWarnings("unchecked")
     public final <N extends ChildOf<? super T>> InstanceIdentifier<N> child(final Class<N> container) {
-        final PathArgument arg = new Item<>(container);
-        return (InstanceIdentifier<N>) childIdentifier(arg);
+        return childIdentifier(new Item<>(container));
     }
 
-    @SuppressWarnings("unchecked")
     public final <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> KeyedInstanceIdentifier<N, K>
             child(final Class<N> listItem, final K listKey) {
-        final PathArgument arg = new IdentifiableItem<>(listItem, listKey);
-        return (KeyedInstanceIdentifier<N, K>) childIdentifier(arg);
+        return (KeyedInstanceIdentifier<N, K>) childIdentifier(new IdentifiableItem<>(listItem, listKey));
     }
 
-    @SuppressWarnings("unchecked")
     public final <N extends DataObject & Augmentation<? super T>> InstanceIdentifier<N> augmentation(
             final Class<N> container) {
-        final PathArgument arg = new Item<>(container);
-        return (InstanceIdentifier<N>) childIdentifier(arg);
+        return childIdentifier(new Item<>(container));
     }
 
     @Deprecated
@@ -517,8 +511,8 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
     }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
-    static InstanceIdentifier<?> trustedCreate(final PathArgument arg, final Iterable<PathArgument> pathArguments,
-            final int hash, boolean wildcarded) {
+    static <N extends DataObject> InstanceIdentifier<N> trustedCreate(final PathArgument arg,
+            final Iterable<PathArgument> pathArguments, final int hash, boolean wildcarded) {
         if (Identifiable.class.isAssignableFrom(arg.getType()) && !wildcarded) {
             Identifier<?> key = null;
             if (arg instanceof IdentifiableItem<?, ?>) {