/**
 * @class A dynamically resizing collection of Objects.
 * @author Richard Franks Jr.
 * @constructor
 */
function ArrayList( ){
    //=================ATTRIBUTES============================
    /**
     * @type int
     */
    this.DEFAULT_CAPACITY = 10;
    
    /**
     * @type int
     */
    this.NOT_FOUND = -1;
    
    /**
     items in this collection
     @type Array
     */
    this.theItems = new Array(this.DEFAULT_CAPACITY);
    
    /**
     number of items in this collection
     @type int
     */
    this.theSize = 0;
    
    //=================METHODS============================
    /**
     * Returns the number of items in this collection.
     * @return the number of items in this collection.
     * @type int
     */
    this.size = function() {
        return this.theSize;
    };
    
    /**
     * Returns the item at position idx.
     * @param idx the index to search in.
     * @return the item at position idx
     * @type Object
     */
    this.get = function(idx) {
        if( idx < 0 || idx >= this.size( ) ){
        }else{
            return this.theItems[ idx ];    
        }
    };
    
    /**
     * Changes the item at position idx.
     * @param idx the index to change.
     * @param newVal the new value.
     * @return the old value.
     * @type Object
     * @throws ArrayIndexOutOfBoundsException if index is out of range.
     */
    this.set = function(idx,newVal) {
        if( idx < 0 || idx >= this.size() ){
        } else {
            var old = this.theItems[idx];    
            this.theItems[idx] = newVal;
            
            return old;    
        }
    };
    
    /**
     * Tests if some item is in this collection.
     * @param x any object.
     * @return true if this collection contains an item equal to x.
     * @type boolean
     */
    this.contains = function(x) {
        return this.findPos(x) != this.NOT_FOUND;
    }; 
    
    /**
     * Returns the position of first item matching x in this collection,
     * or NOT_FOUND if not found.
     * @param x any object.
     * @return the position of first item matching x in this collection,
     * or NOT_FOUND if not found.
     * @type int
     */
    this.findPos = function(x) {
        var i;
        for(i = 0; i < this.size(); i++ )
            if( x == null ) {
                if( this.theItems[ i ] == null )
                    return i;
            }
            else if( x == this.theItems[ i ] )
                return i;
        
        return this.NOT_FOUND;
        
    };
    
    /**
     * Adds an item to this collection, at the end.
     * @param x any object.
     * @return true.
     * @type boolean
     */
    this.add = function(x) {
        if( this.theItems.length == this.size( ) ) {
            var old = this.theItems;
            this.theItems = new Array(this.theItems.length * 2 + 1);
            var i;
            for( i = 0; i < this.size( ); i++ )
                this.theItems[ i ] = old[ i ];
        }
        
        this.theItems[this.theSize] = x; 
        this.theSize = this.theSize + 1;
        
        return true;            
    };
    
    /**
     * Removes an item from this collection.
     * @param x any object.
     * @return true if this item was removed from the collection.
     * @type boolean
     */
    this.removeObj = function(x) {
        var pos = this.findPos( x );
        
        if( pos == this.NOT_FOUND )
            return false;
        else {
            this.remove( pos );
            return true;
        }        
    };
    
    /**
     * Removes an item from this collection.
     * @param idx the index of the object.
     * @return the item was removed from the collection.
     * @type Object
     */
    this.removeAtIdx = function(idx) {
        var removedItem = this.theItems[idx];
        var i;
        for( i = idx; i < this.size( ) - 1; i++ )
            this.theItems[ i ] = this.theItems[ i + 1 ];
        this.theSize = this.theSize - 1;    
        
        return removedItem;
    };
    
    /**
     * Change the size of this collection to zero.
     */
    this.clear=function( ) {
        this.theSize = 0;
        this.theItems = new Array(this.DEFAULT_CAPACITY);
    };
}

function strToArrayList(str){
	var myList = new ArrayList();
	if ( str.length > 0 ){
		while (str.indexOf(",") != -1) {
			myList.add(str.substring(0, str.indexOf(",")));
			str = str.substring(str.indexOf(",") + 1, str.length);
		}
		myList.add(str);
	}
	return myList;
}