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

private static <T> boolean isMatch(Component component, Class<T> type, Predicate<T> predicate) {
    return type.isInstance(component) && predicate.test(type.cast(component));
}

From source file:Main.java

public static <E> boolean anyMatch(List<E> elements, Predicate<E> predicate) {
    for (E element : elements) {
        if (predicate.test(element)) {
            return true;
        }//from   w ww  .j a v a 2s  . c  o  m
    }
    return false;
}

From source file:Main.java

public static <E> boolean allMatch(List<E> elements, Predicate<E> predicate) {
    for (E element : elements) {
        if (!predicate.test(element)) {
            return false;
        }//from   w w w  . j  a va 2  s  . c o  m
    }
    return true;
}

From source file:Main.java

public static <ELEM, INTO extends Collection<ELEM>> INTO filter2(INTO into, Iterable<? extends ELEM> from,
        Predicate<ELEM> predicate) {
    for (ELEM elem : from) {
        if (predicate.test(elem)) {
            into.add(elem);//from w  w  w.j ava  2  s . com
        }
    }
    return into;
}

From source file:Main.java

public static <Key, Value> Collection<Value> filterMapValuesByKey(Map<Key, Value> map,
        Predicate<Key> keyPredicate) {
    return map.entrySet().parallelStream().filter(entry -> keyPredicate.test(entry.getKey()))
            .map(Map.Entry::getValue).collect(Collectors.toList());
}

From source file:Main.java

public static <T> boolean anyMatch(Iterable<T> inputs, Predicate<T> predicate) {
    for (T t : inputs) {
        if (predicate.test(t)) {
            return true;
        }//from   w w  w. ja v a2s  . c  om
    }
    return false;
}

From source file:Main.java

public static <T> boolean allMatch(Iterable<T> inputs, Predicate<T> predicate) {
    for (T t : inputs) {
        if (!predicate.test(t)) {
            return false;
        }//from  w  w  w.j  av a2s .c o m
    }
    return true;
}

From source file:Main.java

public static <T> List<T> filterIt(List<T> candidates, Predicate<T> condition) {
    List<T> filteredList = new ArrayList<>();

    for (T candidate : candidates) {
        if (condition.test(candidate)) {
            filteredList.add(candidate);
        }//from  w  w w  . j  a  v a  2s. c o  m
    }

    return filteredList;
}

From source file:Main.java

public static <T> int positionOf(List<T> list, Predicate<T> predicate) {
    int i = 0;/*  www.ja  v a 2  s .c o  m*/
    for (T item : list) {
        if (predicate.test(item)) {
            return i;
        }

        i++;
    }

    return -1;
}

From source file:Main.java

static <E> boolean noneMatch(List<E> elements, Predicate<E> predicate) {
    //TODO Implement me
    for (E element : elements) {
        if (predicate.test(element)) {
            return false;
        }//from   ww w  .  j a v  a2  s .  c o m
    }
    return true;
}