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);
}
}
}