/*
 * 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 CollectionAppender<T>
        extends UnaryProcedure<T> {

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

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

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

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

    /**
     * @param value value
     */
    public void evaluate(T value) {
        this.collection.add(value);
    }

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