FileDocCategorySizeDatePackage
BasicTypeHelperImpl.javaAPI DocGlassfish v2 API15378Tue May 22 16:54:34 BST 2007oracle.toplink.essentials.internal.helper

BasicTypeHelperImpl

public class BasicTypeHelperImpl extends Object
INTERNAL This class is a helper class providing type information. Its implementation uses Java reflection to calculate the type information.

Fields Summary
private static Set
integralTypes
Set of intergral types and its wrapper classes.
private static Set
floatingPointTypes
Set of floating point types and its wrapper classes.
private static Set
dateClasses
Set of date classes.
private static Map
primitiveToWrapper
Maps primtives types to their wrapper classes.
private static Map
wrapperToPrimitive
Maps wrapper classes to their primitive types.
private static final BasicTypeHelperImpl
singleton
A singleton for this class
Constructors Summary
Methods Summary
protected java.lang.ObjectbinaryNumericPromotion(java.lang.Object left, java.lang.Object right)
Implements binary numeric promotion as defined in JLS.

        if ((left == null) || (right == null)) {
            return null;
        }
        Object type = null;
        
        if (left == getDoubleType() || right == getDoubleType()) {
            type = getDoubleType();
        } else if (left == getFloatType() || right == getFloatType()) {
            type = getFloatType();
        } else if (left == getLongType() || right == getLongType()) {
            type = getLongType();
        } else if (isIntegralType(left) && isIntegralType(right)) {
            type = getIntType();
        }
        return type;
    
public java.lang.ObjectextendedBinaryNumericPromotion(java.lang.Object left, java.lang.Object right)
Implements binary numeric promotion as defined in JLS extended by wrapper classes, BigDecimal and BigInteger.

        if ((left == null) || (right == null) || 
            !isNumericType(left) || !isNumericType(right)) {
            return null;
        }

        // handle BigDecimal
        if (isBigDecimalType(left) || isBigDecimalType(right)) {
            return getBigDecimalType();
        }
        
        // handle BigInteger
        if (isBigIntegerType(left)) {
            return isFloatingPointType(right) ? right : getBigIntegerType();
        }
        if (isBigIntegerType(right)) {
            return isFloatingPointType(left) ? left : getBigIntegerType();
        }

        // check wrapper classes
        boolean wrapper = false;
        if (isWrapperClass(left)) {
            wrapper = true;
            left = getPrimitiveType(left);
        }
        if (isWrapperClass(right)) {
            wrapper = true;
            right = getPrimitiveType(right);
        }
        
        Object promoted = binaryNumericPromotion(left, right);
        if (wrapper && promoted != null) {
            promoted = getWrapperClass(promoted);
        }
        return promoted;
    
public java.lang.ObjectgetBigDecimalType()
Returns the BigDecimal type representation.

        return BigDecimal.class;
    
public java.lang.ObjectgetBigIntegerType()
Returns the BigInteger type representation.

        return BigInteger.class;
    
public java.lang.ObjectgetBooleanClassType()
Returns the Boolean class representation.

        return Boolean.class;
    
public java.lang.ObjectgetBooleanType()
Returns the boolean type representation.

        return boolean.class;
    
public java.lang.ObjectgetByteClassType()
Returns the Byte class representation.

        return Byte.class;
    
public java.lang.ObjectgetByteType()
Returns the byte type representation.

        return byte.class;
    
public java.lang.ObjectgetCharType()
Returns the char type representation.

        return char.class;
    
public java.lang.ObjectgetCharacterClassType()
Returns the Character class representation.

        return Character.class;
    
public java.lang.ObjectgetDateType()
Returns the java.util.Date type representation.

        return Date.class;
    
public java.lang.ObjectgetDoubleClassType()
Returns the type representation of class Double.

        return Double.class;
    
public java.lang.ObjectgetDoubleType()
Returns the double type representation.

        return double.class;
    
public java.lang.ObjectgetFloatClassType()
Returns the type representation of class Float.

        return Float.class;
    
public java.lang.ObjectgetFloatType()
Returns the float type representation.

        return float.class;
    
public static oracle.toplink.essentials.internal.helper.BasicTypeHelperImplgetInstance()
Gets instance of this class


          
        
        return singleton;
    
public java.lang.ObjectgetIntType()
Returns the int type representation.

        return int.class;
    
public java.lang.ObjectgetIntegerClassType()
Returns the Inter class representation.

        return Integer.class;
    
public java.lang.ClassgetJavaClass(java.lang.Object type)
Returns the class object of the specified type.

        Class clazz = null;
        if (type instanceof Class) {
            clazz = (Class)type;
        } else if (type instanceof ClassDescriptor) {
            clazz = ((ClassDescriptor)type).getJavaClass();
        }
        return clazz;
    
