package com.jscape.util.collections;

import com.jscape.util.functor.UnaryFunction;
import com.jscape.util.functor.UnaryPredicate;

import java.util.Collection;
import java.util.List;

/**
 * @author Alex Usun
 */
public class CopyCollectionIf<T>
        extends UnaryFunction<Collection<T>, List<T>> {

    /**
     * Predicate.
     */
    private final UnaryPredicate<? super T> predicate;

    /**
     * @param predicate predicate
     */
    public CopyCollectionIf(UnaryPredicate<? super T> predicate) {
        this.predicate = predicate;
    }

    /** */
    public CopyCollectionIf() {
        this(new UnaryPredicate.True<T>());
    }

    /**
     * @param value value
     *
     * @return List<T>
     */
    public List<T> evaluate(Collection<T> value) {
        return Algorithms.copyIf(value, this.predicate);
    }
}