prefuse.util
Class TypeLib

java.lang.Object
  extended by prefuse.util.TypeLib

public class TypeLib
extends java.lang.Object

Library routines dealing with Java Class types.

Author:
jeffrey heer

Method Summary
static java.lang.Class<?> getNumericType(java.lang.Class<?> c1, java.lang.Class<?> c2)
          Get a compatible numeric type for two primitive numeric class types.
static java.lang.Class<?> getPrimitiveType(java.lang.Class<?> type)
          Given a numeric (byte, short, int, long, float, or double) class type or associated wrapper class type, return the primitive class type
static java.lang.Class<?> getSharedType(java.lang.Class<?> type1, java.lang.Class<?> type2)
          Get the nearest shared ancestor class of two classes.
static java.lang.Class<?> getSharedType(java.lang.Object o1, java.lang.Object o2)
          Get the nearest shared ancestor class of two objects.
static java.lang.Class<?> getWrapperType(java.lang.Class<?> type)
          Get the wrapper class type for a primitive class type.
static boolean isIntegerType(java.lang.Class<?> type)
          Indicates if a given class type is a primitive integer type (one of byte, short, int, or long).
static boolean isNumericType(java.lang.Class<?> type)
          Indicates if a given class type is a primitive numeric one type (one of byte, short, int, long, float, or double).
static boolean isWrapperInstance(java.lang.Class<?> type, java.lang.Object instance)
          Indicates if an object is an instance of a wrapper class for a given primitive type.
static boolean typeCheck(java.lang.Class<?> type, java.lang.Object instance)
          Check if an object is an instance of a given class, or, if the class is a primitive type, if the Object is an instance of the wrapper class for that primitive (e.g., as Integer is a wrapper for int).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

typeCheck

public static boolean typeCheck(java.lang.Class<?> type,
                                java.lang.Object instance)
Check if an object is an instance of a given class, or, if the class is a primitive type, if the Object is an instance of the wrapper class for that primitive (e.g., as Integer is a wrapper for int).

Parameters:
type - the Class type
instance - the Object instance
Returns:
true if the object is an instance of the given class, or if of the appropriate primitive wrapper type.

getSharedType

public static java.lang.Class<?> getSharedType(java.lang.Object o1,
                                               java.lang.Object o2)
Get the nearest shared ancestor class of two objects. Note: this currently does not compute the actual least common ancestor, but only looks up one level in the inheritance tree and quits if it does not find a match.

Parameters:
o1 - the first object
o2 - the second object
Returns:
the nearest class instance of which both objects are instances

getSharedType

public static java.lang.Class<?> getSharedType(java.lang.Class<?> type1,
                                               java.lang.Class<?> type2)
Get the nearest shared ancestor class of two classes. Note: this currently does not compute the actual least common ancestor, but only looks up one level in the inheritance tree and quits if it does not find a match.

Parameters:
type1 - the first type
type2 - the second type
Returns:
the nearest class instance which is equal to or a superclass of the two class instances

isWrapperInstance

public static boolean isWrapperInstance(java.lang.Class<?> type,
                                        java.lang.Object instance)
Indicates if an object is an instance of a wrapper class for a given primitive type.

Parameters:
type - the primitive Class type
instance - the object to test as wrapper (e.g., as Integer is a wrapper type for int)
Returns:
true if the object is a wrapper instance of the given primitive type

getPrimitiveType

public static java.lang.Class<?> getPrimitiveType(java.lang.Class<?> type)
Given a numeric (byte, short, int, long, float, or double) class type or associated wrapper class type, return the primitive class type

Parameters:
type - the type to look up, must be a numerical type, but can be either primitive or a wrapper.
Returns:
the primitive class type

getWrapperType

public static java.lang.Class<?> getWrapperType(java.lang.Class<?> type)
Get the wrapper class type for a primitive class type.

Parameters:
type - a class type
Returns:
the wrapper class for the input type if it is a primitive class type, otherwise returns the input type

isIntegerType

public static boolean isIntegerType(java.lang.Class<?> type)
Indicates if a given class type is a primitive integer type (one of byte, short, int, or long).

Parameters:
type - the type to check
Returns:
true if it is a primitive numeric type, false otherwise

isNumericType

public static boolean isNumericType(java.lang.Class<?> type)
Indicates if a given class type is a primitive numeric one type (one of byte, short, int, long, float, or double).

Parameters:
type - the type to check
Returns:
true if it is a primitive numeric type, false otherwise

getNumericType

public static java.lang.Class<?> getNumericType(java.lang.Class<?> c1,
                                                java.lang.Class<?> c2)
Get a compatible numeric type for two primitive numeric class types. Any of (byte, short, int) will resolve to int.

Parameters:
c1 - a numeric primitive class type (int, long, float, or double)
c2 - a numeric primitive class type (int, long, float, or double)
Returns:
the compatible numeric type for binary operations involving both types.


Copyright © 2008 Regents of the University of California