X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdynamicmbean%2FAnnotationsHelper.java;h=6859e4caf3f37dd086a512651146290e8306b53a;hp=efb357466d52096db4506f9611ed6b4113c38fcb;hb=6227570f6482136b72a26675d43c8bb88279503e;hpb=ed6019236d78a69577888f60064c3714eaa80f6a diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java index efb357466d..6859e4caf3 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java @@ -7,6 +7,8 @@ */ 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; @@ -29,9 +31,9 @@ public class AnnotationsHelper { * @return list of found annotations */ static List findMethodAnnotationInSuperClassesAndIfcs( - final Method setter, Class annotationType, - Set> inspectedInterfaces) { - List result = new ArrayList(); + final Method setter, final Class annotationType, + final Set> inspectedInterfaces) { + Builder result = ImmutableSet.builder(); Class inspectedClass = setter.getDeclaringClass(); do { try { @@ -43,13 +45,15 @@ public class AnnotationsHelper { } // 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 { @@ -63,7 +67,7 @@ public class AnnotationsHelper { } } - return result; + return new ArrayList<>(result.build()); } /** @@ -74,8 +78,8 @@ public class AnnotationsHelper { * @return list of found annotations */ static List findClassAnnotationInSuperClassesAndIfcs( - Class clazz, Class annotationType, Set> interfaces) { - List result = new ArrayList(); + final Class clazz, final Class annotationType, final Set> interfaces) { + List result = new ArrayList<>(); Class declaringClass = clazz; do { T annotation = declaringClass.getAnnotation(annotationType); @@ -83,10 +87,10 @@ public class AnnotationsHelper { 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); @@ -101,7 +105,7 @@ public class AnnotationsHelper { * @return empty string if no annotation is found, or list of descriptions * separated by newline */ - static String aggregateDescriptions(List descriptions) { + static String aggregateDescriptions(final List descriptions) { StringBuilder builder = new StringBuilder(); for (Description d : descriptions) { if (builder.length() != 0) {