Consider the following interfaces: IntegerCollection and IntegerIterator. Your job is to implement these two interfaces. In implementation of these classes, you MUST not use any classes from java.util or any other classes. The solution must be original and it must be your own solution.
I will provide the driver class (for testing your implementation on next class, October 7, 2003).
/**
* IntegerCollection is a collection of integers;
* Rule-1: IntegerCollection can not have null values.
* Rule-2: IntegerCollection may have duplicate elements.
* Rule-3: IntegerCollection may have any number of elements.
*/
public interface IntegerCollection {
public boolean add(int i);
// Ensures that this collection contains the
// specified element.
public boolean addAll(IntegerCollection c);
// Adds all of the elements in the specified
// collection to this collection.
public void clear();
// Removes all of the elements from this collection
public boolean contains(int i);
// Returns true if this collection contains
// the specified element.
public boolean containsAll(IntegerCollection c);
// Returns true if this collection contains all
// of the elements in the specified collection.
public boolean equals(int i);
// Compares the specified object with this
// collection for equality.
public int hashCode();
// Returns the hash code value for this collection.
public boolean isEmpty();
// Returns true if this collection contains no elements.
public IntegerIterator iterator();
//Returns an iterator over the elements in this collection.
public boolean remove(int i);
// Removes a single instance of the specified element
// from this collection, if it is present.
public boolean removeAll(IntegerCollection c);
// Removes all this collection's elements that are also
// contained in the specified collection
public boolean retainAll(IntegerCollection c)
// Retains only the elements in this collection that are
// contained in the specified collection (optional operation).
public int size();
// Returns the number of elements in this collection.
public int[] toArray()
// Returns an array containing all of the elements
// in this collection.
public void unique();
// all duplicate elements will be removed.
}
/**
* An iterator over a collection of integers. IntegerIterator takes
* the place of Enumeration in the Java collections framework.
* IntegerIterator allow the caller to remove elements from the
* underlying collection during the iteration with well-defined semantics.
*/
public interface IntegerIterator
public boolean hasNext();
//Returns true if the iteration has more elements.
public int next()
//Returns the next element in the iteration.
public void remove();
//Removes from the underlying collection the last
// element returned by the iterator
}