nl.knowledgeplaza.util
Class TypeToken

java.lang.Object
  extended by nl.knowledgeplaza.util.TypeToken

public class TypeToken
extends Object

http://www.jquantlib.org/index.php/Using_TypeTokens_to_retrieve_generic_parameters TypeNode keeps a Class information and a list of children classes.

A typical usage consists on obtain a TypeToken root which can be used to traverse a hierarchy of generic parameters. Each TypeToken holds a Class information and contains a list of children nodes. A typical usage is in the context of retrieving actual generic parameters. The example below shows how a generic class can verify at instantiation time which actual generic parameters where passed by the caller. public class TimeSeries { public TimeSeries() { this.klass = new TypeTokenTree(this.getClass()).getRoot().get(0).getElement(); if (Double.class.isAssignableFrom(klass)) { this.delegate = new SeriesDouble(); } else if (IntervalPrice.class.isAssignableFrom(klass)) { this.delegate = new SeriesIntervalPrice(); } else { throw new UnsupportedOperationException("only Double and IntervalPrice are supported"); } } } Below you can see how the caller code looks like: TimeSeries ts = new TimeSeries() { } Notice that ts is an anonymous class, denoted by { }.

Author:
Richard Gomes
See Also:
Using TypeTokens to retrieve generic parameters, TypeNodeTree

Constructor Summary
TypeToken(Class<?> klass)
           
 
Method Summary
 Iterable<TypeToken> children()
           
 TypeToken get(int index)
           
 Class<?> getElement()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeToken

public TypeToken(Class<?> klass)
Method Detail

getElement

public Class<?> getElement()
Returns:
the contents of this TypeNode

get

public TypeToken get(int index)

children

public Iterable<TypeToken> children()


Copyright © 2011 KnowledgePlaza. All Rights Reserved.