jdsl.core.api
Interface KeyBasedContainer

All Known Subinterfaces:
Dictionary, OrderedDictionary, PriorityQueue

public abstract interface KeyBasedContainer
extends Container

A Container in which each element in its structure is associated with a key. This association is known as a mapping.

KeyBasedContainers may be viewed abstractly as storing pairs of the type, p(k,e) where

Author:
John Kloss, Mike Boilen (mgb)

Method Summary
 void insert(Locator locator)
          Inserts a Locator into this Container.
 Locator insert(java.lang.Object key, java.lang.Object element)
          Inserts a <key, element> pair into this Container.
 java.util.Enumeration keys()
          Returns an enumeration of all of the keys of all the locators in the Container.
 java.util.Enumeration locators()
          Returns an Enumeration of all the Locators within this Container.
 Locator makeLocator(java.lang.Object key, java.lang.Object element)
          For when you need a locator that can be inserted into this KeyBasedContainer but don't want to insert it quite yet.
 void remove(Locator locator)
          Removes an element from this Container.
 java.lang.Object replaceElement(Locator loc, java.lang.Object newElement)
          Takes constant time -- even in key-based containers, since the element can be changed independently of the key.
 java.lang.Object replaceKey(Locator locator, java.lang.Object key)
          Changes the mapping of a Locator's element to a new key.
 
Methods inherited from interface jdsl.core.api.Container
elements, newContainer
 
Methods inherited from interface jdsl.simple.api.SimpleContainer
isEmpty, size
 

Method Detail

insert

public void insert(Locator locator)
            throws InvalidKeyException,
                   InvalidLocatorException,
                   ContainedLocatorException
Inserts a Locator into this Container.
Parameters:
locator - The Locator whose key and element are inserted into this Container.
Throws:
InvalidKeyException - If the key referenced by locator is not a type accepted by this Container. (For instance, if the container's Comparator can't compare the element, or if the container should have a comparator but doesn't.)
InvalidLocatorException - If locator cannot be inserted into this container.

insert

public Locator insert(java.lang.Object key,
                      java.lang.Object element)
               throws InvalidKeyException
Inserts a <key, element> pair into this Container. Here, key is an explicit key. That is, it is mapped to element and used to position element within this Container.
Parameters:
key - The key used to position the element within this Container.
element - The element to be inserted into this Container.
Returns:
A Locator which points to element within this Container.
Throws:
InvalidKeyException - If key is not a type accepted by this Container. (For instance, if the container's Comparator can't compare the element, or if the container should have a comparator but doesn't.)

remove

public void remove(Locator locator)
            throws InvalidLocatorException,
                   UncontainedLocatorException
Removes an element from this Container. This method provides the only guaranteed way of removing a particular element from a KeyBasedContainer. The Container may make no guarantee about the uniqueness of its keys or stored elements. Many elements may be mapped to the same key and vice versa depending upon the particular implementaion.
Parameters:
locator - The Locator which points to a particular element within this Container.
Throws:
InvalidLocatorException - If locator is invalid.
UncontainedLocatorException - If locator is not in a container.

replaceKey

public java.lang.Object replaceKey(Locator locator,
                                   java.lang.Object key)
                            throws InvalidLocatorException,
                                   InvalidKeyException
Changes the mapping of a Locator's element to a new key. That is, within this Container locator's element will now be mapped to key. The original key this element was mapped to is returned Note: this method does not necessarily remove the old key (other elements within this Container may be mapped to it).
Parameters:
locator - The Locator which points to a particular element within this Container.
key - The new key to which locator's element should be mapped.
Returns:
The old key to which locator's element was mapped.
Throws:
InvalidLocatorException - If locator is invalid (For example: It does not actually reference an element in this Container).
InvalidKeyException - If key is not a type accepted by this Container (e.g. If this Container is unable to use key as a key).

replaceElement

public java.lang.Object replaceElement(Locator loc,
                                       java.lang.Object newElement)
                                throws InvalidLocatorException
Takes constant time -- even in key-based containers, since the element can be changed independently of the key.
Parameters:
loc - Locator at which replacement should occur
newElement - Element now to be stored at Locator loc
Returns:
Old element, previously stored at Locator loc

locators

public java.util.Enumeration locators()
Returns an Enumeration of all the Locators within this Container. If this Container is empty then an empty Enumeration is returned.
Returns:
An Enumeration of all the Locators stored in the container. Note: this Enumeration may be empty.

keys

public java.util.Enumeration keys()
Returns an enumeration of all of the keys of all the locators in the Container.
Returns:
An Enumeration of all the keys in this container. Note: this Enumeration may be empty.

makeLocator

public Locator makeLocator(java.lang.Object key,
                           java.lang.Object element)
                    throws InvalidKeyException
For when you need a locator that can be inserted into this KeyBasedContainer but don't want to insert it quite yet.