package com.jscape.util.collections;

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

import java.util.Iterator;
import java.util.List;

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

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

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

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

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