All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openclover.util.function.Streams Maven / Gradle / Ivy

Go to download

Clover is an award winning code coverage and testing tool for Java and Groovy. It integrates easily with Maven, Ant, Grails, Eclipse and IntelliJ IDEA as well as with continuous integration servers such as Bamboo, Jenkins or Hudson. Note: before Clover 4.0 this artifact was named com.cenqua.clover:clover.

The newest version!
package org.openclover.util.function;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @deprecated Will be replaced by Java streams API once support for JDK7 is dropped.
 */
public abstract class Streams {

    public static  Collection filter(Collection source, Predicate predicate) {
        final Collection target = new ArrayList<>();
        for (S element : source) {
            if (predicate.test(element)) {
                target.add(element);
            }
        }
        return target;
    }

    public static  Collection map(Collection source, Function function) {
        final Collection target = new ArrayList<>();
        for (S element : source) {
            target.add(function.apply(element));
        }
        return target;
    }

    public static  boolean matchesAny(Collection source, Predicate predicate) {
        for (S element : source) {
            if (predicate.test(element)) {
                return true;
            }
        }
        return false;
    }
}