Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. package common;
  2.  
  3. import java.util.function.Function;
  4. import java.util.function.Predicate;
  5.  
  6. public class Predicates {
  7.  
  8. /**
  9. * <pre>
  10. *Stream.of(new Point(1, 2), new Point(2, 3))
  11. *
  12. * // write
  13. * .filter(equals(1D, Point::getX))
  14. *
  15. * // instead of
  16. * .filter(p -> new Double(1).equals(p.getX()) )
  17. * </pre>
  18. */
  19. public static <T, U> Predicate<T> equals(final U expected, Function<T, U> mapping) {
  20. return (T it) -> expected.equals(mapping.apply(it));
  21. }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement