net.sf.mmm.util.reflect.impl
Class SimpleGenericTypeImpl<T>

java.lang.Object
  extended by net.sf.mmm.util.reflect.base.AbstractGenericType<T>
      extended by net.sf.mmm.util.reflect.impl.SimpleGenericTypeImpl<T>
Type Parameters:
T - is the templated type of the upper bound.
All Implemented Interfaces:
Type, GenericType<T>

public class SimpleGenericTypeImpl<T>
extends AbstractGenericType<T>

This is an implementation of the GenericType interface for a simple Class.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  GenericType<?> componentType
           
private  GenericType<?> keyType
           
private  Class<T> type
           
static GenericType<?> TYPE_INT
          The GenericType for int.
static GenericType<Object> TYPE_OBJECT
          The GenericType for Object.
static GenericType<?> TYPE_VOID
          The GenericType for void.
 
Fields inherited from interface net.sf.mmm.util.reflect.api.GenericType
NO_TYPES
 
Constructor Summary
SimpleGenericTypeImpl(Class<T> type)
          The constructor.
 
Method Summary
protected  GenericType<?> create(Type genericType)
          This method creates the GenericType that encapsulates the given type.
 Class<T> getAssignmentClass()
          This method gets the Class to be used for assignment (as parameter) of a value of this GenericType.
 GenericType<?> getComponentType()
          This method gets the component-type of this GenericType if it represents an array, Collection or Map.
 GenericType<?> getDefiningType()
          This method gets the defining type.
 GenericType<?> getKeyType()
          This method gets the key-type of this GenericType if it represents a Map.
 Class<T> getRetrievalClass()
          This method gets the Class to be used for retrieval (the return-type) of a value of this GenericType.
 Type getType()
          This method gets the Type represented by this GenericType.
 GenericType<?> getTypeArgument(int index)
          This method gets the type-argument at the given index.
 int getTypeArgumentCount()
          This method gets the number of type-arguments .
 
Methods inherited from class net.sf.mmm.util.reflect.base.AbstractGenericType
equals, getDeclarationIndex, getGenericDeclarations, hashCode, isAssignableFrom, resolveTypeVariable, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_OBJECT

public static final GenericType<Object> TYPE_OBJECT
The GenericType for Object.


TYPE_VOID

public static final GenericType<?> TYPE_VOID
The GenericType for void.


TYPE_INT

public static final GenericType<?> TYPE_INT
The GenericType for int.


type

private final Class<T> type
See Also:
getType()

componentType

private GenericType<?> componentType
See Also:
getComponentType()

keyType

private GenericType<?> keyType
See Also:
getKeyType()
Constructor Detail

SimpleGenericTypeImpl

public SimpleGenericTypeImpl(Class<T> type)
The constructor.

Parameters:
type - is the type to represent.
Method Detail

create

protected GenericType<?> create(Type genericType)
This method creates the GenericType that encapsulates the given type.

Specified by:
create in class AbstractGenericType<T>
Parameters:
genericType - is the Type to get as GenericType.
Returns:
the according GenericType.
See Also:
GenericTypeFactory.createGenericType(Type)

getDefiningType

public GenericType<?> getDefiningType()
This method gets the defining type. This will typically be the Class where the type of this GenericType was retrieved from as parameter, return-type or field-type.

Specified by:
getDefiningType in class AbstractGenericType<T>
Returns:
the defining type or null if NOT available.

getComponentType

public GenericType<?> getComponentType()
This method gets the component-type of this GenericType if it represents an array, Collection or Map.
Here are some examples:
type GenericType.getComponentType()
List<Map<String, Long>> Map<String, Long>
List Object
Foo[] Foo
Foo<Bar>[] Foo<Bar>
Foo<Bar> null
Map<String, Long> Long

Returns:
the component-type of this GenericType or null if this GenericType does NOT represent an array, Collection or Map.

getKeyType

public GenericType<?> getKeyType()
This method gets the key-type of this GenericType if it represents a Map.
Here are some examples:
type GenericType.getComponentType()
List<Map<String, Long>> null
Map Object
Foo[] null
Foo<K,V> null
Map<String, Long> String

Returns:
the key-type of this GenericType or null if this GenericType does NOT represent a Map .

getType

public Type getType()
This method gets the Type represented by this GenericType.

Returns:
the value-type.
See Also:
Class.getGenericSuperclass(), Class.getGenericInterfaces(), Method.getGenericReturnType(), Method.getGenericParameterTypes(), Field.getGenericType(), Constructor.getGenericParameterTypes()

getAssignmentClass

public Class<T> getAssignmentClass()
This method gets the Class to be used for assignment (as parameter) of a value of this GenericType.
It will only differ from the retrieval-class if this GenericType is a WildcardType.
Unlike the lower-bound, the assignment-class is never null. If there is no lower-bound, the assignment-class is the same as the retrieval-class. Therefore the assignment-class is always equal or more specific to the retrieval-class.
Here are some examples:
Type GenericType.getAssignmentClass()
<? super Integer> Integer
<? extends CharSequence> CharSequence
String String

Returns:
the Class that is the lower bound.

getRetrievalClass

public Class<T> getRetrievalClass()
This method gets the Class to be used for retrieval (the return-type) of a value of this GenericType.
It will only differ from the assignment-class if this GenericType is a WildcardType.
The retrieval-class is the upper-bound, however for usability and simplicity only one bound is supported.
Here are some examples:
Type GenericType.getAssignmentClass()
<? super Integer> Object
<? extends CharSequence> CharSequence
String String

Returns:
the Class that is the upper bound.

getTypeArgument

public GenericType<?> getTypeArgument(int index)
This method gets the type-argument at the given index.
E.g. for the GenericType representing Map<String, List<Integer>> this method would return String for an index of 0 and List<Integer> for an index of 1.

Parameters:
index - is the position of the requested type-argument. It has to be in the range from 0 to GenericType.getTypeArgumentCount() - 1.
Returns:
the type-argument at the given index.
See Also:
GenericType.getTypeArgumentCount(), ParameterizedType.getActualTypeArguments()

getTypeArgumentCount

public int getTypeArgumentCount()
This method gets the number of type-arguments .

Returns:
the type-argument count.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.