jdsl.core.api
Interface ComparatorBased

All Known Implementing Classes:
RBTree, BTHeap

public abstract interface ComparatorBased

Interface to support containers that rely on an underlying ordering of the elements. Since the PriorityQueue and Dictionary interfaces are not written to force use of comparators, containers that do use them need to implement this interface, as well.

Any class implementing ComparatorBased should provide require that the class be constructed with a Comparator (for example, as a parameter to the constructor), and should not allow the class to be created without one (for example, no zero argument constructor). Any class allowing itself to be constructed without a comparator should throw an InvalidComparatorException from any method that fails because a comparator has not been set.

Author:
Mark Handy (mdh), Mike Boilen (mgb)
See Also:
InvalidComparatorException

Method Summary
 Comparator comparator()
          Returns the Comparator used by this ComparatorBased container.
 Comparator setComparator(Comparator c)
          This method establishes a ContainerInterfaces.Comparator that an ordered container should use to compare its elements.
 

Method Detail

setComparator

public Comparator setComparator(Comparator c)
                         throws NotEmptyContainerException
This method establishes a ContainerInterfaces.Comparator that an ordered container should use to compare its elements. It must be called after a container is instantiated. It should not be called on a non-empty container.
Parameters:
c - A jdsl.core.api.Comparator appropriate to the elements stored by the container
Returns:
The old Comparator
Throws:
NotEmptyContainerException - if the container has elements in it when setComparator(.) is called.

comparator

public Comparator comparator()
Returns the Comparator used by this ComparatorBased container.
Parameters:
c - A jdsl.core.api.Comparator appropriate to the elements stored by the container
Returns:
The old Comparator