List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:Main.java
public static void processMembersWithFunction(List<Student> roster, Predicate<Student> tester, Function<Student, String> mapper, Consumer<String> block) { for (Student p : roster) { if (tester.test(p)) { String data = mapper.apply(p); block.accept(data); }/*from ww w. jav a 2s . c o m*/ } }
From source file:Main.java
public static void processThreadDump(final Consumer<String> writer) { for (final Map.Entry<Thread, StackTraceElement[]> entry : Thread.getAllStackTraces().entrySet()) { writer.accept("Thread: " + entry.getKey()); final StackTraceElement[] trace = entry.getValue(); for (final StackTraceElement element : trace) { writer.accept("\tat " + element); }/*from ww w . j a v a 2 s . com*/ } }
From source file:com.github.aptd.simulation.elements.common.CMath.java
/** * consums a stream of matrix objects//from ww w . j av a 2 s .co m * * @param p_stream stream * @param p_consumer consumer function * @return stream */ public static Stream<DoubleMatrix1D> matrixconsumer(final Stream<DoubleMatrix1D> p_stream, final Consumer<String> p_consumer) { return p_stream.peek(i -> p_consumer.accept(MATRIXFORMAT.toString(i) + " ")); }
From source file:Main.java
public static void flattenRecursively(Object toFlat, Consumer consumer) { if (isIterable(toFlat)) { ((Iterable<Object>) toFlat).forEach(item -> flattenRecursively(item, consumer)); } else {/* w w w . ja v a 2s.c om*/ consumer.accept(toFlat); } }
From source file:org.lightjason.examples.pokemon.simulation.CMath.java
/** * consums a stream of matrix objects/* w w w . j a v a 2 s . c o m*/ * * @param p_stream stream * @param p_consumer consumer function * @return stream */ public static Stream<DoubleMatrix1D> matrixconsumer(final Stream<DoubleMatrix1D> p_stream, final Consumer<String> p_consumer) { return p_stream.map(i -> { p_consumer.accept(MATRIXFORMAT.toString(i) + " "); return i; }); }
From source file:it.unibo.alchemist.test.TestInSimulator.java
private static <T> Consumer<Environment<T>> checkOnNodes(final Consumer<Node<T>> proc) { return env -> env.forEach(n -> { proc.accept(n); });/*w ww . j a v a2 s . co m*/ }
From source file:net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil.java
/** * Binds the underlying property to a source of values. The source property is also initialised using the setter. * * @param underlying The underlying property * @param ui The property exposed to the user (the one in this wizard) * @param setter Setter to initialise the UI value * @param <T> Type of values *///from w ww .j a va2s. com public static <T> void rewire(Property<T> underlying, ObservableValue<? extends T> ui, Consumer<? super T> setter) { setter.accept(underlying.getValue()); rewire(underlying, ui); }
From source file:Main.java
/** * The given consumer will be called once the worker is finished. The result of the worker * will be passed to the consumer./* w w w. j av a 2 s .co m*/ * @param worker the worker * @param consumer the consumer * @param <T> the resukt type of the worker */ public static <T> void then(Worker<T> worker, Consumer<T> consumer) { ReadOnlyBooleanProperty doneProperty = createIsDoneProperty(worker); ChangeListener<Boolean> listener = (o, oldValue, newValue) -> { if (newValue) { consumer.accept(worker.getValue()); } }; doneProperty.addListener(listener); }
From source file:Main.java
/** * Polls every element within the specified {@link Queue} and performs the specified {@link Consumer} event for each * element./*from w w w . j ava 2 s .co m*/ * * @param queue The Queue to poll each element for, may not be {@code null}. * @param consumer The Consumer event to execute for each polled element, may not be {@code null}. */ public static <T> void pollAll(Queue<T> queue, Consumer<T> consumer) { Preconditions.checkNotNull(queue, "Queue may not be null"); Preconditions.checkNotNull(consumer, "Consumer may not be null"); T element; while ((element = queue.poll()) != null) { consumer.accept(element); } }
From source file:Main.java
public static void addTextUpdateListener(JTextComponent textComponent, Consumer<DocumentEvent> listener) { Document doc = textComponent.getDocument(); doc.addDocumentListener(new DocumentListener() { @Override//w w w . j av a2s . c o m public void removeUpdate(DocumentEvent e) { listener.accept(e); } @Override public void insertUpdate(DocumentEvent e) { listener.accept(e); } @Override public void changedUpdate(DocumentEvent e) { listener.accept(e); } }); }