List of usage examples for java.util.function Predicate test
boolean test(T t);
From source file:at.gridtec.lambda4j.function.bi.conversion.BiBooleanToFloatFunction.java
/** * Returns a composed {@link ToFloatBiFunction} that first applies the {@code before} predicates to its input, and * then applies this function to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given predicate, and of composed function * @param <B> The type of the argument to the second given predicate, and of composed function * @param before1 The first predicate to apply before this function is applied * @param before2 The second predicate to apply before this function is applied * @return A composed {@code ToFloatBiFunction} that first applies the {@code before} predicates to its input, and * then applies this function to the result. * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. *///from w w w .j a v a 2 s .c o m @Nonnull default <A, B> ToFloatBiFunction<A, B> compose(@Nonnull final Predicate<? super A> before1, @Nonnull final Predicate<? super B> before2) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); return (a, b) -> applyAsFloat(before1.test(a), before2.test(b)); }
From source file:at.gridtec.lambda4j.function.bi.conversion.BiBooleanToShortFunction.java
/** * Returns a composed {@link ToShortBiFunction} that first applies the {@code before} predicates to its input, and * then applies this function to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given predicate, and of composed function * @param <B> The type of the argument to the second given predicate, and of composed function * @param before1 The first predicate to apply before this function is applied * @param before2 The second predicate to apply before this function is applied * @return A composed {@code ToShortBiFunction} that first applies the {@code before} predicates to its input, and * then applies this function to the result. * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. *//* w w w . j a v a 2 s .com*/ @Nonnull default <A, B> ToShortBiFunction<A, B> compose(@Nonnull final Predicate<? super A> before1, @Nonnull final Predicate<? super B> before2) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); return (a, b) -> applyAsShort(before1.test(a), before2.test(b)); }
From source file:at.gridtec.lambda4j.function.bi.conversion.BiBooleanToDoubleFunction.java
/** * Returns a composed {@link ToDoubleBiFunction2} that first applies the {@code before} predicates to its input, and * then applies this function to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given predicate, and of composed function * @param <B> The type of the argument to the second given predicate, and of composed function * @param before1 The first predicate to apply before this function is applied * @param before2 The second predicate to apply before this function is applied * @return A composed {@code ToDoubleBiFunction2} that first applies the {@code before} predicates to its input, and * then applies this function to the result. * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. *//*from w ww . jav a 2s . c om*/ @Nonnull default <A, B> ToDoubleBiFunction2<A, B> compose(@Nonnull final Predicate<? super A> before1, @Nonnull final Predicate<? super B> before2) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); return (a, b) -> applyAsDouble(before1.test(a), before2.test(b)); }
From source file:at.gridtec.lambda4j.function.tri.TriBooleanFunction.java
/** * Returns a composed {@link TriFunction} that first applies the {@code before} predicates to its input, and * then applies this function to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given predicate, and of composed function * @param <B> The type of the argument to the second given predicate, and of composed function * @param <C> The type of the argument to the third given predicate, and of composed function * @param before1 The first predicate to apply before this function is applied * @param before2 The second predicate to apply before this function is applied * @param before3 The third predicate to apply before this function is applied * @return A composed {@code TriFunction} that first applies the {@code before} predicates to its input, and then * applies this function to the result.// w ww. java 2 s . c o m * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. */ @Nonnull default <A, B, C> TriFunction<A, B, C, R> compose(@Nonnull final Predicate<? super A> before1, @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); Objects.requireNonNull(before3); return (a, b, c) -> apply(before1.test(a), before2.test(b), before3.test(c)); }
From source file:com.diffplug.gradle.GradleIntegrationTest.java
protected String getContents(Predicate<String> subpathsToInclude) throws IOException { TreeDef<File> treeDef = TreeDef.forFile(Errors.rethrow()); List<File> files = TreeStream.depthFirst(treeDef, folder.getRoot()).filter(file -> file.isFile()) .collect(Collectors.toList()); ListIterator<File> iterator = files.listIterator(files.size()); int rootLength = folder.getRoot().getAbsolutePath().length() + 1; return StringPrinter.buildString(printer -> { Errors.rethrow().run(() -> {/*from w w w . j a va 2 s . co m*/ while (iterator.hasPrevious()) { File file = iterator.previous(); String subPath = file.getAbsolutePath().substring(rootLength); if (subpathsToInclude.test(subPath)) { printer.println("### " + subPath + " ###"); printer.println(read(subPath)); } } }); }); }
From source file:com.dtolabs.rundeck.core.authorization.RuleEvaluator.java
/** * Return true if all predicate tests on a certain resource entry evaluate to true * * @param resource the resource * @param stringPredicate a Converter<S,Predicate> to convert String to Predicate test * @param key the resource attribute key to check * @param test test to apply, can be a String, or List of Strings if allowListMatch is true * @param listpred//w ww. j ava 2 s .c o m * @param sourceIdentity */ boolean applyTest(final Map<String, String> resource, final Function<String, Predicate<String>> stringPredicate, final String key, final Object test, final Function<List, Predicate<String>> listpred, final String sourceIdentity) { final ArrayList<Predicate<String>> tests = new ArrayList<>(); if (listpred != null && test instanceof List) { //must match all values tests.add(listpred.apply((List) test)); } else if (test instanceof String) { //match single test tests.add(stringPredicate.apply((String) test)); } else { //unexpected format, do not match if (test != null) { logger.error(sourceIdentity + ": cannot evaluate unexpected type: " + test.getClass().getName()); } else { logger.error(sourceIdentity + ": cannot evaluate: null value for key `" + key + "`"); } return false; } String value = resource.get(key); return tests.stream().allMatch(new Predicate<Predicate<String>>() { @Override public boolean test(final Predicate<String> pred) { return pred.test(value); } }); }
From source file:org.openstreetmap.josm.tools.Utils.java
/** * Finds the first item in the iterable for which the predicate matches. * @param <T> The iterable type./*ww w. java 2s . c om*/ * @param collection The iterable to search in. * @param predicate The predicate to match * @return the item or <code>null</code> if there was not match. */ public static <T> T find(Iterable<? extends T> collection, Predicate<? super T> predicate) { for (T item : collection) { if (predicate.test(item)) { return item; } } return null; }
From source file:at.gridtec.lambda4j.function.tri.obj.ObjBiBooleanFunction.java
/** * Returns a composed {@link TriFunction} that first applies the {@code before} functions to its input, and * then applies this function to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given function, and of composed function * @param <B> The type of the argument to the second given predicate, and of composed function * @param <C> The type of the argument to the third given predicate, and of composed function * @param before1 The first function to apply before this function is applied * @param before2 The second predicate to apply before this function is applied * @param before3 The third predicate to apply before this function is applied * @return A composed {@code TriFunction} that first applies the {@code before} functions to its input, and then * applies this function to the result.// www . j av a 2s . com * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. */ @Nonnull default <A, B, C> TriFunction<A, B, C, R> compose(@Nonnull final Function<? super A, ? extends T> before1, @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); Objects.requireNonNull(before3); return (a, b, c) -> apply(before1.apply(a), before2.test(b), before3.test(c)); }
From source file:org.openstreetmap.josm.tools.Utils.java
/** * Find the index of the first item that matches the predicate. * @param <T> The iterable type//from ww w. j av a 2s. c o m * @param collection The iterable to iterate over. * @param predicate The predicate to search for. * @return The index of the first item or -1 if none was found. */ public static <T> int indexOf(Iterable<? extends T> collection, Predicate<? super T> predicate) { int i = 0; for (T item : collection) { if (predicate.test(item)) return i; i++; } return -1; }
From source file:at.gridtec.lambda4j.function.tri.obj.BiObjBooleanFunction.java
/** * Returns a composed {@link TriFunction} that first applies the {@code before} functions to its input, and * then applies this function to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given function, and of composed function * @param <B> The type of the argument to the second given function, and of composed function * @param <C> The type of the argument to the third given predicate, and of composed function * @param before1 The first function to apply before this function is applied * @param before2 The second function to apply before this function is applied * @param before3 The third predicate to apply before this function is applied * @return A composed {@code TriFunction} that first applies the {@code before} functions to its input, and then * applies this function to the result.//from w w w.j av a 2 s . com * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. */ @Nonnull default <A, B, C> TriFunction<A, B, C, R> compose(@Nonnull final Function<? super A, ? extends T> before1, @Nonnull final Function<? super B, ? extends U> before2, @Nonnull final Predicate<? super C> before3) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); Objects.requireNonNull(before3); return (a, b, c) -> apply(before1.apply(a), before2.apply(b), before3.test(c)); }