Example usage for java.util.function Predicate test

List of usage examples for java.util.function Predicate test

Introduction

In this page you can find the example usage for java.util.function Predicate test.

Prototype

boolean test(T t);

Source Link

Document

Evaluates this predicate on the given argument.

Usage

From source file:Main.java

public static void main(String... args) {
    Predicate<String> predicate = (s) -> s.length() > 0;

    predicate.test("foo"); // true
    predicate.negate().test("foo"); // false  
}

From source file:Main.java

public static void main(String... args) {
    Predicate<String> isEmpty = String::isEmpty;
    System.out.println(isEmpty.test(""));
    System.out.println(isEmpty.negate().test(""));
}

From source file:Main.java

public static void main(String... args) {
    Predicate<Boolean> nonNull = Objects::isNull;
    System.out.println(nonNull.test(true));
    System.out.println(nonNull.negate().test(false));
}

From source file:Main.java

public static void main(String[] args) {
    Predicate<String> i = (s) -> s.length() > 5;

    System.out.println(i.test("java2s.com "));
}

From source file:Main.java

public static void main(String... args) {
    Predicate<Boolean> nonNull = Objects::nonNull;
    System.out.println(nonNull.test(true));
    System.out.println(nonNull.negate().test(false));
}

From source file:Main.java

public static void main(String... args) {
    Predicate<String> isEmpty = String::isEmpty;
    System.out.println(isEmpty.test(""));

    Predicate<String> isNotEmpty = isEmpty.negate();

    System.out.println(isNotEmpty.test(""));
}

From source file:Main.java

License:asdf

public static void main(String[] args) {
    Predicate<String> i = Predicate.isEqual("asdf");

    System.out.println(i.test("java2s.com "));
}

From source file:Main.java

public static void main(String[] args) {
    Predicate<Integer> prime = (value) -> {
        if (value <= 2) {
            return (value == 2);
        }//from w  ww. ja  v  a 2 s  . c o  m
        for (long i = 2; i * i <= value; i++) {
            if (value % i == 0) {
                return false;
            }
        }
        return true;
    };

    System.out.println("Primzahl 1: " + prime.test(1));
    System.out.println("Primzahl 1: " + prime.test(3));
}

From source file:Main.java

public static boolean checkVisaCode(Predicate<Integer> pred, Integer param) {

    return pred.test(param);

}

From source file:Main.java

/**
 * Adds the given value to the collection if the value satisfies the given predicate.
 *
 * @param <E>//www.ja v a 2 s .  c om
 *            the collection element type
 * @param collection
 *            the collection to add the value to
 * @param value
 *            the value to add
 * @param predicate
 *            the predicate to test againts the given value
 * @return <code>true</code>, if the collection has been modified by the operation and <code>false</code> if the
 *         value was <code>null</code> or the collection already contained the value
 */
public static <E> boolean addIf(Collection<E> collection, E value, Predicate<E> predicate) {
    if (predicate.test(value)) {
        return collection.add(value);
    }
    return false;
}