package cop3530; import java.util.Comparator; import java.util.Iterator; public class BogusSet implements Set { public BogusSet( ) { this( null ); } @SuppressWarnings("unchecked") public BogusSet( Comparator c ) { theSize = 0; items = (AnyType[]) new Object[ 5 ]; cmp = c; } public boolean isEmpty( ) { return theSize == 0; } public int size( ) { return theSize; } public Iterator iterator( ) { return new MyIterator( ); } public boolean add( AnyType x ) { /* Code mostly redacted */ // Stop 0: Double the array if full // Step 1: Find pos of first item >= x: CLEANUP // Step 2: If duplicate return false: CLEANUP // Step 3: Slide items from pos onwards over one spot: CLEANUP // Step 4: // Step 5 // Step 6 return true; } // Like compareTo: <0 if lhs0 if lhs>rhs @SuppressWarnings("unchecked") private int myCompare( AnyType lhs, AnyType rhs ) { if( cmp == null ) return ((Comparable)lhs).compareTo( rhs ); else return cmp.compare( lhs, 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 cmp; } class MyIterator implements Iterator { public boolean hasNext( ) { throw new UnsupportedOperationException( ); } public AnyType next( ) { throw new UnsupportedOperationException( ); } public void remove( ) { throw new UnsupportedOperationException( ); } }