rlgamekit.objects
Class Registry<E>

java.lang.Object
  extended by rlgamekit.objects.Registry<E>

public class Registry<E>
extends java.lang.Object

Since the LayeredMap class can only store integers, but most games need some kind of objects to keep track of item data, this class was introduced to create the association from integers (map data) to some sort of game-defined item data. It can be used more generic, too, for any sort of integer based object lookup. This class uses a Cardinal object internally to keep object allocation for map lookup low.

See Also:
Cardinal, LayeredMap

Constructor Summary
Registry()
          Create a new object registry for type E
 
Method Summary
 void clear()
          Clear the registry from all registered items.
 int findKey(E item)
          Find the key for the item in the registry.
 E get(int keyValue)
          Look up the object bound to keyValue.
 int nextFreeKey()
          Find the next free key in the registry.
 void put(int key, E item)
          Put a new object into the registry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Registry

public Registry()
Create a new object registry for type E

Method Detail

put

public void put(int key,
                E item)
Put a new object into the registry

Parameters:
key - The objects key
item - The object

findKey

public int findKey(E item)
Find the key for the item in the registry. Will do a full table scan.

Parameters:
item - The item to search.
Returns:
0 if not found, the item key otherwise

nextFreeKey

public int nextFreeKey()
Find the next free key in the registry.

Returns:
the next free key.

get

public E get(int keyValue)
Look up the object bound to keyValue.

Parameters:
keyValue - The key value
Returns:
The bound object or null if there is no such object

clear

public void clear()
Clear the registry from all registered items.