List of usage examples for java.util.function Predicate test
boolean test(T t);
From source file:org.talend.dataprep.api.filter.SimpleFilterService.java
private static Predicate<DataSetRow> safeDate(Predicate<DataSetRow> inner) { return r -> { try {//from w w w.j a v a 2s. co m return inner.test(r); } catch (DateTimeException e) { // thrown by DateParser LOGGER.debug("Unable to parse date.", e); return false; } }; }
From source file:src.main.java.com.vgorcinschi.assignmentone.utils.StringValidator.java
public static String stringValidator(Predicate<String> cond, Supplier<String> validationMsg, String type, Scanner sc) {//from www.j a va2 s . c o m String response = null; boolean responseReady = false; System.out.println("Please enter your " + type); while (!responseReady) { String unsanitized = sc.nextLine(); if (!isNotBlank(unsanitized)) { log.error("An invalid input has been provided while asking for " + type); System.out.println("You cannot enter blank name. Please try again."); } else if (ofNullable(cond).isPresent()) { if (!cond.test(unsanitized)) { log.error("An invalid input has been provided(" + unsanitized + ") " + "while asking for " + type + ". Additional requirements failed: " + validationMsg.get()); System.out.println(isNotBlank(validationMsg.get()) ? validationMsg.get() : "You haven't " + "meat caller's additional requirements. Unfortunately he hasn't provided " + "any validation details."); } else { responseReady = true; response = unsanitized; log.info("A successful response has been provided for " + type + ": " + response); } } else { responseReady = true; response = unsanitized; log.info("A successful response has been provided for " + type + ": " + response); } } return response; }
From source file:at.gridtec.lambda4j.predicate.bi.BiPredicate2.java
/** * Creates a {@link BiPredicate2} which uses the {@code first} parameter of this one as argument for the given * {@link Predicate}.//from w w w . j a va2 s. c om * * @param <T> The type of the first argument to the predicate * @param <U> The type of the second argument to the predicate * @param predicate The predicate which accepts the {@code first} parameter of this one * @return Creates a {@code BiPredicate2} which uses the {@code first} parameter of this one as argument for the * given {@code Predicate}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U> BiPredicate2<T, U> onlyFirst(@Nonnull final Predicate<? super T> predicate) { Objects.requireNonNull(predicate); return (t, u) -> predicate.test(t); }
From source file:at.gridtec.lambda4j.predicate.bi.BiPredicate2.java
/** * Creates a {@link BiPredicate2} which uses the {@code second} parameter of this one as argument for the given * {@link Predicate}.//from w w w .j a va 2 s .co m * * @param <T> The type of the first argument to the predicate * @param <U> The type of the second argument to the predicate * @param predicate The predicate which accepts the {@code second} parameter of this one * @return Creates a {@code BiPredicate2} which uses the {@code second} parameter of this one as argument for the * given {@code Predicate}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U> BiPredicate2<T, U> onlySecond(@Nonnull final Predicate<? super U> predicate) { Objects.requireNonNull(predicate); return (t, u) -> predicate.test(u); }
From source file:org.nuxeo.common.utils.ZipUtils.java
private static void unzip(ZipInputStream in, File dir, Predicate<ZipEntry> filter, Function<String, String> nameFormatter) throws IOException { dir.mkdirs();/*w w w . j a v a2 s .com*/ ZipEntry entry; while ((entry = in.getNextEntry()) != null) { if (!entry.getName().contains("..") && filter.test(entry)) { File file = new File(dir, nameFormatter.apply(entry.getName())); if (entry.isDirectory()) { file.mkdirs(); } else { file.getParentFile().mkdirs(); try (FileOutputStream output = FileUtils.openOutputStream(file)) { IOUtils.copy(in, output); } } } } }
From source file:src.main.java.com.vgorcinschi.assignmenttwo.util.StringValidator.java
public static String stringValidator(Predicate<String> cond, Supplier<String> validationMsg, Supplier<String> type, Scanner sc) { String response = null;// w w w .j a va 2s.c o m boolean responseReady = false; System.out.println("Please enter your " + type.get()); while (!responseReady) { String unsanitized = sc.nextLine(); if (!isNotBlank(unsanitized)) { log.error("An invalid input has been provided while asking for " + type.get()); System.out.println("You cannot enter blank name. Please try again."); } else if (ofNullable(cond).isPresent()) { if (!cond.test(unsanitized)) { log.error("An invalid input has been provided(" + unsanitized + ") " + "while asking for " + type.get() + ". Additional requirements failed: " + validationMsg.get()); System.out.println(isNotBlank(validationMsg.get()) ? validationMsg.get() : "You haven't " + "meat caller's additional requirements. Unfortunately he hasn't provided " + "any validation details."); } else { responseReady = true; response = unsanitized; log.info("A successful response has been provided for " + type.get() + ": " + response); } } else { responseReady = true; response = unsanitized; log.info("A successful response has been provided for " + type.get() + ": " + response); } } return response; }
From source file:at.gridtec.lambda4j.predicate.tri.TriPredicate.java
/** * Creates a {@link TriPredicate} which uses the {@code first} parameter of this one as argument for the given * {@link Predicate}./*from www . j a v a2 s .c o m*/ * * @param <T> The type of the first argument to the predicate * @param <U> The type of the second argument to the predicate * @param <V> The type of the third argument to the predicate * @param predicate The predicate which accepts the {@code first} parameter of this one * @return Creates a {@code TriPredicate} which uses the {@code first} parameter of this one as argument for the * given {@code Predicate}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U, V> TriPredicate<T, U, V> onlyFirst(@Nonnull final Predicate<? super T> predicate) { Objects.requireNonNull(predicate); return (t, u, v) -> predicate.test(t); }
From source file:at.gridtec.lambda4j.predicate.tri.TriPredicate.java
/** * Creates a {@link TriPredicate} which uses the {@code second} parameter of this one as argument for the given * {@link Predicate}./*from ww w .j a v a2 s . c o m*/ * * @param <T> The type of the first argument to the predicate * @param <U> The type of the second argument to the predicate * @param <V> The type of the third argument to the predicate * @param predicate The predicate which accepts the {@code second} parameter of this one * @return Creates a {@code TriPredicate} which uses the {@code second} parameter of this one as argument for the * given {@code Predicate}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U, V> TriPredicate<T, U, V> onlySecond(@Nonnull final Predicate<? super U> predicate) { Objects.requireNonNull(predicate); return (t, u, v) -> predicate.test(u); }
From source file:at.gridtec.lambda4j.predicate.tri.TriPredicate.java
/** * Creates a {@link TriPredicate} which uses the {@code third} parameter of this one as argument for the given * {@link Predicate}./* w w w . j a va2s. co m*/ * * @param <T> The type of the first argument to the predicate * @param <U> The type of the second argument to the predicate * @param <V> The type of the third argument to the predicate * @param predicate The predicate which accepts the {@code third} parameter of this one * @return Creates a {@code TriPredicate} which uses the {@code third} parameter of this one as argument for the * given {@code Predicate}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U, V> TriPredicate<T, U, V> onlyThird(@Nonnull final Predicate<? super V> predicate) { Objects.requireNonNull(predicate); return (t, u, v) -> predicate.test(v); }
From source file:password.pwm.util.java.JavaHelper.java
public static long pause(final long sleepTimeMS, final long predicateCheckIntervalMS, final Predicate predicate) { final long startTime = System.currentTimeMillis(); final long pauseTime = Math.max(sleepTimeMS, predicateCheckIntervalMS); while ((System.currentTimeMillis() - startTime) < sleepTimeMS) { JavaHelper.pause(pauseTime);/*from www.j av a 2 s. co m*/ if (predicate.test(null)) { break; } } return System.currentTimeMillis() - startTime; }