package cop3530; import java.util.Comparator; public class BogusSet implements Set { public BogusSet( ) { this( null ); } public BogusSet( Comparator c ) { items = (AnyType[]) new Object[ 5 ]; // Oops size = 0; cmp = c; } public boolean isEmpty( ) { return getSize( ) == 0; } public int getSize( ) { return size; } public boolean add( AnyType x ) { /* Omitted... */ } private int myCompare( AnyType lhs, AnyType rhs ) { if( cmp != null ) return cmp.compare( lhs, rhs ); else return ((Comparable)lhs).compareTo( rhs ); } 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 < size; i++ ) result.append( " " + items[ i ] ); result.append( " ]" ); return new String( result ); } private AnyType [ ] items; private int size; private Comparator cmp; }