Skip to content

Commit be3e552

Browse files
committed
Javadoc
- Use ternary expression - Reduce vertical space
1 parent 7790d95 commit be3e552

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

src/main/java/org/apache/commons/beanutils2/MethodUtils.java

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
* method can be invoked as normal. This call will only succeed when the application has sufficient security privileges. If this call fails then a warning will
4949
* be logged and the method may fail.
5050
* </p>
51+
*
52+
* @see <a href="https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/reflect/MethodUtils.html">Apache Commons Lang MethodUtils</a>
5153
*/
5254
public final class MethodUtils {
5355

@@ -89,7 +91,6 @@ public boolean equals(final Object obj) {
8991
return false;
9092
}
9193
final MethodKey md = (MethodKey) obj;
92-
9394
return exact == md.exact && methodName.equals(md.methodName) && cls.equals(md.cls) && Arrays.equals(paramTypes, md.paramTypes);
9495
}
9596

@@ -157,7 +158,7 @@ public static synchronized int clearCache() {
157158
}
158159

159160
/**
160-
* Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found,
161+
* Gets an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found,
161162
* return {@code null}.
162163
*
163164
* @param clazz The class of the object.
@@ -209,7 +210,7 @@ public static Method getAccessibleMethod(Class<?> clazz, Method method) {
209210
}
210211

211212
/**
212-
* Return an accessible method (that is, one that can be invoked via reflection) with given name and parameters. If no such method can be found, return
213+
* Gets an accessible method (that is, one that can be invoked via reflection) with given name and parameters. If no such method can be found, return
213214
* {@code null}. This is just a convenient wrapper for {@link #getAccessibleMethod(Method method)}.
214215
*
215216
* @param clazz get method from this class.
@@ -225,7 +226,6 @@ public static Method getAccessibleMethod(final Class<?> clazz, final String meth
225226
if (method != null) {
226227
return method;
227228
}
228-
229229
method = getAccessibleMethod(clazz, clazz.getMethod(methodName, parameterTypes));
230230
cacheMethod(key, method);
231231
return method;
@@ -235,23 +235,18 @@ public static Method getAccessibleMethod(final Class<?> clazz, final String meth
235235
}
236236

237237
/**
238-
* Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found,
238+
* Gets an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found,
239239
* return {@code null}.
240240
*
241241
* @param method The method that we wish to call.
242242
* @return The accessible method.
243243
*/
244244
public static Method getAccessibleMethod(final Method method) {
245-
// Make sure we have a method to check
246-
if (method == null) {
247-
return null;
248-
}
249-
250-
return getAccessibleMethod(method.getDeclaringClass(), method);
245+
return method != null ? getAccessibleMethod(method.getDeclaringClass(), method) : null;
251246
}
252247

