aim4.util
Class HashMapRegistry<T>

java.lang.Object
  extended by aim4.util.HashMapRegistry<T>
Type Parameters:
T - the type of the object
All Implemented Interfaces:
Registry<T>

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

A registry based on HashMap


Constructor Summary
HashMapRegistry()
          Create a hashmap-based registry
HashMapRegistry(int initId)
          Create a hashmap-based 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

HashMapRegistry

public HashMapRegistry()
Create a hashmap-based registry


HashMapRegistry

public HashMapRegistry(int initId)
Create a hashmap-based 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.