aim4.util
Class WeakRefRegistry<T>

java.lang.Object
  extended by aim4.util.WeakRefRegistry<T>
All Implemented Interfaces:
Registry<T>

public class WeakRefRegistry<T>
extends Object
implements Registry<T>

A registry based on weak references.


Constructor Summary
WeakRefRegistry()
          Create a weak reference registry.
WeakRefRegistry(int initId)
          Create a weak reference registry.
 
Method Summary
 T get(int id)
          Retrieve an object from the registry.
 int getNewId()
          Get a new unused ID.
 boolean isIdExist(int id)
          Whether or not an object is in the registry.
 int register(T obj)
          Register an object.
 void set(int id, T obj)
          Associate an object to a given ID.
 void setNull(int id)
          Remove the object associated with a given ID from the registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeakRefRegistry

public WeakRefRegistry()
Create a weak reference registry.


WeakRefRegistry

public WeakRefRegistry(int initId)
Create a weak reference registry.

Parameters:
initId - the initial ID
Method Detail

register

public int register(T obj)
Description copied from interface: Registry
Register an object.

Specified by:
register in interface Registry<T>
Parameters:
obj - the object
Returns:
the ID of the object

isIdExist

public boolean isIdExist(int id)
Description copied from interface: Registry
Whether or not an object is in the registry.

Specified by:
isIdExist in interface Registry<T>
Parameters:
id - the ID of the object
Returns:
Whether or not an object is in the registry

get

public T get(int id)
Description copied from interface: Registry
Retrieve an object from the registry.

Specified by:
get in interface Registry<T>
Parameters:
id - the ID of the object
Returns:
the object

getNewId

public int getNewId()
Description copied from interface: Registry
Get a new unused ID.

Specified by:
getNewId in interface Registry<T>
Returns:
a new unused ID

set

public void set(int id,
                T obj)
Description copied from interface: Registry
Associate an object to a given ID.

Specified by:
set in interface Registry<T>
Parameters:
id - the ID
obj - the object

setNull

public void setNull(int id)
Description copied from interface: Registry
Remove the object associated with a given ID from the registry.

Specified by:
setNull in interface Registry<T>
Parameters:
id - the ID


Copyright © 2011. All Rights Reserved.