3.5 Reducer Aggregation Aggregate (merge results) Returns from multiple implementations at one extension point All aggregation classes need to implement the IReducer interface and customize the reduce() stop() method

/** Return the first qualified, short-circuit abort subsequent extension point execution, */ public static <R> SimpleReducer<R> firstOf(final Predicate<R> p) {return new SimpleReducer<R>() {public R  reduce(List<R> list) { R result = null; if (list ! = null && list.size() > 0) result = list.get(list.size() - 1); return result; } public boolean stop(List<R> list) { boolean result = false; if (list ! = null && list.size() > 0) result = p.test(list.get(list.size() - 1)); return result; }}; }Copy the code

Pseudocode sample

List<R> resultList = new ArrayList<>(); for (ExtensionSpec task : this.taskList) { ... result = apply(task.getExt(), preResult); . resultList.add(result); if (this.reducer.stop(resultList)) break; } result = (R) this.reducer.reduce(resultList);Copy the code