Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package common;
- import java.util.function.Consumer;
- import java.util.function.Function;
- public class Consumers {
- /**
- * <pre>
- *Stream.of(new Point(1, 2), new Point(2, 3))
- *
- * // write
- * Optional.ofNullable(properties.getProperty("enabled")).ifPresent(call(button::setEnabled,Boolean::valueOf));
- *
- * // instead of
- * Optional.ofNullable(properties.getProperty("enabled")).ifPresent(prop -> button.setEnabled(Boolean.valueOf(prop)));
- * </pre>
- */
- public static <U, T> Consumer<T> call(Consumer<U> consumer, Function<T, U> mapping) {
- return (tmp)-> consumer.accept(mapping.apply(tmp));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement