Determines that all of the items returned in the given iterator evaluate to true against the given predicate. - Java java.util.function

Java examples for java.util.function:Predicate

Description

Determines that all of the items returned in the given iterator evaluate to true against the given predicate.

Demo Code


//package com.java2s;

import java.util.function.Predicate;

public class Main {
    /**//from www .j  av  a 2s.  c  o  m
     * Determines that all of the items returned in the given iterator evaluate to true against
     * the given predicate.  For empty items, will return true.
     *
     * @param items The iterable items that will be evaluated.
     * @param predicate The predicate used to evaluate against.
     * @param <T> The type of items
     * @return True if all the items evaluated to true on the predicate.
     * @throws NullPointerException if iterable or predicate are null.
     */
    public static <T> boolean all(final Iterable<T> items,
            final Predicate<T> predicate) {
        for (T item : items)
            if (!predicate.test(item))
                return false;
        return true;
    }
}

Related Tutorials