List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:Main.java
public static void send(Consumer<Mailer> mailerOperator) { Mailer mailer = new Mailer(); mailerOperator.accept(mailer); System.out.println("Sending ..."); }
From source file:Main.java
public static void processCustomer(int id, Consumer<Customer> makeCustomerHappy) { Customer c = Database.getCustomerWithId(id); makeCustomerHappy.accept(c); }
From source file:Main.java
public static <A> void forEach(List<A> as, Consumer<A> effect) { for (A a : as) { effect.accept(a); }//from ww w . j a v a 2 s . co m }
From source file:Main.java
public static <T> void runInThread(Consumer<T> consumer, T element) { Runnable runnable = () -> consumer.accept(element); new Thread(runnable).start(); }
From source file:Main.java
public static void forEach(NodeList list, Consumer<Node> consumer) { for (int i = 0; i < list.getLength(); i++) { consumer.accept(list.item(i)); }//w w w . ja v a 2 s .c om }
From source file:Main.java
public static void forEach(NodeList nl, Consumer<Node> action) { for (int i = 0; i < nl.getLength(); i++) { action.accept(nl.item(i)); }//from w w w . j a va 2s . c o m }
From source file:Main.java
/** * //from w w w .java 2 s. c om * <pre> * {@code * forEach(Arrays.asList(1, 2, 3), (Integer content) -> System.out.format("Have been consumed %d", content)); * } * </pre> * * @param list * @param consumer */ public static <T> void forEach(List<T> list, Consumer<T> consumer) { for (T entry : list) { consumer.accept(entry); } }
From source file:Main.java
public static Iterable<String> iterate(Matcher matcher) { return new Iterable<String>() { @Override/* www . j a v a 2s.c o m*/ public Iterator<String> iterator() { return new Iterator<String>() { @Override public boolean hasNext() { return matcher.find(); } @Override public String next() { return matcher.group(); } }; } @Override public void forEach(Consumer<? super String> action) { while (matcher.find()) { action.accept(matcher.group()); } } }; }
From source file:Main.java
public static <E> void forEach(Collection<E> c, Consumer<? super E> action) { if (isNullOrEmpty(c)) { return;/*from ww w . j a v a 2s .c om*/ } for (E item : c) { action.accept(item); } }
From source file:com.netflix.spinnaker.clouddriver.google.names.GoogleLabeledResourceNamer.java
private static <T> void setIfPresent(Consumer<T> setter, T value) { if (value != null) { setter.accept(value); }/* ww w. j a v a2s . co m*/ }