com.emarsys.ecommon.collections
Class BoundedGenericContainer

java.lang.Object
  extended by com.emarsys.ecommon.collections.BoundedGenericContainer

public class BoundedGenericContainer
extends java.lang.Object

BoundedGenericContainer is very similar to GenericContainer with the exception that the getElem(Class) and setElem(Class, Object) methods do not provide 100 % strict type parameter binding. So you are able identify/access an element of the container by a sublclass:
setElem( Class klass, T thing )

Be aware of this:
class D {} class DS extends D {} class DL extends D {}
DS ds = new DS();
DL dl = new DL();
this.container.setElem( ds.getClass(), ds );
this.container.setElem( dl.getClass(), dl );
D dsret = this.container.getElem( ds.getClass() );
D dlret = this.container.getElem( dl.getClass() );

assert( ds == dsret);
assert( ds instanceof DS );
assert( dl == dlret);
assert( dl instanceof DL );

D ds2 = new D();
D dl2 = new D();
this.container.setElem( ds2.getClass(), ds2 );
this.container.setElem( dl2.getClass(), dl2 );
D ds2ret = this.container.getElem( ds2.getClass() );
D dl2ret = this.container.getElem( dl2.getClass() );

assert( ds2ret == dl2ret);

Author:
Michael "kULO" Kulovits
See Also:
GenericContainer

Constructor Summary
BoundedGenericContainer()
           
 
Method Summary
<T> T
getElem(java.lang.Class<? extends T> klass)
           
<T> void
setElem(java.lang.Class<? extends T> klass, T thing)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoundedGenericContainer

public BoundedGenericContainer()
Method Detail

setElem

public <T> void setElem(java.lang.Class<? extends T> klass,
                        T thing)

getElem

public <T> T getElem(java.lang.Class<? extends T> klass)


Copyright © 2010 emarsys AG. All Rights Reserved.