package cop3530;

public class BogusSet<AnyType> implements Set<AnyType>
{
    public BogusSet( )
    {
        items = (AnyType []) new Object[ 5 ];
        size  = 0;
    }
    
    public boolean isEmpty( )
    {
        return getSize( ) == 0;
    }
    
    public int getSize( )
    {
        return size;
    }
    
    public boolean add( AnyType x )
    {
        if( size == items.length )
        {
            AnyType [ ] old = items;
            items = (AnyType[]) new Object[ old.length * 2 + 1 ];
            for( int i = 0; i < old.length; i++ )
                items[ i ] = old[ i ];
        }
        
        items[ size++ ] = x;
        
        return true;
    }
    
    public boolean contains( AnyType x )
    {
        throw new UnsupportedOperationException( );    
    }
    
    public boolean remove( AnyType x )
    {
        throw new UnsupportedOperationException( );    
    }
    
    public String toString( )
    {
        StringBuffer result = new StringBuffer( "[ " );

        for( int i = 0; i < theSize; i++ )
            result.append( items[ i ] + " " );

        result.append( "]" );

        return new String( result );
    }

    private AnyType [ ] items;
    private int size;
}
