private Set<Class<?>> getInputs(List<ResolvedFunction> nextFuncs) { Set<Class<?>> inputs = new HashSet<>(); for (ResolvedFunction nextFunc : nextFuncs) { inputs.add(nextFunc.getArgType()); } return inputs; }
private Set<Class<?>> getInputs(List<ResolvedFunction> nextFuncs) { Set<Class<?>> inputs = new HashSet<>(); for (ResolvedFunction nextFunc : nextFuncs) { inputs.add(nextFunc.getArgType()); } return inputs; }
sb.append(libraryName).append("::"); sb.append(getArgType().getSimpleName()).append("->"); sb.append(getMethod().getDeclaringClass().getName());
/** * If there are direct type matches between the inner func and the outer func, then remove all * other outer funcs except the ones with direct matches. * * @param prevFuncs The list of candidate inner functions * @param nextFuncs The list of candidate outer functions * @return count of items removed */ private int reduceByDirectTypes(List<ResolvedFunction> prevFuncs, List<ResolvedFunction> nextFuncs) { int progressed = 0; // Rule 1: If there are direct type matches, remove extraneous next funcs Set<Class<?>> outputs = getOutputs(prevFuncs); Set<Class<?>> inputs = getInputs(nextFuncs); Set<Class<?>> directMatches = inputs.stream().filter(outputs::contains).collect(Collectors.toCollection(HashSet::new)); if (directMatches.size() > 0) { List<ResolvedFunction> toremove = new ArrayList<>(); for (ResolvedFunction nextFunc : nextFuncs) { if (!directMatches.contains(nextFunc.getArgType())) { String logmsg = "BY-DIRECT-TYPE removing next func: " + nextFunc + " because its input types are not satisfied by any previous func"; logger.trace(logmsg); toremove.add(nextFunc); progressed++; } } nextFuncs.removeAll(toremove); } return progressed; }
/** * If there are direct type matches between the inner func and the outer func, then remove all * other outer funcs except the ones with direct matches. * * @param prevFuncs The list of candidate inner functions * @param nextFuncs The list of candidate outer functions * @return count of items removed */ private int reduceByDirectTypes(List<ResolvedFunction> prevFuncs, List<ResolvedFunction> nextFuncs) { int progressed = 0; // Rule 1: If there are direct type matches, remove extraneous next funcs Set<Class<?>> outputs = getOutputs(prevFuncs); Set<Class<?>> inputs = getInputs(nextFuncs); Sets.SetView<Class<?>> directMatches = Sets.intersection(inputs, outputs); if (directMatches.size() > 0) { List<ResolvedFunction> toremove = new ArrayList<>(); for (ResolvedFunction nextFunc : nextFuncs) { if (!directMatches.contains(nextFunc.getArgType())) { logger.debug("removing next func: " + nextFunc + " because its input types are not satisfied by an previous func"); toremove.add(nextFunc); progressed++; } } nextFuncs.removeAll(toremove); } return progressed; }
@Override public int compare(ResolvedFunction o1, ResolvedFunction o2) { ValueType iv1 = ValueType.valueOfAssignableClass(o1.getArgType()); ValueType iv2 = ValueType.valueOfAssignableClass(o2.getArgType()); int inputComparison = iv1.compareTo(iv2); if (inputComparison != 0) { return inputComparison; } iv1 = ValueType.valueOfAssignableClass(o1.getResultClass()); iv2 = ValueType.valueOfAssignableClass(o2.getResultClass()); return iv1.compareTo(iv2); } }