NEUTRON-208: BGPVPN network and router association
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / INeutronRequest.java
index 7a376b221a7b2fea1b7026bd7c45e6e08e7219e0..f03c00bf2f53fa336ff636ef5021d21e7eb74024 100644 (file)
@@ -13,33 +13,34 @@ import java.util.List;
 import org.opendaylight.neutron.spi.INeutronObject;
 
 public interface INeutronRequest<T extends INeutronObject<T>> {
+
     default T getSingleton() {
-        Class aClass = getClass();
+        // return this.singleton
+        Class<?> cls = getClass();
         try {
-            Field field = aClass.getDeclaredField("singleton");
-            return (T) field.get(this);
+            Field field = cls.getDeclaredField("singleton");
+            @SuppressWarnings("unchecked")
+            T value = (T) field.get(this);
+            return value;
         } catch (IllegalAccessException | NoSuchFieldException e) {
-            throw new RuntimeException(e);
+            throw new IllegalArgumentException(e);
         }
     }
 
     default boolean isSingleton() {
-        Class aClass = getClass();
-        try {
-            Field field = aClass.getDeclaredField("singleton");
-            return field.get(this) != null;
-        } catch (IllegalAccessException | NoSuchFieldException e) {
-            throw new RuntimeException(e);
-        }
+        return getSingleton() != null;
     }
 
     default List<T> getBulk() {
-        Class aClass = getClass();
+        // return this.bulkRequest
+        Class<?> cls = getClass();
         try {
-            Field field = aClass.getDeclaredField("bulkRequest");
-            return (List<T>) field.get(this);
+            Field field = cls.getDeclaredField("bulkRequest");
+            @SuppressWarnings("unchecked")
+            List<T> value = (List<T>) field.get(this);
+            return value;
         } catch (IllegalAccessException | NoSuchFieldException e) {
-            throw new RuntimeException(e);
+            throw new IllegalArgumentException(e);
         }
     }
 }