org.spicefactory.cinnamon.reflect.util
Class ClassMappedRepository<T>

java.lang.Object
  extended by org.spicefactory.cinnamon.reflect.util.ClassMappedRepository<T>

public class ClassMappedRepository<T>
extends Object

Respository for objects that are associated with a certain Java class. This will also take into account subclasses and subinterfaces when retrieving those instances from the repository.

Author:
Jens Halm

Constructor Summary
ClassMappedRepository()
           
 
Method Summary
 void add(Class<?> type, T item)
          Adds the given item and associates it with the given class and all its subclasses or subinterfaces.
 T get(Class<?> type)
          Returns the item associated with the given type.
 Set<T> getAll()
          Returns a Set of all items that were added to this repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassMappedRepository

public ClassMappedRepository()
Method Detail

add

public void add(Class<?> type,
                T item)
Adds the given item and associates it with the given class and all its subclasses or subinterfaces.

Parameters:
type - the type the item should be associated with
item - the item to be added to the repository

get

public T get(Class<?> type)
Returns the item associated with the given type. If there is no direct match the implementation will try all superclasses and all interfaces (in that order) of the given type. It will return null if no matching item is found

Parameters:
type - the type for which the associated item should be retrieved
Returns:
the item associated with the given type or null if no matching item exists

getAll

public Set<T> getAll()
Returns a Set of all items that were added to this repository.

Returns:
all items that were added to this repository.