edu.stanford.nlp.util
Class MetaClass

java.lang.Object
  extended by edu.stanford.nlp.util.MetaClass

public class MetaClass
extends Object

A meta class using Java's reflection library. Can be used to create a single instance, or a factory, where each Class from the factory share their constructor parameters.

Author:
Gabor Angeli

Nested Class Summary
static class MetaClass.ClassCreationException
           
static class MetaClass.ClassFactory<Type>
           
static class MetaClass.ConstructorNotFoundException
           
 
Constructor Summary
MetaClass(Class<?> classname)
          Creates a new MetaClass producing objects of the given type
MetaClass(String classname)
          Creates a new MetaClass producing objects of the given type
 
Method Summary
 boolean checkConstructor(Object... params)
           
static MetaClass create(Class<?> clazz)
          Creates a new MetaClass (helper method)
static MetaClass create(String classname)
          Creates a new MetaClass (helper method)
<E> MetaClass.ClassFactory<E>
createFactory(Class<?>... classes)
          Creates a factory for producing instances of this class from a constructor taking the given types as arguments
<E> MetaClass.ClassFactory<E>
createFactory(Object... objects)
          Creates a factory for producing instances of this class from a constructor taking objects of the types given
<E> MetaClass.ClassFactory<E>
createFactory(String... classes)
          Creates a factory for producing instances of this class from a constructor taking the given types as arguments
<E,F extends E>
F
createInstance(Class<E> type, Object... params)
          Creates an instance of the class, forcing a cast to a certain type and given an array of objects as constructor parameters NOTE: the resulting instance will [unlike java] invoke the most narrow constructor rather than the one which matches the signature passed to this function
<E> E
createInstance(Object... objects)
          Create an instance of the class, inferring the type automatically, and given an array of objects as constructor parameters NOTE: the resulting instance will [unlike java] invoke the most narrow constructor rather than the one which matches the signature passed to this function
 boolean equals(Object o)
           
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MetaClass

public MetaClass(String classname)
Creates a new MetaClass producing objects of the given type

Parameters:
classname - The full classname of the objects to create

MetaClass

public MetaClass(Class<?> classname)
Creates a new MetaClass producing objects of the given type

Parameters:
classname - The class to create
Method Detail

createFactory

public <E> MetaClass.ClassFactory<E> createFactory(Class<?>... classes)
Creates a factory for producing instances of this class from a constructor taking the given types as arguments

Type Parameters:
E - The type of the objects to be produced
Parameters:
classes - The types used in the constructor
Returns:
A ClassFactory of the given type

createFactory

public <E> MetaClass.ClassFactory<E> createFactory(String... classes)
Creates a factory for producing instances of this class from a constructor taking the given types as arguments

Type Parameters:
E - The type of the objects to be produced
Parameters:
classes - The types used in the constructor
Returns:
A ClassFactory of the given type

createFactory

public <E> MetaClass.ClassFactory<E> createFactory(Object... objects)
Creates a factory for producing instances of this class from a constructor taking objects of the types given

Type Parameters:
E - The type of the objects to be produced
Parameters:
objects - Instances of the types used in the constructor
Returns:
A ClassFactory of the given type

createInstance

public <E> E createInstance(Object... objects)
Create an instance of the class, inferring the type automatically, and given an array of objects as constructor parameters NOTE: the resulting instance will [unlike java] invoke the most narrow constructor rather than the one which matches the signature passed to this function

Type Parameters:
E - The type of the object returned
Parameters:
objects - The arguments to the constructor of the class
Returns:
An instance of the class

createInstance

public <E,F extends E> F createInstance(Class<E> type,
                                        Object... params)
Creates an instance of the class, forcing a cast to a certain type and given an array of objects as constructor parameters NOTE: the resulting instance will [unlike java] invoke the most narrow constructor rather than the one which matches the signature passed to this function

Type Parameters:
E - The type of the object returned
Parameters:
type - The class of the object returned
params - The arguments to the constructor of the class
Returns:
An instance of the class

checkConstructor

public boolean checkConstructor(Object... params)

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

create

public static MetaClass create(String classname)
Creates a new MetaClass (helper method)

Parameters:
classname - The name of the class to create
Returns:
A new MetaClass object of the given class

create

public static MetaClass create(Class<?> clazz)
Creates a new MetaClass (helper method)

Parameters:
clazz - The class to create
Returns:
A new MetaClass object of the given class


Stanford NLP Group