Linked Iterator

Summary

Create an Iterator for the LinkedBag class and use it to implement the removeAll and retainAll methods for that class.

Ensure that the Iterator returned by LinkedBag's iterator method throws all the proper exceptions:

This assignment is the same as A05, except it's for the LinkedBag class instead of the ArrayBag class.

Other than activating method calls in TestIterator, all changes are to be made in the file LinkedBag.java. If you make changes anywhere else your code will not work with the automated testing system.

Details

For your convenience, I'll repeat the requirements (and suggested order for your implementation work) from A05 here.

Revise LinkedBag by implementing the iterator method. Use a private class for the iterator.

Also implement the next and hasNext methods in your private iterator class.

Run the program to make sure you get reasonable output.

Write the next method so that it throws a NoSuchElementException if all of there are no more items to return.

Run the program to make sure you get reasonable output.

Add the remove method to your iterator.

In A05 you (should have) used the removeItemAt method from ArrayBag. What is the corresponding method in LinkedBag?

Activate the call to testPart3 in TestIterator and run the program again to ensure that you get reasonable behaviour.

Make sure that remove throws an IllegalStateException whenever it's called at a bad time. It's only OK to call remove when next has been called since the previous (if any) call to remove.

Activate the call to testPart4 in TestIterator and run it.

Implement the removeAll and retainAll methods in LinkedBag using your private class.

Activate the call to testPart5 in TestIterator and run it to make sure the provided implementations of removeAll and retainAll work properly.

Make sure that next and remove throw ConcurrentModificationExceptions when they notice a change to the LinkedBag that this Iterator didn't make.

Activate the testPart6 call in TestIterator and check the output.