/*
 * @(#)QuickArrayList.java    2.3  25 November 2003
 *
 * Copyright 2004
 * College of Computer and Information Science
 * Northeastern University
 * Boston, MA  02115
 *
 * The Java Power Tools software may be used for educational
 * purposes as long as this copyright notice is retained intact
 * at the top of all source files.
 *
 * To discuss possible commercial use of this software, 
 * contact Richard Rasala at Northeastern University, 
 * College of Computer and Information Science,
 * 617-373-2462 or rasala@ccs.neu.edu.
 *
 * The Java Power Tools software has been designed and built
 * in collaboration with Viera Proulx and Jeff Raab.
 *
 * Should this software be modified, the words "Modified from 
 * Original" must be included as a comment below this notice.
 *
 * All publication rights are retained.  This software or its 
 * documentation may not be published in any media either
 * in whole or in part without explicit permission.
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

package edu.neu.ccs.quick;

import java.util.*;

/**
 * <P><CODE>QuickArrayList</CODE> extends <CODE>ArrayList</CODE> by
 * adding one constructor and three methods <CODE>addItems</CODE>,
 * <CODE>setItems</CODE>, and <CODE>removeItems</CODE> that handle
 * an array of <CODE>Object</CODE> at once.</P>
 *
 * <P>All constructors of the original <CODE>ArrayList</CODE> class
 * are provided as well.</P>
 *
 * <P>No changes are made to the internal data structure or to any
 * inherited methods.</P>
 *
 * @author  Richard Rasala
 * @version 2.3
 * @since   2.3
 */
public class QuickArrayList extends ArrayList {
    
    /** A constructor that delegates to class <CODE>ArrayList</CODE>. */
    public QuickArrayList() { }
    
    
    /** A constructor that delegates to class <CODE>ArrayList</CODE>. */
    public QuickArrayList(Collection c) {
        super(c);
    }
    
    
    /** A constructor that delegates to class <CODE>ArrayList</CODE>. */
    public QuickArrayList(int initialCapacity) {
        super(initialCapacity);
    }
    
    
    /**
     * <P>Constructor that adds the given array of items one-by-one
     * to the array list.</P>
     *
     * <P>The capacity is set to the length of <CODE>items</CODE>.
     
     * <P>If <CODE>items</CODE> is <CODE>null</CODE>, then the
     * capacity is set to 10 (Java default) and nothing is added.</P>
     *
     * @param items the array of items to add to this array list
     * @see #addItems(Object[])
     */
    public QuickArrayList(Object[] items) {
        super((items == null) ? 10 : items.length);
        
        addItems(items);
    }
    
    
    /**
     * <P>Method that adds the given array of items one-by-one to the array list.</P>
     *
     * <P>If <CODE>items</CODE> is <CODE>null</CODE>, then does nothing.</P>
     *
     * @param items the array of items to add to this array list
     * @see #QuickArrayList(Object[])
     * @see #setItems(Object[])
     * @see #removeItems(Object[])
     */
    public void addItems(Object[] items) {
        if (items == null)
            return;
        
        int length = items.length;
        
        for (int i = 0; i < length; i++)
            add(items[i]);
    }
    
    
    /**
     * <P>Method that first clears this array list of any existing items and
     * then adds the given array of items one-by-one to the array list.</P>
     *
     * <P>If <CODE>items</CODE> is <CODE>null</CODE>, then this method
     * is equivalent to the inherited method <CODE>clear</CODE>.</P>
     *
     * @param items the array of items to add to this array list after clearance
     * @see #addItems(Object[])
     * @see #removeItems(Object[])
     */
    public void setItems(Object[] items) {
        clear();
        addItems(items);
    }
    
    
    /**
     * <P>Method that removes the given array of items one-by-one from the
     * array list.</P>
     *
     * <P>If <CODE>items</CODE> is <CODE>null</CODE>, then does nothing.</P>
     *
     * @param items the array of items to remove from this array list
     * @see #addItems(Object[])
     * @see #setItems(Object[])
     */
    public void removeItems(Object[] items) {
        if (items == null)
            return;
        
        int length = items.length;
        
        for (int i = 0; i < length; i++)
            remove(items[i]);
    }
}
