net.sf.mmm.util.reflect.base
Class AbstractGenericType<T>

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

public abstract class AbstractGenericType<T>
extends Object
implements GenericType<T>

This is the implementation of the GenericType interface.

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

Field Summary
 
Fields inherited from interface net.sf.mmm.util.reflect.api.GenericType
NO_TYPES
 
Constructor Summary
protected AbstractGenericType()
          The constructor.
 
Method Summary
protected abstract  GenericType<?> create(Type type)
          This method creates the GenericType that encapsulates the given type.
 boolean equals(Object other)
          
protected  int getDeclarationIndex(TypeVariable<?> typeVariable)
          This method gets the declaration-index of the given typeVariable.
abstract  GenericType<?> getDefiningType()
          This method gets the defining type.
protected  List<Type> getGenericDeclarations(Class<?> ancestor, Class<?> descendant)
          This method walks up the Class-hierarchy from descendant up to ancestor and collects the generic super-classes or super-interfaces of ancestor on that hierarchy-path.
 int hashCode()
          
 boolean isAssignableFrom(GenericType<?> subType)
          This method determines if this GenericType is equal to or a super-type of the given subType.
protected  Type resolveTypeVariable(TypeVariable<?> typeVariable, GenericType<?> declaringType)
          This method resolves the given typeVariable in the context of the given declaringType.
 String toString()
          This method gets the string representation of this GenericType.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.mmm.util.reflect.api.GenericType
getAssignmentClass, getComponentType, getKeyType, getRetrievalClass, getType, getTypeArgument, getTypeArgumentCount
 

Constructor Detail

AbstractGenericType

protected AbstractGenericType()
The constructor.

Method Detail

create

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

Parameters:
type - is the Type to get as GenericType.
Returns:
the according GenericType.
See Also:
GenericTypeFactory.createGenericType(Type)

getDefiningType

public abstract 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.

Returns:
the defining type or null if NOT available.

equals

public final boolean equals(Object other)

Overrides:
equals in class Object

hashCode

public final int hashCode()

Overrides:
hashCode in class Object

isAssignableFrom

public boolean isAssignableFrom(GenericType<?> subType)
This method determines if this GenericType is equal to or a super-type of the given subType.
If X.isAssignableFrom(Y) is true, then an instance of Y can be casted to X.
NOTE:
In case of strange and deeply cascaded generic constructs this can be an expensive operation with many recursive invocations.

Specified by:
isAssignableFrom in interface GenericType<T>
Parameters:
subType - is the potential sub-type of this GenericType.
Returns:
true if objects of the type subType can be assigned to this GenericType.
See Also:
Class.isAssignableFrom(Class)

getGenericDeclarations

protected List<Type> getGenericDeclarations(Class<?> ancestor,
                                            Class<?> descendant)
This method walks up the Class-hierarchy from descendant up to ancestor and collects the generic super-classes or super-interfaces of ancestor on that hierarchy-path.
Please note that if ancestor is an interface, the hierarchy may NOT be unique. In such case it will be unspecified which of the possible paths is used.

Parameters:
ancestor - is the super-class or super-interface of descendant.
descendant - is the sub-class or sub-interface of ancestor.
Returns:
the List of the generic super-Types from descendant up to ancestor, where the first element represents the super-Type of descendant and the last element represents the generic declaration of ancestor itself.

getDeclarationIndex

protected int getDeclarationIndex(TypeVariable<?> typeVariable)
This method gets the declaration-index of the given typeVariable.

Parameters:
typeVariable - is the TypeVariable.
Returns:
the index of the given typeVariable in its declaration.

resolveTypeVariable

protected Type resolveTypeVariable(TypeVariable<?> typeVariable,
                                   GenericType<?> declaringType)
This method resolves the given typeVariable in the context of the given declaringType.

Parameters:
typeVariable - is the TypeVariable to resolve.
declaringType - is the GenericType where the given typeVariable occurs or is replaced.
Returns:
the resolved Type or null if the given typeVariable could NOT be resolved (e.g. it was declared in a Class that is NOT assignable from the given declaringType) .

toString

public final String toString()
This method gets the string representation of this GenericType. In case the underlying value-type is a regular Class, this method will return its qualified name otherwise it will return the string representation of the generic type information (e.g. java.util.Map<java.lang.String, java.util.List<java.lang.Integer>>[] ).

Specified by:
toString in interface GenericType<T>
Overrides:
toString in class Object
Returns:
this GenericType as string.


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