Goals: (A) (more) converting preconditions into postconditions, and (B) Basic JUnit tests.
A: Consider the following three excerpts from the java collection classes documentation:
Note: Great care must be exercised if mutable objects are used as set elements. The behavior of a set is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is an element in the set. A special case of this prohibition is that it is not permissible for a set to contain itself as an element.
The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.
Note that this implementation is not synchronized. If multiple threads access a hash set concurrently, and at least one of the threads modifies the set, it must be synchronized externally.
HashSetimplements both the
Iteratorinterface (the former directly, and the latter through the
iterator()method). Have either of the first two preconditions above been converted into postconditions via the exception handling mechanism?