public void onDone() { if (text.length() == index) { callback.accept(textReceived.toString()); } else { kgb.addCommand(this); } }
public static void main(String[] args) { String s = "abc"; IntSupplier supplier = s::length; System.out.println(supplier.getAsInt()); String s2 = "ぶーさん"; IntSupplier supplier2 = () -> s2.length(); System.out.println(supplier2.getAsInt()); String s3 = "ブタ過ぎる"; IntSupplier supplier3 = new IntSupplier() { @Override public int getAsInt() { return s3.length(); } }; System.out.println(supplier3.getAsInt()); // --------------------------------------------------------- Consumer<String> c = System.out::println; c.accept("pig!!"); Consumer<String> c2 = (String cs) -> System.out.println(cs); c2.accept("buta"); Consumer<String> c3 = new Consumer<String>() { @Override public void accept(String t) { System.out.println(t); } }; c3.accept("ぶうさーん!"); // --------------------------------------------------------- IntBinaryOperator op = Integer::sum; System.out.println(op.applyAsInt(100, 25)); IntBinaryOperator op2 = (int n1, int n2) -> Integer.sum(n1, n2); System.out.println(op2.applyAsInt(70, 50)); }
@Override default Tree<T> peek(Consumer<? super T> action) { Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(head()); } return this; }
final void forEachValue(Consumer<? super V> action) { for (long a, tail, allocations = (a = ~bitSet) << (tail = Long.numberOfLeadingZeros(a)), allocIndex = 64 - tail; allocations != 0; allocations <<= 1, allocIndex--) { if (allocations < 0) action.accept(this.<V>readValue(allocIndex)); } }
private static long execute(Consumer<Integer> primePartitioner) { long fastest = Long.MAX_VALUE; for (int i = 0; i < 10; i++) { long start = System.nanoTime(); primePartitioner.accept(1_000_000); long duration = (System.nanoTime() - start) / 1_000_000; if (duration < fastest) fastest = duration; System.out.println("done in " + duration); } return fastest; }
protected void transactional(Consumer<EntityManager> consumer) { EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); boolean success = false; try { tx.begin(); consumer.accept(em); success = true; } finally { try { if (success) { tx.commit(); } else { tx.rollback(); } } finally { em.close(); } } }
@Override public void render() { CONSUMER.accept("hello"); }
@Override public void foreach(Consumer<T> fun) { fun.accept(value); }
@Override public void foreach(@Nonnull Consumer<T> fun) { assert fun != null; fun.accept(value); }
public static void main(String... args) { Consumer<String> c = s -> id(s); c.accept("rr"); }