public java.lang.ObjectgetLongClassType()
Returns the type representation of class Long.

        return Long.class;
    
public java.lang.ObjectgetLongType()
Returns the long type representation.

        return long.class;
    
public java.lang.ObjectgetObjectType()
Returns the Object type representation.

        return Object.class;
    
protected java.lang.ObjectgetPrimitiveType(java.lang.Object wrapper)
Returns the primitive for the specified wrapper class.

        return wrapperToPrimitive.get(wrapper);
    
public java.lang.ObjectgetShortClassType()
Returns the Short class representation.

        return Short.class;
    
public java.lang.ObjectgetShortType()
Returns the short type representation.

        return short.class;
    
public java.lang.ObjectgetStringType()
Returns the String type representation.

        return String.class;
    
public java.lang.StringgetTypeName(java.lang.Object type)
Returns the name of the specified type.

        Class clazz = getJavaClass(type);
        return (clazz == null) ? null : clazz.getName();
    
protected java.lang.ObjectgetWrapperClass(java.lang.Object primitive)
Returns the wrapper class for the specified primitive.

        return primitiveToWrapper.get(primitive);
    
public booleanisAssignableFrom(java.lang.Object left, java.lang.Object right)

        if ((left == null) || (right == null)) {
            return false;
        }
        // chec for identical types
        if (left == right) {
            return true;
        }
        // numeric types are compatible
        Object promoted = extendedBinaryNumericPromotion(left, right);
        if (promoted != null) {
            return true;
        }
        // date types are compatible
        if (isDateClass(left) && isDateClass(right))  {
            return true;
        }
        // handle boolean and Boolean
        if (isBooleanType(left) && isBooleanType(right)) {
            return true;
        }
        // check for inheritance and implements
        return getJavaClass(left).isAssignableFrom(getJavaClass(right));
    
public booleanisBigDecimalType(java.lang.Object type)

        return type == getBigDecimalType();
    
public booleanisBigIntegerType(java.lang.Object type)

        return type == getBigIntegerType();
    
public booleanisBooleanType(java.lang.Object type)
Returns true if type is the boolean primitive type or the Boolean wrapper class

        return (type == getBooleanType()) || (type == getBooleanClassType());
    
public booleanisByteType(java.lang.Object type)
Returns true if type is the byte primitive type or the Byte wrapper class

        return (type == getByteType()) || (type == getByteClassType());
    
public booleanisCharacterType(java.lang.Object type)
Returns true if type is the char primitive type or the Character wrapper class

        return (type == getCharType()) || (type == getCharacterClassType());
    
public booleanisDateClass(java.lang.Object type)

        return dateClasses.contains(type);
    
public booleanisDoubleType(java.lang.Object type)
Returns true if type is the double primitive type or the Double wrapper class

        return (type == getDoubleType()) || (type == getDoubleClassType());
    
public booleanisEnumType(java.lang.Object type)

        Class clazz = getJavaClass(type);
        return (clazz != null) && (clazz.isEnum());
    
public booleanisFloatType(java.lang.Object type)
Returns true if type is the float primitive type or the Float wrapper class

        return (type == getFloatType()) || (type == getFloatClassType());
    
public booleanisFloatingPointType(java.lang.Object type)
Returns true if the specified type represents an floating point type or a wrapper class of an floating point type.

        return floatingPointTypes.contains(type);
    
public booleanisIntType(java.lang.Object type)
Returns true if type is the int primitive type or the Integer wrapper class

        return (type == getIntType()) || (type == getIntegerClassType());
    
public booleanisIntegralType(java.lang.Object type)
Returns true if the specified type represents an integral type or a wrapper class of an integral type.

        return integralTypes.contains(type);
    
public booleanisLongType(java.lang.Object type)
Returns true if type is the long primitive type or the Long wrapper class

        return (type == getLongType()) || (type == getLongClassType());
    
public booleanisNumericType(java.lang.Object type)

        return isIntegralType(type) || isFloatingPointType(type) ||
            isBigIntegerType(type) || isBigDecimalType(type);
    
public booleanisOrderableType(java.lang.Object type)
Returns true if the specified type denotes an orable type

        return isNumericType(type) || isStringType(type) || 
            isDateClass(type) || isEnumType(type);
    
public booleanisShortType(java.lang.Object type)
Returns true if type is the short primitive type or the Short wrapper class

        return (type == getShortType()) || (type == getShortClassType());
    
public booleanisStringType(java.lang.Object type)
Returns true if the specified type represents java.lang.String.

        return type == getStringType();
    
public booleanisWrapperClass(java.lang.Object type)
Returns true if the specified type is a wrapper class.

        return wrapperToPrimitive.containsKey(type);