@Override public void onNext(T item) { currentKey = getGroupKey.apply(item); if(currentAcc == null) { // First time init priorKey = currentKey; currentAcc = accCtor.get(); } else if(!Objects.equal(priorKey, currentKey)) { child.onNext(Maps.immutableEntry(priorKey, currentAcc)); currentAcc = accCtor.get(); } accAdd.accept(currentAcc, item); priorKey = currentKey; }
@Override public Flowable<Entry<K, O>> apply(Range<Long> range) { return delegate.apply(range).map(e -> Maps.immutableEntry(e.getKey(), fnTransformItem.apply(e.getValue()))); }
@Override public Flowable<Entry<K, W>> apply(Iterable<K> keys) { Flowable<Entry<K, V>> tmp = base.apply(keys); Flowable<Entry<K, W>> result = tmp.map(e-> Maps.immutableEntry(e.getKey(), fn.apply(e.getKey(), e.getValue()))); // Map<K, W> result = tmp.entrySet().stream() // .collect(Collectors.toMap( // e -> e.getKey(), // e -> fn.apply(e.getKey(), e.getValue()), // (u, v) -> { throw new IllegalStateException(String.format("Duplicate key %s", u)); }, // LinkedHashMap::new)); // // // //Maps.transformValues(tmp, GuavaFunctionWrapper.wrap(fn)); return result; }
@Override public Flowable<Entry<KI, V>> apply(Iterable<KI> keys) { Iterable<KO> kos = Iterables.transform(keys, to); Flowable<Entry<KO, V>> tmp = delegate.apply(kos); Flowable<Entry<KI, V>> result = tmp.map(entry -> { KI ki = from.apply(entry); V v = entry.getValue(); return Maps.immutableEntry(ki, v); }); // Map<KI, V> result = new LinkedHashMap<KI, V>(); // for(Entry<KO, V> entry : tmp.entrySet()) { // KI ki = from.apply(entry); // V v = entry.getValue(); // result.put(ki, v); // } return result; }
@Override public void onComplete() { if(currentAcc != null) { child.onNext(Maps.immutableEntry(priorKey, currentAcc)); } child.onComplete(); }
public static Entry<Var, Node> tryGetVarConst(Expr a, Expr b) { Var v = a.isVariable() ? a.asVar() // Hack to unwrap variables from NodeValue : Optional.of(a).filter(Expr::isConstant) .map(Expr::getConstant).map(NodeValue::asNode).filter(Node::isVariable).map(n -> (Var)n) .orElse(null) ; Entry<Var, Node> result = v != null && b.isConstant() ? Maps.immutableEntry(v, b.getConstant().asNode()) : null ; return result; }
public static Entry<Var, Var> tryGetVarVar(Expr a, Expr b) { Entry<Var, Var> result = a.isVariable() && b.isVariable() ? Maps.immutableEntry(a.asVar(), b.asVar()) : null; return result; }
.doOnNext(i -> currentValue[0] = i) .doOnCancel(() -> isCancelled[0] = true) .map(i -> Maps.immutableEntry((int)(i / 3), i)) .lift(new OperatorOrderedGroupBy<Entry<Integer, Integer>, Integer, List<Integer>>(Entry::getKey, ArrayList::new, (acc, e) -> acc.add(e.getValue())));
K groupKey = tmp; return Maps.immutableEntry(groupKey, buffer); });