Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. package common;
  2.  
  3. import java.util.function.Consumer;
  4. import java.util.function.Function;
  5.  
  6. public class Consumers {
  7.  
  8.  
  9. /**
  10. * <pre>
  11. *Stream.of(new Point(1, 2), new Point(2, 3))
  12. *
  13. * // write
  14. * Optional.ofNullable(properties.getProperty("enabled")).ifPresent(call(button::setEnabled,Boolean::valueOf));
  15. *
  16. * // instead of
  17. * Optional.ofNullable(properties.getProperty("enabled")).ifPresent(prop -> button.setEnabled(Boolean.valueOf(prop)));
  18. * </pre>
  19. */
  20. public static <U, T> Consumer<T> call(Consumer<U> consumer, Function<T, U> mapping) {
  21. return (tmp)-> consumer.accept(mapping.apply(tmp));
  22. }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement