X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Futil%2FInterfacesHelper.java;h=8538e3f84d62daf7e216352808743c1bfe2c78f9;hb=refs%2Fchanges%2F73%2F46573%2F5;hp=510fdf9373f46a7dc0c5f1aa61aabd15d31fbb25;hpb=cb9d74fc36ddcbca1b7fb62941396db1eb3c42c1;p=controller.git diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java index 510fdf9373..8538e3f84d 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java @@ -7,19 +7,22 @@ */ package org.opendaylight.controller.config.manager.impl.util; -import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface; -import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation; -import org.opendaylight.controller.config.spi.Module; -import org.opendaylight.controller.config.spi.ModuleFactory; - -import javax.management.JMX; +import com.google.common.collect.ImmutableSet; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import javax.management.JMX; +import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface; +import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation; +import org.opendaylight.controller.config.spi.Module; +import org.opendaylight.controller.config.spi.ModuleFactory; + +public final class InterfacesHelper { -public class InterfacesHelper { + private InterfacesHelper() { + } public static Set> getAllInterfaces(Class clazz) { if (clazz.isInterface()) { @@ -28,7 +31,7 @@ public class InterfacesHelper { } // getInterfaces gets interfaces implemented directly by this class Set> toBeInspected = new HashSet<>(); - while (clazz.equals(Object.class) == false) { + while (!clazz.equals(Object.class)) { toBeInspected.addAll(Arrays.asList(clazz.getInterfaces())); // get parent class clazz = clazz.getSuperclass(); @@ -37,18 +40,18 @@ public class InterfacesHelper { } - private static Set> getAllSuperInterfaces(Set> ifcs) { - ifcs = new HashSet<>(ifcs); // create copy to modify + private static Set> getAllSuperInterfaces(final Set> ifcs) { + Set> interfaces = new HashSet<>(ifcs); // create copy to modify // each interface can extend other interfaces Set> result = new HashSet<>(); - while (ifcs.size() > 0) { - Iterator> iterator = ifcs.iterator(); + while (!interfaces.isEmpty()) { + Iterator> iterator = interfaces.iterator(); Class ifc = iterator.next(); iterator.remove(); - if (ifc.isInterface() == false) { + if (!ifc.isInterface()) { throw new IllegalArgumentException(ifc + " should be an interface"); } - ifcs.addAll(Arrays.asList(ifc.getInterfaces())); + interfaces.addAll(Arrays.asList(ifc.getInterfaces())); result.add(ifc); } return result; @@ -58,7 +61,7 @@ public class InterfacesHelper { * Get interfaces that this class is derived from that are JMX interfaces. */ public static Set> getMXInterfaces( - Class configBeanClass) { + final Class configBeanClass) { Set> allInterfaces = getAllInterfaces(configBeanClass); Set> result = new HashSet<>(); for (Class clazz : allInterfaces) { @@ -75,7 +78,7 @@ public class InterfacesHelper { * annotation. */ public static Set> getServiceInterfaces( - Class configBeanClass) { + final Class configBeanClass) { Set> allInterfaces = getAllInterfaces(configBeanClass); Set> result = new HashSet<>(); for (Class clazz : allInterfaces) { @@ -90,11 +93,11 @@ public class InterfacesHelper { return result; } - public static Set> getAllAbstractServiceClasses(Class configBeanClass) { + public static Set> getAllAbstractServiceClasses(final Class configBeanClass) { Set> foundGeneratedSIClasses = new HashSet<>(); for (Class clazz : getAllInterfaces(configBeanClass)) { - if (AbstractServiceInterface.class.isAssignableFrom(clazz) && AbstractServiceInterface.class.equals(clazz) == false) { + if (AbstractServiceInterface.class.isAssignableFrom(clazz) && !AbstractServiceInterface.class.equals(clazz)) { foundGeneratedSIClasses.add((Class) clazz); } } @@ -108,7 +111,7 @@ public class InterfacesHelper { * {@link org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation#osgiRegistrationType()} */ public static Set> getOsgiRegistrationTypes( - Class configBeanClass) { + final Class configBeanClass) { Set> serviceInterfaces = getServiceInterfaces(configBeanClass); Set> result = new HashSet<>(); for (Class clazz : serviceInterfaces) { @@ -119,20 +122,20 @@ public class InterfacesHelper { return result; } - public static Set getQNames(Set siAnnotations) { + public static Set getQNames(final Set siAnnotations) { Set qNames = new HashSet<>(); for (ServiceInterfaceAnnotation sia: siAnnotations) { qNames.add(sia.value()); } - return Collections.unmodifiableSet(qNames); + return ImmutableSet.copyOf(qNames); } - public static Set getServiceInterfaceAnnotations(ModuleFactory factory) { + public static Set getServiceInterfaceAnnotations(final ModuleFactory factory) { Set> implementedServiceIntefaces = Collections.unmodifiableSet(factory.getImplementedServiceIntefaces()); return getServiceInterfaceAnnotations(implementedServiceIntefaces); } - private static Set getServiceInterfaceAnnotations(Set> implementedServiceIntefaces) { + private static Set getServiceInterfaceAnnotations(final Set> implementedServiceIntefaces) { Set> inspected = getAllAbstractServiceInterfaceClasses(implementedServiceIntefaces); Set result = new HashSet<>(); // SIs can form hierarchies, inspect superclass until it does not extend AbstractSI @@ -146,13 +149,13 @@ public class InterfacesHelper { } static Set> getAllAbstractServiceInterfaceClasses( - Set> directlyImplementedAbstractSIs) { + final Set> directlyImplementedAbstractSIs) { - Set> allInterfaces = getAllSuperInterfaces((Set) directlyImplementedAbstractSIs); + Set> allInterfaces = getAllSuperInterfaces(directlyImplementedAbstractSIs); Set> result = new HashSet<>(); for(Class ifc: allInterfaces){ if (AbstractServiceInterface.class.isAssignableFrom(ifc) && - ifc.equals(AbstractServiceInterface.class) == false) { + !ifc.equals(AbstractServiceInterface.class)) { result.add((Class) ifc); }