/*
 * Copyright (c) 2009 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 *
 */

package com.jscape.util.collections;

import com.jscape.util.functor.UnaryProcedure;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.LinkedList;

/**
 * @author Alex Usun
 */
public class CollectionsAppender<T>
        extends UnaryProcedure<Collection<T>> {

    /**
     * Collection.
     */
    private final Collection<T> collection;

    /**
     * @param <T> CollectionsAppender
     *
     * @return CollectionsAppender
     */
    public static <T> CollectionsAppender<T> listAppender() {
        return new CollectionsAppender<T>(new LinkedList<T>());
    }

    /**
     * @param <T> CollectionsAppender
     *
     * @return CollectionsAppender
     */
    public static <T> CollectionsAppender<T> setAppender() {
        return new CollectionsAppender<T>(new LinkedHashSet<T>());
    }

    /**
     * @param collection collection
     */
    public CollectionsAppender(Collection<T> collection) {
        this.collection = collection;
    }

    /**
     * @param value value
     */
    public void evaluate(Collection<T> value) {
        this.collection.addAll(value);
    }

    /**
     * @return Collection
     */
    public Collection<T> getCollection() {
        return this.collection;
    }
}