| CSC 207 | Algorithms and Object Oriented Design | Spring 2009 |
Summary: In this lab, you will reinforce the properties of Java's inner classes.
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.
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
two conditions. Either
List interface AND
equals) in
precisely the same order,
Set interface 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 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.
hashCode to
the weiss.util.AbstractCollection class that satisfies
this contract.
(Hint: sum the hash codes of the objects in the collection.)