org.geworkbench.bison.util
Class DefaultIdentifiable

java.lang.Object
  extended by org.geworkbench.bison.util.DefaultIdentifiable
All Implemented Interfaces:
java.io.Serializable

public class DefaultIdentifiable
extends java.lang.Object
implements java.io.Serializable

This class provides a baseline implementation to be used by objects that implement the Identifiable interface. It is intended to support the needs of multiple collections of objects. For each collection, it guarantees uniqueness of ids as long as (1) the collection has a unique name, (2) objects within the collection request IDs by providing the collection's name, and (3) objects are members of a single collection for the entirety of their lifespan.

See Also:
Serialized Form

Field Summary
protected  java.lang.String id
          Stores a unique id.
protected  java.lang.String name
          Stores a (not necessarily unique) name.
protected static java.util.HashMap usedIds
          Keeps track of ids currently in use.
 
Constructor Summary
DefaultIdentifiable()
          Default constructor
DefaultIdentifiable(java.lang.String someID, java.lang.String collectionName)
          Instantiates using the prescribed id.
DefaultIdentifiable(java.lang.String someID, java.lang.String someName, java.lang.String collectionName)
          Instantiates using the prescribed id and name
 
Method Summary
 void clearID(java.lang.String someId, java.lang.String collectionName)
          Resets the id to null.
 java.lang.String getID()
           
 java.lang.String getLabel()
           
static boolean idExists(java.lang.String someId, java.lang.String collectionName)
          Checks if the someID has already been assigned to an object of the designated named collection.
 void setID(java.lang.String someId, java.lang.String collectionName)
          Sets the id for the current object.
 void setLabel(java.lang.String someName)
          Sets the name of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected java.lang.String id
Stores a unique id.


name

protected java.lang.String name
Stores a (not necessarily unique) name.


usedIds

protected static java.util.HashMap usedIds
Keeps track of ids currently in use. Each key in the map corresponds to a name for a collection of objects. The key is mapped to a value that is a Vector and stores the ids currently in use for that named collection.

NOTE: Serializable implementations of the Identifiable interface that make use of DefaultIdentifiable should explicitly handle the restoration of usedIds.

Constructor Detail

DefaultIdentifiable

public DefaultIdentifiable()
Default constructor


DefaultIdentifiable

public DefaultIdentifiable(java.lang.String someID,
                           java.lang.String collectionName)
Instantiates using the prescribed id.

Parameters:
someID - The ID to use for initialization

DefaultIdentifiable

public DefaultIdentifiable(java.lang.String someID,
                           java.lang.String someName,
                           java.lang.String collectionName)
Instantiates using the prescribed id and name

Parameters:
someID - The ID to use for initialization
someName - The name to use for initialization
Method Detail

idExists

public static boolean idExists(java.lang.String someId,
                               java.lang.String collectionName)
Checks if the someID has already been assigned to an object of the designated named collection.

Parameters:
someId - The id to check.
collectionName - The name of the reference collection.
Returns:
True if the ID exists, false otherwise.

getID

public java.lang.String getID()
Returns:
The ID for this object.

setID

public void setID(java.lang.String someId,
                  java.lang.String collectionName)
Sets the id for the current object.

Parameters:
someId - The id to use.
collectionName - The name of the collection where the object belongs.

getLabel

public java.lang.String getLabel()
Returns:
The 'name' of this object.

setLabel

public void setLabel(java.lang.String someName)
Sets the name of this object.

Parameters:
someName - The name to use.

clearID

public void clearID(java.lang.String someId,
                    java.lang.String collectionName)
Resets the id to null. It may be necessary to manually release the ID of an object that is being serialized if, (1) the object is destroyed after the serialization, and (2) the object can be deserialized in the same working session. If the id does not get so released, then the subsequent attempt to deserialize will find the ID still present in usedIds.

This explicit handling of ID release is unfortunately made necessary due to the latent nature of garbage collection (and the corresponsing latency in calling the finalize() method, which is where the ID release would naturally occur).

Parameters:
someId - The ID to be released.
collectionName - The reference collection name.