sonar: use dedicated exception instead of RuntimeException
[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 aClass = getClass();
19         try {
20             Field field = aClass.getDeclaredField("singleton");
21             return (T) field.get(this);
22         } catch (IllegalAccessException | NoSuchFieldException e) {
23             throw new IllegalArgumentException(e);
24         }
25     }
26
27     default boolean isSingleton() {
28         // return this.sinleton != null;
29         Class aClass = getClass();
30         try {
31             Field field = aClass.getDeclaredField("singleton");
32             return field.get(this) != null;
33         } catch (IllegalAccessException | NoSuchFieldException e) {
34             throw new IllegalArgumentException(e);
35         }
36     }
37
38     default List<T> getBulk() {
39         // return this.bulkRequest;
40         Class aClass = getClass();
41         try {
42             Field field = aClass.getDeclaredField("bulkRequest");
43             return (List<T>) field.get(this);
44         } catch (IllegalAccessException | NoSuchFieldException e) {
45             throw new IllegalArgumentException(e);
46         }
47     }
48 }