package cop3530; public class BogusSet implements Set { public BogusSet( ) { items = (AnyType []) new Object[ 5 ]; size = 0; } public Object [ ] toArray( ) { Object [ ] copy = new Object[ size ]; for( int i = 0; i < size; i++ ) copy[ i ] = items[ i ]; return copy; } public OtherType [ ] toArray( OtherType [ ] copy ) { if( copy.length < size ) throw new IllegalArgumentException( ); for( int i = 0; i < size; i++ ) copy[ i ] = (OtherType) items[ i ]; return copy; } public boolean isEmpty( ) { return getSize( ) == 0; } public int getSize( ) { return size; } public boolean add( AnyType x ) { /* Redacted */ } public boolean contains( AnyType x ) { throw new UnsupportedOperationException( ); } public boolean remove( AnyType x ) { throw new UnsupportedOperationException( ); } public String toString( ) { StringBuilder result = new StringBuilder( "[" ); for( int i = 0; i < size; i++ ) result.append( " " + items[ i ] ); result.append( " ]" ); return new String( result ); } public java.util.Iterator iterator( ) { return new MyIterator( ); } private AnyType [ ] items; private int size; private class MyIterator implements java.util.Iterator { public boolean hasNext( ) { return currentPos != size; } public AnyType next( ) { if( !hasNext( ) ) throw new IndexOutOfBoundsException( ); return items[ currentPos++ ]; } public void remove( ) { BogusSet.this.remove( items[ --currentPos ] ); } private int currentPos = 0; } }