org.apache.commons.el

Class Coercions


public class Coercions
extends java.lang.Object

This class contains the logic for coercing data types before operators are applied to them.

The following is the list of rules applied for various type conversions.

Version:
$Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: luehe $
Author:
Nathan Abramson - Art Technology Group

Field Summary

private static Number
ZERO

Method Summary

static Object
applyArithmeticOperator(Object pLeft, Object pRight, ArithmeticOperator pOperator, Logger pLogger)
Performs all of the necessary type conversions, then calls on the appropriate operator.
static Object
applyEqualityOperator(Object pLeft, Object pRight, EqualityOperator pOperator, Logger pLogger)
Performs all of the necessary type conversions, then calls on the appropriate operator.
static Object
applyRelationalOperator(Object pLeft, Object pRight, RelationalOperator pOperator, Logger pLogger)
Performs all of the necessary type conversions, then calls on the appropriate operator.
static Object
coerce(Object pValue, Class pClass, Logger pLogger)
Coerces the given value to the specified class.
static Boolean
coerceToBoolean(Object pValue, Logger pLogger)
Coerces a value to a Boolean
static Character
coerceToCharacter(Object pValue, Logger pLogger)
Coerces a value to a Character
static Integer
coerceToInteger(Object pValue, Logger pLogger)
Coerces a value to an Integer, returning null if the coercion isn't possible.
static Object
coerceToObject(Object pValue, Class pClass, Logger pLogger)
Coerces a value to the specified Class that is not covered by any of the above cases
(package private) static Number
coerceToPrimitiveNumber(Number pValue, Class pClass)
Coerces a Number to the given primitive number class
static Number
coerceToPrimitiveNumber(Object pValue, Class pClass, Logger pLogger)
Coerces a value to the given primitive number class
(package private) static Number
coerceToPrimitiveNumber(String pValue, Class pClass)
Coerces a String to the given primitive number class
(package private) static Number
coerceToPrimitiveNumber(double pValue, Class pClass)
Coerces a double to the given primitive number class
(package private) static Number
coerceToPrimitiveNumber(long pValue, Class pClass)
Coerces a long to the given primitive number class
static String
coerceToString(Object pValue, Logger pLogger)
Coerces the specified value to a String
static boolean
isBigDecimal(Object pObject)
Returns true if the given object is BigDecimal.
static boolean
isBigInteger(Object pObject)
Returns true if the given object is BigInteger.
static boolean
isFloatingPointString(Object pObject)
Returns true if the given string might contain a floating point number - i.e., it contains ".", "e", or "E"
static boolean
isFloatingPointType(Class pClass)
Returns true if the given class is of a floating point type
static boolean
isFloatingPointType(Object pObject)
Returns true if the given Object is of a floating point type
static boolean
isIntegerType(Class pClass)
Returns true if the given class is of an integer type
static boolean
isIntegerType(Object pObject)
Returns true if the given Object is of an integer type
(package private) static boolean
isNumberClass(Class pClass)
Returns true if the given class is Byte, Short, Integer, Long, Float, Double, BigInteger, or BigDecimal

Field Details

ZERO

private static final Number ZERO

Method Details

applyArithmeticOperator

public static Object applyArithmeticOperator(Object pLeft,
                                             Object pRight,
                                             ArithmeticOperator pOperator,
                                             Logger pLogger)
            throws ELException
Performs all of the necessary type conversions, then calls on the appropriate operator.

applyEqualityOperator

public static Object applyEqualityOperator(Object pLeft,
                                           Object pRight,
                                           EqualityOperator pOperator,
                                           Logger pLogger)
            throws ELException
Performs all of the necessary type conversions, then calls on the appropriate operator.

applyRelationalOperator

public static Object applyRelationalOperator(Object pLeft,
                                             Object pRight,
                                             RelationalOperator pOperator,
                                             Logger pLogger)
            throws ELException
Performs all of the necessary type conversions, then calls on the appropriate operator.

coerce

public static Object coerce(Object pValue,
                            Class pClass,
                            Logger pLogger)
            throws ELException
Coerces the given value to the specified class.

coerceToBoolean

public static Boolean coerceToBoolean(Object pValue,
                                      Logger pLogger)
            throws ELException
Coerces a value to a Boolean

coerceToCharacter

public static Character coerceToCharacter(Object pValue,
                                          Logger pLogger)
            throws ELException
Coerces a value to a Character

coerceToInteger

public static Integer coerceToInteger(Object pValue,
                                      Logger pLogger)
            throws ELException
Coerces a value to an Integer, returning null if the coercion isn't possible.

coerceToObject

public static Object coerceToObject(Object pValue,
                                    Class pClass,
                                    Logger pLogger)
            throws ELException
Coerces a value to the specified Class that is not covered by any of the above cases

coerceToPrimitiveNumber

(package private) static Number coerceToPrimitiveNumber(Number pValue,
                                                        Class pClass)
            throws ELException
Coerces a Number to the given primitive number class

coerceToPrimitiveNumber

public static Number coerceToPrimitiveNumber(Object pValue,
                                             Class pClass,
                                             Logger pLogger)
            throws ELException
Coerces a value to the given primitive number class

coerceToPrimitiveNumber

(package private) static Number coerceToPrimitiveNumber(String pValue,
                                                        Class pClass)
            throws ELException
Coerces a String to the given primitive number class

coerceToPrimitiveNumber

(package private) static Number coerceToPrimitiveNumber(double pValue,
                                                        Class pClass)
            throws ELException
Coerces a double to the given primitive number class

coerceToPrimitiveNumber

(package private) static Number coerceToPrimitiveNumber(long pValue,
                                                        Class pClass)
            throws ELException
Coerces a long to the given primitive number class

coerceToString

public static String coerceToString(Object pValue,
                                    Logger pLogger)
            throws ELException
Coerces the specified value to a String

isBigDecimal

public static boolean isBigDecimal(Object pObject)
Returns true if the given object is BigDecimal.
Parameters:
pObject - - Object to evaluate
Returns:
- true if the given object is BigDecimal

isBigInteger

public static boolean isBigInteger(Object pObject)
Returns true if the given object is BigInteger.
Parameters:
pObject - - Object to evaluate
Returns:
- true if the given object is BigInteger

isFloatingPointString

public static boolean isFloatingPointString(Object pObject)
Returns true if the given string might contain a floating point number - i.e., it contains ".", "e", or "E"

isFloatingPointType

public static boolean isFloatingPointType(Class pClass)
Returns true if the given class is of a floating point type

isFloatingPointType

public static boolean isFloatingPointType(Object pObject)
Returns true if the given Object is of a floating point type

isIntegerType

public static boolean isIntegerType(Class pClass)
Returns true if the given class is of an integer type

isIntegerType

public static boolean isIntegerType(Object pObject)
Returns true if the given Object is of an integer type

isNumberClass

(package private) static boolean isNumberClass(Class pClass)
Returns true if the given class is Byte, Short, Integer, Long, Float, Double, BigInteger, or BigDecimal

Copyright (c) 2001-2002 - Apache Software Foundation