253248
/**
254-
* Return an accessible method (that is, one that can be invoked via reflection) that implements the specified method, by scanning through all implemented
249+
* Gets an accessible method (that is, one that can be invoked via reflection) that implements the specified method, by scanning through all implemented
255250
* interfaces and subinterfaces. If no such method can be found, return {@code null}.
256251
*
257252
* <p>
@@ -265,19 +260,15 @@ public static Method getAccessibleMethod(final Method method) {
265260
*/
266261
private static Method getAccessibleMethodFromInterfaceNest(Class<?> clazz, final String methodName, final Class<?>[] parameterTypes) {
267262
Method method = null;
268-
269263
// Search up the superclass chain
270264
for (; clazz != null; clazz = clazz.getSuperclass()) {
271-
272265
// Check the implemented interfaces of the parent class
273266
final Class<?>[] interfaces = clazz.getInterfaces();
274267
for (final Class<?> anInterface : interfaces) {
275-
276268
// Is this interface public?
277269
if (!Modifier.isPublic(anInterface.getModifiers())) {
278270
continue;
279271
}
280-
281272
// Does the method exist on this interface?
282273
try {
283274
method = anInterface.getDeclaredMethod(methodName, parameterTypes);
@@ -289,23 +280,19 @@ private static Method getAccessibleMethodFromInterfaceNest(Class<?> clazz, final
289280
if (method != null) {
290281
return method;
291282
}
292-
293283
// Recursively check our parent interfaces
294284
method = getAccessibleMethodFromInterfaceNest(anInterface, methodName, parameterTypes);
295285
if (method != null) {
296286
return method;
297287
}
298-
299288
}
300-
301289
}
302-
303290
// We did not find anything
304291
return null;
305292
}
306293

307294
/**
308-
* Return an accessible method (that is, one that can be invoked via reflection) by scanning through the superclasses. If no such method can be found,
295+
* Gets an accessible method (that is, one that can be invoked via reflection) by scanning through the superclasses. If no such method can be found,
309296
* return {@code null}.
310297
*
311298
* @param clazz Class to be checked.
@@ -344,7 +331,7 @@ private static Method getCachedMethod(final MethodKey key) {
344331
}
345332

346333
/**
347-
* Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean that every method parameter is assignable
334+
* Gets an accessible method that matches the given name and has compatible parameters. Compatible parameters mean that every method parameter is assignable
348335
* from the given parameters. In other words, it finds a method with the given name that will take the parameters given.
349336
*
350337
* <p>
@@ -366,7 +353,6 @@ public static Method getMatchingAccessibleMethod(final Class<?> clazz, final Str
366353
LOG.trace("Matching name=" + methodName + " on " + clazz);
367354
}
368355
final MethodKey key = new MethodKey(clazz, methodName, parameterTypes, false);
369-
370356
// see if we can find the method directly
371357
// most of the time this works and it's much faster
372358
try {
@@ -375,21 +361,16 @@ public static Method getMatchingAccessibleMethod(final Class<?> clazz, final Str
375361
if (method != null) {
376362
return method;
377363
}
378-
379364
method = clazz.getMethod(methodName, parameterTypes);
380365
if (LOG.isTraceEnabled()) {
381366
LOG.trace("Found straight match: " + method);
382367
LOG.trace("isPublic:" + Modifier.isPublic(method.getModifiers()));
383368
}
384-
385369
setMethodAccessible(method); // Default access superclass workaround
386-
387370
cacheMethod(key, method);
388371
return method;
389-
390372
} catch (final NoSuchMethodException e) {
391373
/* SWALLOW */ }
392-
393374
// search through all methods
394375
final int paramSize = parameterTypes.length;
395376
Method bestMatch = null;
@@ -403,7 +384,6 @@ public static Method getMatchingAccessibleMethod(final Class<?> clazz, final Str
403384
LOG.trace("Found matching name:");
404385
LOG.trace(method2);
405386
}
406-
407387
// compare parameters
408388
final Class<?>[] methodsParams = method2.getParameterTypes();
409389
final int methodParamSize = methodsParams.length;
@@ -422,7 +402,6 @@ public static Method getMatchingAccessibleMethod(final Class<?> clazz, final Str
422402
break;
423403
}
424404
}
425-
426405
if (match) {
427406
// get accessible version of method
428407
final Method method = getAccessibleMethod(clazz, method2);
@@ -437,7 +416,6 @@ public static Method getMatchingAccessibleMethod(final Class<?> clazz, final Str
437416
bestMatchCost = myCost;
438417
}
439418
}
440-
441419
LOG.trace("Couldn't find accessible method.");
442420
}
443421
}
@@ -449,7 +427,6 @@ public static Method getMatchingAccessibleMethod(final Class<?> clazz, final Str
449427
// didn't find a match
450428
LOG.trace("No match found.");
451429
}
452-
453430
return bestMatch;
454431
}
455432

@@ -495,7 +472,7 @@ private static float getObjectTransformationCost(Class<?> srcClass, final Class<
495472
}
496473

497474
/**
498-
* Returns the sum of the object transformation cost for each class in the source argument list.
475+
* Gets the sum of the object transformation cost for each class in the source argument list.
499476
*
500477
* @param srcArgs The source arguments.
501478
* @param destArgs The destination arguments.
@@ -509,7 +486,6 @@ private static float getTotalTransformationCost(final Class<?>[] srcArgs, final
509486
destClass = destArgs[i];
510487
totalCost += getObjectTransformationCost(srcClass, destClass);
511488
}
512-
513489
return totalCost;
514490
}
515491

0 commit comments

Comments
 (0)