| CSC 207 | Algorithms and Object Oriented Design | Spring 2011 |
Summary: In this lab, you will experiment with implementations of methods for collections.
Collection
interface.
/** 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);
Collection interface in
package weiss.util.
AbstractCollection in
the same package.
weiss.util.LinkedList and
its add method) and uses one of the above methods on
them.
Do not put your test class in the book code folder. Instead, put it wherever you regularly place code for this course's labs.
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
to javac.
Collection objects are considered equal under one of
the following two conditions. Either:
List AND
equals) in
precisely the same order,
Set AND
equals) in
any order.
Collection to
implement both the Set and
the List interface?
equals
to AbstractCollection that adheres to the
specification above.
hashCode method is:
Add an implementation of-- Object (Java Platform SE 6), hashCode
- Whenever it is invoked on the same object more than once during an execution of a Java application, the
hashCodemethod 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 thehashCodemethod 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 thehashCodemethod 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.
hashCode to
the weiss.util.AbstractCollection class that satisfies
this contract.
(Hint: sum the hash codes of the objects in the collection.)