Use Method.getParameterCount() 73/77873/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Nov 2018 06:38:51 +0000 (07:38 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Nov 2018 07:26:01 +0000 (08:26 +0100)
Java 8 introduced this method, which bypasses array cloning done
by getParameterTypes(), making it more efficient. Take advantage
of it.

JIRA: MDSAL-398
Change-Id: Id5d4972ba20d63a8ff79e4adbdf6d2adbfce0b87
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapter.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingCodecContext.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyDataObject.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/CascadeUsesCompilationTest.java
binding/mdsal-binding-spec-util/src/main/java/org/opendaylight/mdsal/binding/spec/reflect/BindingReflections.java

index ef1379d13205bb8626c9e3afb30fcb5b92467f54..f7a69b59560f7f7308a0311c8782c5ebf713e7de 100644 (file)
@@ -76,7 +76,7 @@ class RpcServiceAdapter implements InvocationHandler {
 
         final RpcInvocationStrategy rpc = rpcNames.get(method);
         if (rpc != null) {
-            if (method.getParameterTypes().length == 0) {
+            if (method.getParameterCount() == 0) {
                 return rpc.invokeEmpty();
             }
             if (args.length != 1) {
@@ -87,17 +87,17 @@ class RpcServiceAdapter implements InvocationHandler {
 
         switch (method.getName()) {
             case "toString":
-                if (method.getReturnType().equals(String.class) && method.getParameterTypes().length == 0) {
+                if (method.getReturnType().equals(String.class) && method.getParameterCount() == 0) {
                     return type.getName() + "$Adapter{delegate=" + delegate.toString() + "}";
                 }
                 break;
             case "hashCode":
-                if (method.getReturnType().equals(int.class) && method.getParameterTypes().length == 0) {
+                if (method.getReturnType().equals(int.class) && method.getParameterCount() == 0) {
                     return System.identityHashCode(proxy);
                 }
                 break;
             case "equals":
-                if (method.getReturnType().equals(boolean.class) && method.getParameterTypes().length == 1
+                if (method.getReturnType().equals(boolean.class) && method.getParameterCount() == 1
                         && method.getParameterTypes()[0] == Object.class) {
                     return proxy == args[0];
                 }
index f4d589696eb4a5b668e3bca1faa87786915dbdb0..fe0824110d12d0abb1a190b99fe743f60fc01981 100644 (file)
@@ -243,7 +243,7 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
             final Map<String, DataSchemaNode> getterToLeafSchema) {
         final Map<String, LeafNodeCodecContext<?>> leaves = new HashMap<>();
         for (final Method method : parentClass.getMethods()) {
-            if (method.getParameterTypes().length == 0) {
+            if (method.getParameterCount() == 0) {
                 final DataSchemaNode schema = getterToLeafSchema.get(method.getName());
                 final Class<?> valueType;
                 if (schema instanceof LeafSchemaNode) {
index 4437c00772f869d08073286433b1dc17961c6072..bc9d1863e0040c956b8f60bc7705376b17f2d014 100644 (file)
@@ -63,7 +63,7 @@ class LazyDataObject<D extends DataObject> implements InvocationHandler, Augment
 
     @Override
     public Object invoke(final Object proxy, final Method method, final Object[] args) {
-        if (method.getParameterTypes().length == 0) {
+        if (method.getParameterCount() == 0) {
             final String name = method.getName();
             if (DATA_CONTAINER_GET_IMPLEMENTED_INTERFACE_NAME.equals(name)) {
                 return context.getBindingClass();
index 1d2c06e9e730f4fe7f4686b4b0a685292596ab9e..461a9073d6e0a7a895256aa389452f3e0ff0f128 100644 (file)
@@ -120,7 +120,7 @@ public class CascadeUsesCompilationTest extends BaseCompilationTest {
             }
         }
         assertNotNull(fieldsFromMethod);
-        assertEquals(1, fieldsFromMethod.getParameterTypes().length);
+        assertEquals(1, fieldsFromMethod.getParameterCount());
 
         cleanUp(sourcesOutputDir, compiledOutputDir);
     }
index 17938db379531b945597805fd294c2fd67b68560..0da11d9945ee1a20c8528f765321f964848193ca 100644 (file)
@@ -137,7 +137,7 @@ public final class BindingReflections {
                 // resolveRpcInputClass() check.While RpcMethodInvoker counts with one argument for
                 // non input type and two arguments for input type, resolveRpcInputClass() counting
                 // with zero for non input and one for input type
-                && possibleMethod.getParameterTypes().length <= 2;
+                && possibleMethod.getParameterCount() <= 2;
     }
 
     /**
@@ -284,7 +284,7 @@ public final class BindingReflections {
      */
     public static boolean isNotificationCallback(final Method method) {
         checkArgument(method != null);
-        if (method.getName().startsWith("on") && method.getParameterTypes().length == 1) {
+        if (method.getName().startsWith("on") && method.getParameterCount() == 1) {
             Class<?> potentialNotification = method.getParameterTypes()[0];
             if (isNotification(potentialNotification)
                     && method.getName().equals("on" + potentialNotification.getSimpleName())) {
@@ -422,7 +422,7 @@ public final class BindingReflections {
     private static Optional<Class<? extends DataContainer>> getYangModeledReturnType(final Method method,
             final String prefix) {
         final String methodName = method.getName();
-        if ("getClass".equals(methodName) || !methodName.startsWith(prefix) || method.getParameterTypes().length > 0) {
+        if ("getClass".equals(methodName) || !methodName.startsWith(prefix) || method.getParameterCount() > 0) {
             return Optional.empty();
         }