Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package common;
- import java.util.function.Function;
- import java.util.function.Predicate;
- public class Predicates {
- /**
- * <pre>
- *Stream.of(new Point(1, 2), new Point(2, 3))
- *
- * // write
- * .filter(equals(1D, Point::getX))
- *
- * // instead of
- * .filter(p -> new Double(1).equals(p.getX()) )
- * </pre>
- */
- public static <T, U> Predicate<T> equals(final U expected, Function<T, U> mapping) {
- return (T it) -> expected.equals(mapping.apply(it));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement