*/
package org.opendaylight.controller.config.manager.impl.dynamicmbean;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
* @return list of found annotations
*/
static <T extends Annotation> List<T> findMethodAnnotationInSuperClassesAndIfcs(
- final Method setter, Class<T> annotationType,
- Set<Class<?>> inspectedInterfaces) {
- List<T> result = new ArrayList<T>();
+ final Method setter, final Class<T> annotationType,
+ final Set<Class<?>> inspectedInterfaces) {
+ Builder<T> result = ImmutableSet.builder();
Class<?> inspectedClass = setter.getDeclaringClass();
do {
try {
}
// we need to go deeper
inspectedClass = inspectedClass.getSuperclass();
+ // no need to go further
} catch (NoSuchMethodException e) {
- inspectedClass = Object.class; // no need to go further
+ inspectedClass = Object.class;
}
- } while (inspectedClass.equals(Object.class) == false);
+ } while (!inspectedClass.equals(Object.class));
+
// inspect interfaces
for (Class<?> ifc : inspectedInterfaces) {
- if (ifc.isInterface() == false) {
+ if (!ifc.isInterface()) {
throw new IllegalArgumentException(ifc + " is not an interface");
}
try {
}
}
- return result;
+ return new ArrayList<>(result.build());
}
/**
* @return list of found annotations
*/
static <T extends Annotation> List<T> findClassAnnotationInSuperClassesAndIfcs(
- Class<?> clazz, Class<T> annotationType, Set<Class<?>> interfaces) {
- List<T> result = new ArrayList<T>();
+ final Class<?> clazz, final Class<T> annotationType, final Set<Class<?>> interfaces) {
+ List<T> result = new ArrayList<>();
Class<?> declaringClass = clazz;
do {
T annotation = declaringClass.getAnnotation(annotationType);
result.add(annotation);
}
declaringClass = declaringClass.getSuperclass();
- } while (declaringClass.equals(Object.class) == false);
+ } while (!declaringClass.equals(Object.class));
// inspect interfaces
for (Class<?> ifc : interfaces) {
- if (ifc.isInterface() == false) {
+ if (!ifc.isInterface()) {
throw new IllegalArgumentException(ifc + " is not an interface");
}
T annotation = ifc.getAnnotation(annotationType);
* @return empty string if no annotation is found, or list of descriptions
* separated by newline
*/
- static String aggregateDescriptions(List<Description> descriptions) {
+ static String aggregateDescriptions(final List<Description> descriptions) {
StringBuilder builder = new StringBuilder();
for (Description d : descriptions) {
if (builder.length() != 0) {