chrriis.common
Class ObjectRegistry

java.lang.Object
  extended by chrriis.common.ObjectRegistry

public class ObjectRegistry
extends Object

A convenient class to register objects to an ID.

Author:
Christopher Deckers

Constructor Summary
ObjectRegistry()
          Construct an object registry.
 
Method Summary
 int add(Object o)
          Add an object to the registry.
 void add(Object o, int instanceID)
          Add an object to the registry, specifying its ID, wich throws an exception if the ID is already in use.
 Object get(int instanceID)
          Get an object using its ID.
static ObjectRegistry getInstance()
          Get the default shared instance of a registry.
 int[] getInstanceIDs()
          Get all the instance IDs that are used in this registry.
 void remove(int instanceID)
          Remove an object from the registry using its instance ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectRegistry

public ObjectRegistry()
Construct an object registry.

Method Detail

add

public int add(Object o)
Add an object to the registry.

Parameters:
o - the object to add.
Returns:
an unused instance ID that is strictly greater than 0.

add

public void add(Object o,
                int instanceID)
Add an object to the registry, specifying its ID, wich throws an exception if the ID is already in use.

Parameters:
o - the object to add.
instanceID - the ID to associate the object to.

get

public Object get(int instanceID)
Get an object using its ID.

Returns:
the object, or null.

remove

public void remove(int instanceID)
Remove an object from the registry using its instance ID.

Parameters:
instanceID - the ID of the object to remove.

getInstanceIDs

public int[] getInstanceIDs()
Get all the instance IDs that are used in this registry.

Returns:
the instance IDs.

getInstance

public static ObjectRegistry getInstance()
Get the default shared instance of a registry.