package com.srbenoit.filter;

import java.util.ArrayList;
import java.util.List;

/**
 * A filter tree, consisting of an ordered list of filters, each of which has its actual input and
 * output tags set, as well as any parameter values.
 */
public class FilterTree {

    /** the filters in the tree */
    private final List<AbstractFilter> filters;

    /**
     * Constructs a new <code>FilterTree</code>.
     */
    public FilterTree() {

        this.filters = new ArrayList<AbstractFilter>(20);
    }

    /**
     * Gets the number of filters in the tree.
     *
     * @return  the number of filters
     */
    public int getNumFilters() {

        return this.filters.size();
    }

    /**
     * Gets a particular filter.
     *
     * @param   index  the index of the filter to retrieve
     * @return  the filter
     */
    public AbstractFilter getFilter(final int index) {

        return this.filters.get(index);
    }

    /**
     * Adds a particular filter.
     *
     * @param  filter  the filter to add
     */
    public void addFilter(final AbstractFilter filter) {

        this.filters.add(filter);
    }

    /**
     * Adds a particular filter at a specified position in the list, shifting the filter in that
     * position and all subsequent filters down one position.
     *
     * @param  index   the position at which to insert the filter
     * @param  filter  the filter to add
     */
    public void addFilter(final int index, final AbstractFilter filter) {

        this.filters.add(index, filter);
    }

    /**
     * Removes a particular filter.
     *
     * @param   index  the index of the filter to remove
     * @return  the removed filter
     */
    public AbstractFilter removeFilter(final int index) {

        return this.filters.remove(index);
    }
}
