util
Class TranslatorEngine

java.lang.Object
  |
  +--util.TranslatorEngine
All Implemented Interfaces:
Serializable

public class TranslatorEngine
extends Object
implements Serializable

A basic Translator engine to be used in translator agent

See Also:
TranslatorAgent, Serialized Form

Field Summary
protected  Map names
          this map maps name ==> thing(s)
protected  Hashtable things
          this hashtable maps thing ==> name(s)
 
Constructor Summary
TranslatorEngine(Map names)
           
 
Method Summary
 boolean addName(Serializable thing, Serializable name)
          Allows you to add a name to a thing
 boolean addNames(Serializable thing, Collection names)
          A convenience method -- allows you to add several names at once
 boolean forgetAll()
          Tells the resolver to forget all of the name-thing bindings
 Collection getAllNames()
          Returns all names of all things registered with this agent
 Collection getAllNames(Serializable thing)
          Finds all names for the thing.
 Collection getAllNamesForThings(Collection things)
          Get all the names for all the things passed in as the argument
 Collection getAllThings()
          Returns all things registered with this agent
protected  Hashtable getNameSet(Collection stuff)
          Given a collection of stuff, this method will return a Hashtable that has things from the collection set as keys (with any non-null values)
 Serializable getUniqueName(Serializable thing)
          Get the unique name for the thing in the scope of this agent (all other things registered with this agent will be considered.
 Serializable getUniqueName(Serializable thing, Collection context)
          Find a unique name that distinguishes thing from stuff passed in the collection
protected  Serializable getUniqueName(Serializable thing, Map context)
          The method that really does the job of finding a unique name
 boolean removeName(Serializable thing, Serializable name)
          Remove a name from the list of names for the thing
 boolean removeThing(Serializable thing)
          Remove all names for the thing
 Collection resolveName(Serializable name)
          Returns all things associated with the name
protected  void setUpLookup()
          Set up all data structures for reverse lookups, etc.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

names

protected Map names
this map maps name ==> thing(s)

things

protected Hashtable things
this hashtable maps thing ==> name(s)
Constructor Detail

TranslatorEngine

public TranslatorEngine(Map names)
Method Detail

setUpLookup

protected void setUpLookup()
Set up all data structures for reverse lookups, etc.

addName

public boolean addName(Serializable thing,
                       Serializable name)
Allows you to add a name to a thing
Returns:
true by default, false if something went terribly wrong

addNames

public boolean addNames(Serializable thing,
                        Collection names)
A convenience method -- allows you to add several names at once
Returns:
true if things went well, false if anything went wrong

removeName

public boolean removeName(Serializable thing,
                          Serializable name)
Remove a name from the list of names for the thing
Returns:
true if the name was removed, false if the name was not there or some other problem occured

getUniqueName

public Serializable getUniqueName(Serializable thing)
Get the unique name for the thing in the scope of this agent (all other things registered with this agent will be considered.
Returns:
the unique name or null if no unique name was found for the thing

getUniqueName

public Serializable getUniqueName(Serializable thing,
                                  Collection context)
Find a unique name that distinguishes thing from stuff passed in the collection
Returns:
returns a unique name (there may be more than one) or null if none could be found

getUniqueName

protected Serializable getUniqueName(Serializable thing,
                                     Map context)
The method that really does the job of finding a unique name

getNameSet

protected Hashtable getNameSet(Collection stuff)
Given a collection of stuff, this method will return a Hashtable that has things from the collection set as keys (with any non-null values)

getAllNames

public Collection getAllNames(Serializable thing)
Finds all names for the thing.
Returns:
will return an Empty list if no names were found (never null)

getAllNamesForThings

public Collection getAllNamesForThings(Collection things)
Get all the names for all the things passed in as the argument
Returns:
will return an Empty list if no names were found (never null)

removeThing

public boolean removeThing(Serializable thing)
Remove all names for the thing
Returns:
true of all went well, false if the thing was not found or other trouble happened

resolveName

public Collection resolveName(Serializable name)
Returns all things associated with the name
Returns:
will return an Empty list if no names were found (never null)

forgetAll

public boolean forgetAll()
Tells the resolver to forget all of the name-thing bindings
Returns:
true; false if there is trouble or the process is abandoned (I will probably pop up a window to ask for confirmation so user can change his/her mind)

getAllNames

public Collection getAllNames()
Returns all names of all things registered with this agent

getAllThings

public Collection getAllThings()
Returns all things registered with this agent

toString

public String toString()
Overrides:
toString in class Object