TUM CCSM Commons

edu.tum.cs.commons.reflect
Class ClassType

java.lang.Object
  extended by edu.tum.cs.commons.reflect.ClassType

public final class ClassType
extends java.lang.Object

This stores the full type of a class, i.e., base type plus required interfaces. Primitive types are internally mapped to their corresponding class, so for example int and Integer are the same class type. This class is immutable.

The list of additional interfaces is kept normalized, such that no interface is in the list if it already implicitly given (either implemented by the base type or by another interface of the list).

Version:
$Rev: 26283 $
Author:
Benjamin Hummel, $Author: juergens $
Rating:
GREEN Hash: 1BFC3AEF643BDF2D85CFF4282483AD06

Constructor Summary
ClassType()
          Creates the most general class type, that is of type Object without any additional interfaces.
ClassType(java.lang.Class<?>... classes)
          Creates a new class type from a list of "normal" class by either using it as the base class or adding it to the interface list.
ClassType(java.lang.Class<?> clazz)
          Creates a new class type from a "normal" class.
 
Method Summary
 boolean equals(java.lang.Object obj)
          
 java.lang.Class<?> getBaseClass()
          Returns the base class for this ClassType.
 UnmodifiableSet<java.lang.Class<?>> getInterfaces()
          Returns all interfaces implemented by this class type in addition to the base class.
 int hashCode()
          Returns a hash code for this instance based on the base class and the additional (normalized) interfaces.
 boolean hasInterfaces()
          Returns whether this ClassType requires the implementation of interfaces in addition to the base class.
 boolean implementsInterface(java.lang.Class<?> requiredInterface)
          Returns whether the provided interface is implemented by this class type.
 boolean isAssignableFrom(ClassType classType)
          Checks if an object of class type classType could be assigned to an object of this class type.
 ClassType merge(ClassType classType)
          Merges the given class type with this type.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassType

public ClassType()
Creates the most general class type, that is of type Object without any additional interfaces.


ClassType

public ClassType(java.lang.Class<?> clazz)
Creates a new class type from a "normal" class.


ClassType

public ClassType(java.lang.Class<?>... classes)
          throws TypesNotMergableException
Creates a new class type from a list of "normal" class by either using it as the base class or adding it to the interface list.

Throws:
TypesNotMergableException - if the provided classes can not be joined.
Method Detail

merge

public ClassType merge(ClassType classType)
                throws TypesNotMergableException
Merges the given class type with this type. This class and the merged in class is not modified in this process, and a newly created instance of the correct type is returned.

Throws:
TypesNotMergableException - if the new type could not be merged in.

getBaseClass

public java.lang.Class<?> getBaseClass()
Returns the base class for this ClassType.


hasInterfaces

public boolean hasInterfaces()
Returns whether this ClassType requires the implementation of interfaces in addition to the base class.


getInterfaces

public UnmodifiableSet<java.lang.Class<?>> getInterfaces()
Returns all interfaces implemented by this class type in addition to the base class. The collection is normalized such that no interface is explicitly given if it is implemented by the base class or a super interface of another interface of the list.


isAssignableFrom

public boolean isAssignableFrom(ClassType classType)
Checks if an object of class type classType could be assigned to an object of this class type.


implementsInterface

public boolean implementsInterface(java.lang.Class<?> requiredInterface)
Returns whether the provided interface is implemented by this class type.


toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code for this instance based on the base class and the additional (normalized) interfaces.

Overrides:
hashCode in class java.lang.Object

TUM CCSM Commons

TUM CCSM Commons - 2.7