void merge(V value, BinaryOperator<V> mergeFunction) { checkNotNull(value, "value"); this.value = checkNotNull(mergeFunction.apply(this.value, value), "mergeFunction.apply"); } }
@Override public boolean test(T t) { if (!initialized) { result = t; initialized = true; } else { result = accumulator.apply(result, t); } return true; } }
/** * Reduction with binary operator and initial value * @param initial initial value * @param op the operator * @return the result of reducing initial value and all rows with operator */ default T reduce(T initial, BinaryOperator<T> op) { T acc = initial; for (T t : this) { acc = op.apply(acc, t); } return acc; }
private static <R, C, V> void merge( Table<R, C, V> table, R row, C column, V value, BinaryOperator<V> mergeFunction) { checkNotNull(value); V oldValue = table.get(row, column); if (oldValue == null) { table.put(row, column, value); } else { V newValue = mergeFunction.apply(oldValue, value); if (newValue == null) { table.remove(row, column); } else { table.put(row, column, newValue); } } }
@Override public T reduce(T identity, BinaryOperator<T> accumulator) { requireNonNull(accumulator); return accumulator.apply(identity, element); }
public static <T> Optional<T> combine(Optional<T> left, Optional<T> right, BinaryOperator<T> combiner) { if (left.isPresent() && right.isPresent()) { return Optional.of(combiner.apply(left.get(), right.get())); } else if (left.isPresent()) { return left; } else { return right; } } }
public static <T> Optional<T> combine(Optional<T> left, Optional<T> right, BinaryOperator<T> combiner) { if (left.isPresent() && right.isPresent()) { return Optional.of(combiner.apply(left.get(), right.get())); } else if (left.isPresent()) { return left; } else { return right; } } }
void merge(V value, BinaryOperator<V> mergeFunction) { checkNotNull(value, "value"); this.value = checkNotNull(mergeFunction.apply(this.value, value), "mergeFunction.apply"); } }
@Override public JsonNode apply(JsonNode jsonNode) { return parser.apply(source) .map(configNode -> merger.apply(jsonNode, configNode)) .orElse(jsonNode); } }
@Override final <T, A, R> A result(Collector<T, A, R> collector, Iterable<T> inputs) { A accum = collector.supplier().get(); for (T input : inputs) { A newAccum = collector.supplier().get(); collector.accumulator().accept(newAccum, input); accum = collector.combiner().apply(accum, newAccum); } return accum; } },
private static <R, C, V> void merge( Table<R, C, V> table, R row, C column, V value, BinaryOperator<V> mergeFunction) { checkNotNull(value); V oldValue = table.get(row, column); if (oldValue == null) { table.put(row, column, value); } else { V newValue = mergeFunction.apply(oldValue, value); if (newValue == null) { table.remove(row, column); } else { table.put(row, column, newValue); } } }
void merge(V value, BinaryOperator<V> mergeFunction) { checkNotNull(value, "value"); this.value = checkNotNull(mergeFunction.apply(this.value, value), "mergeFunction.apply"); } }
@Override public ConfigType unparseServiceCreationConfiguration(Configuration configuration, ConfigType configType) { U config = ServiceUtils.findSingletonAmongst(this.configType, configuration.getServiceCreationConfigurations()); if (config == null) { return configType; } else { T foo = getter.apply(configType); if (foo == null) { setter.accept(configType, unparser.apply(config)); } else { setter.accept(configType, merger.apply(foo, unparser.apply(config))); } return configType; } }
@Override public Optional<T> reduce(BinaryOperator<T> accumulator) { if (this.isEmpty()) { return Optional.empty(); } return Optional.of(this.injectInto(null, (result, each) -> result == null ? each : accumulator.apply(result, each))); }
@Override public Optional<T> reduce(BinaryOperator<T> accumulator) { if (this.isEmpty()) { return Optional.empty(); } return Optional.of(this.injectInto(null, (result, each) -> result == null ? each : accumulator.apply(result, each))); }
@Override public Optional<T> reduce(BinaryOperator<T> accumulator) { if (this.isEmpty()) { return Optional.empty(); } return Optional.of(this.injectInto(null, (result, each) -> result == null ? each : accumulator.apply(result, each))); }
@Override public Optional<T> reduce(BinaryOperator<T> accumulator) { if (this.isEmpty()) { return Optional.empty(); } return Optional.of(this.injectInto(null, (result, each) -> result == null ? each : accumulator.apply(result, each))); }
@Override public void add(final String key, final Object value) { checkKeyValue(key, value); if (!this.inExecute && ("incr".equals(key) || "and".equals(key) || "or".equals(key))) throw Memory.Exceptions.memoryIsCurrentlyImmutable(); else if (!this.inExecute) throw Memory.Exceptions.memoryAddOnlyDuringVertexProgramExecute(key); this.currentMap.compute(key, (k, v) -> null == v ? value : this.memoryKeys.get(key).getReducer().apply(v, value)); }
@Override final <T, A, R> A result(Collector<T, A, R> collector, Iterable<T> inputs) { List<A> stack = new ArrayList<>(); for (T input : inputs) { A newAccum = collector.supplier().get(); collector.accumulator().accept(newAccum, input); push(stack, newAccum); } push(stack, collector.supplier().get()); while (stack.size() > 1) { A right = pop(stack); A left = pop(stack); push(stack, collector.combiner().apply(left, right)); } return pop(stack); }
private static <R, C, V> void merge( Table<R, C, V> table, R row, C column, V value, BinaryOperator<V> mergeFunction) { checkNotNull(value); V oldValue = table.get(row, column); if (oldValue == null) { table.put(row, column, value); } else { V newValue = mergeFunction.apply(oldValue, value); if (newValue == null) { table.remove(row, column); } else { table.put(row, column, newValue); } } }