fix Java generics warning in INeutronRequest
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / INeutronRequest.java
1 /*
2  * Copyright (c) 2014, 2015 Red Hat, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.neutron.northbound.api;
10
11 import java.lang.reflect.Field;
12 import java.util.List;
13 import org.opendaylight.neutron.spi.INeutronObject;
14
15 public interface INeutronRequest<T extends INeutronObject<T>> {
16     default T getSingleton() {
17         // return this.sinleton
18         Class<?> cls = getClass();
19         try {
20             Field field = cls.getDeclaredField("singleton");
21             @SuppressWarnings("unchecked")
22             T value = (T) field.get(this);
23             return value;
24         } catch (IllegalAccessException | NoSuchFieldException e) {
25             throw new IllegalArgumentException(e);
26         }
27     }
28
29     default boolean isSingleton() {
30         // return this.sinleton != null
31         Class<?> cls = getClass();
32         try {
33             Field field = cls.getDeclaredField("singleton");
34             return field.get(this) != null;
35         } catch (IllegalAccessException | NoSuchFieldException e) {
36             throw new IllegalArgumentException(e);
37         }
38     }
39
40     default List<T> getBulk() {
41         // return this.bulkRequest
42         Class<?> cls = getClass();
43         try {
44             Field field = cls.getDeclaredField("bulkRequest");
45             @SuppressWarnings("unchecked")
46             List<T> value = (List<T>) field.get(this);
47             return value;
48         } catch (IllegalAccessException | NoSuchFieldException e) {
49             throw new IllegalArgumentException(e);
50         }
51     }
52 }