in src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java [668:719]
private <T extends Executable> T getMostSpecific(final T[] methods) {
final Class<?>[] args = getParameters();
final Deque<T> applicables = getApplicables(methods, args);
if (applicables.isEmpty()) {
return null;
}
if (applicables.size() == 1) {
return applicables.getFirst();
}
/*
* This list will contain the maximally specific methods. Hopefully at
* the end of the below loop, the list will contain exactly one method,
* (the most specific method) otherwise we have ambiguity.
*/
final Deque<T> maximals = new LinkedList<>();
for (final T app : applicables) {
final Class<?>[] parms = app.getParameterTypes();
boolean lessSpecific = false;
final Iterator<T> maximal = maximals.iterator();
while (!lessSpecific && maximal.hasNext()) {
final T max = maximal.next();
switch (moreSpecific(args, parms, max.getParameterTypes())) {
case MORE_SPECIFIC:
/*
* This method is more specific than the previously
* known maximally specific, so remove the old maximum.
*/
maximal.remove();
break;
case LESS_SPECIFIC:
/*
* This method is less specific than any of the
* currently known maximally specific methods, so we
* won't add it into the set of maximally specific
* methods
*/
lessSpecific = true;
break;
default:
// nothing to do
}
}
if (!lessSpecific) {
maximals.addLast(app);
}
}
// if we have more than one maximally specific method, this call is ambiguous...
if (maximals.size() > 1) {
throw ambiguousException(args, applicables);
}
return maximals.getFirst();
} // CSON: RedundantThrows