package cop3530;

import java.util.Comparator;

public class BogusSet<AnyType> implements Set<AnyType>
{
    public BogusSet( Comparator<? super AnyType> c )
    {
        theSize = 0;
        items = (AnyType[]) new Object[ 5 ];
        cmp = c;
    }
    
    public BogusSet( )
    {
        this( null );
    }
    
    public int getSize( )
    {
        return theSize;
    }
    
    public boolean isEmpty( )
    {
        return getSize( ) == 0;
    }
    
    public boolean add( AnyType x )
    {
        if( theSize == 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 ];
        }
        
        /* CODE IS REDACTED */

        // 1. Find first item >= x

        // 2. Check for duplicates

        // 3. Shift right

        // 4. Drop in x

        
        theSize++;
        
        return true;
    }
    
    private int myCompare( AnyType lhs, AnyType rhs )
    {
        if( cmp != null )
            return cmp.compare( lhs, rhs );
        else
            return ((Comparable)lhs).compareTo( rhs );
        
    }
    
    
    public boolean remove( AnyType x )
    {
        throw new UnsupportedOperationException( );
    }
    
    public boolean contains( 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 theSize;
    private Comparator<? super AnyType> cmp;
}