|CSC 207||Algorithms and Object Oriented Design||Spring 2010|
Summary: In this lab, you will experiment with implementations of methods for collections.
/** Adds all of the elements in the specified collection to this * collection. */ public boolean addAll(Collection<? extends AnyType> c); /** Removes all this collection's elements that are also contained * in the specified collection. */ public boolean removeAll(Collection<?> c); /** Returns true if this collection contains all of the elements in * the specified collection. */ public boolean containsAll(Collection<?> c);
Collectioninterface in package
AbstractCollectionin the same package.
addmethod) and uses one of the above methods on them.
Note: Remember that your program will have to know where
to find the
weiss packages. In
an earlier lab, you modified
your .emacs file so that JDE knew this. If you try to
compile your driver program from the command line, you will have
to manually specify it with the -classpath argument
Collectionobjects are considered equal under one of two conditions. Either
equals) in precisely the same order,
equals) in any order.
Collectionto implement both the
AbstractCollectionthat adheres to the specification above.
Add an implementation of
-- Object (Java 2 Platform SE 5.0), hashCode
- Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
- It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.
weiss.util.AbstractCollectionclass that satisfies this contract. (Hint: sum the hash codes of the objects in the collection.)