Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / dynamicmbean / AttributeHolder.java
index 9dd6a2269e259cf4ca5ee4e6b1331d85ef015d81..ff607d32e5f340319b050020998c23ded9e7c9d6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -7,17 +7,16 @@
  */
 package org.opendaylight.controller.config.manager.impl.dynamicmbean;
 
-import org.opendaylight.controller.config.api.annotations.Description;
-import org.opendaylight.controller.config.api.annotations.RequireInterface;
-
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.Immutable;
-import javax.management.MBeanAttributeInfo;
-import javax.management.ObjectName;
 import java.lang.reflect.Method;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.Immutable;
+import javax.management.MBeanAttributeInfo;
+import javax.management.ObjectName;
+import org.opendaylight.controller.config.api.annotations.Description;
+import org.opendaylight.controller.config.api.annotations.RequireInterface;
 
 @Immutable
 class AttributeHolder {
@@ -31,7 +30,7 @@ class AttributeHolder {
     private final RequireInterface requireInterfaceAnnotation;
     private final String attributeType;
 
-    public static final Set<Class<?>> PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER = new HashSet<>();
+    protected static final Set<Class<?>> PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER = new HashSet<>();
 
     static {
         PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(ObjectName.class);
@@ -39,10 +38,8 @@ class AttributeHolder {
         PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(List.class);
     }
 
-    public AttributeHolder(String name, Object object, String returnType,
-            boolean writable,
-            @Nullable RequireInterface requireInterfaceAnnotation,
-            String description) {
+    AttributeHolder(final String name, final Object object, final String returnType, final boolean writable,
+            @Nullable final RequireInterface requireInterfaceAnnotation, final String description) {
         if (name == null) {
             throw new NullPointerException();
         }
@@ -58,12 +55,12 @@ class AttributeHolder {
     }
 
     public MBeanAttributeInfo toMBeanAttributeInfo() {
-        MBeanAttributeInfo info = new MBeanAttributeInfo(name, attributeType,
-                description, true, true, false);
-        return info;
+        return new MBeanAttributeInfo(name, attributeType, description, true, true, false);
     }
 
     /**
+     * Anotation.
+     *
      * @return annotation if setter sets ObjectName or ObjectName[], and is
      *         annotated. Return null otherwise.
      */
@@ -95,54 +92,54 @@ class AttributeHolder {
      * Find @Description annotations in method class and all its exported
      * interfaces.
      *
-     * @param setter
-     * @param jmxInterfaces
+     * @param setter setter method
+     * @param jmxInterfaces JMX interfaces
      * @return empty string if no annotation is found, or list of descriptions
      *         separated by newline
      */
-    static String findDescription(Method setter, Set<Class<?>> jmxInterfaces) {
-        List<Description> descriptions = AnnotationsHelper
-                .findMethodAnnotationInSuperClassesAndIfcs(setter, Description.class, jmxInterfaces);
+    static String findDescription(final Method setter, final Set<Class<?>> jmxInterfaces) {
+        List<Description> descriptions = AnnotationsHelper.findMethodAnnotationInSuperClassesAndIfcs(setter,
+                Description.class, jmxInterfaces);
         return AnnotationsHelper.aggregateDescriptions(descriptions);
     }
 
     /**
-     * Find @RequireInterface annotation by searching method class and all
-     * exported interfaces.
+     * Find @RequireInterface annotation by searching method class and all exported
+     * interfaces.
      *
-     * @param setter
-     * @param inspectedInterfaces
+     * @param setter setter method
+     * @param inspectedInterfaces interfaces
+     * @return null if no annotation is found, otherwise return the annotation
      * @throws IllegalStateException
      *             if more than one value is specified by found annotations
      * @throws IllegalArgumentException
      *             if set of exported interfaces contains non interface type
-     * @return null if no annotation is found, otherwise return the annotation
      */
     static RequireInterface findRequireInterfaceAnnotation(final Method setter,
-            Set<Class<?>> inspectedInterfaces) {
+            final Set<Class<?>> inspectedInterfaces) {
 
-        // only allow setX(ObjectName y) or setX(ObjectName[] y) or setX(List<ObjectName> y) to continue
+        // only allow setX(ObjectName y) or setX(ObjectName[] y) or
+        // setX(List<ObjectName> y) to continue
 
-        if (setter.getParameterTypes().length > 1)
-            return null;
-        if(PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.contains(setter.getParameterTypes()[0]) == false)
+        if (setter.getParameterTypes().length > 1
+                || !PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.contains(setter.getParameterTypes()[0])) {
             return null;
+        }
 
         List<RequireInterface> foundRequireInterfaces = AnnotationsHelper
                 .findMethodAnnotationInSuperClassesAndIfcs(setter, RequireInterface.class, inspectedInterfaces);
         // make sure the list if not empty contains always annotation with same
         // value
-        Set<Class<?>> foundValues = new HashSet<Class<?>>();
+        Set<Class<?>> foundValues = new HashSet<>();
         for (RequireInterface ri : foundRequireInterfaces) {
             foundValues.add(ri.value());
         }
-        if (foundValues.size() == 0) {
+        if (foundValues.isEmpty()) {
             return null;
         } else if (foundValues.size() > 1) {
-            throw new IllegalStateException("Error finding @RequireInterface. "
-                    + "More than one value specified as required interface "
-                    + foundValues + " of " + setter + " of "
-                    + setter.getDeclaringClass());
+            throw new IllegalStateException(
+                    "Error finding @RequireInterface. " + "More than one value specified as required interface "
+                            + foundValues + " of " + setter + " of " + setter.getDeclaringClass());
         } else {
             return foundRequireInterfaces.get(0);
         }