FileDocCategorySizeDatePackage
ELArithmetic.javaAPI DocGlassfish v2 API14207Fri May 04 22:31:18 BST 2007com.sun.el.lang

ELArithmetic

public abstract class ELArithmetic extends Object
A helper class of Arithmetic defined by the EL Specification
author
Jacob Hookom [jacob@hookom.net]
version
$Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: tcfujii $

Fields Summary
public static final BigDecimalDelegate
BIGDECIMAL
public static final BigIntegerDelegate
BIGINTEGER
public static final DoubleDelegate
DOUBLE
public static final LongDelegate
LONG
private static final Long
ZERO
Constructors Summary
protected ELArithmetic()

        super();
    
Methods Summary
public static final java.lang.Numberadd(java.lang.Object obj0, java.lang.Object obj1)


              
        if (obj0 == null && obj1 == null) {
            return Long.valueOf(0);
        }

        final ELArithmetic delegate;
        if (BIGDECIMAL.matches(obj0, obj1))
            delegate = BIGDECIMAL;
        else if (DOUBLE.matches(obj0, obj1))
            delegate = DOUBLE;
        else if (BIGINTEGER.matches(obj0, obj1))
            delegate = BIGINTEGER;
        else
            delegate = LONG;

        Number num0 = delegate.coerce(obj0);
        Number num1 = delegate.coerce(obj1);

        return delegate.add(num0, num1);
    
protected abstract java.lang.Numberadd(java.lang.Number num0, java.lang.Number num1)

protected abstract java.lang.Numbercoerce(java.lang.Number num)

protected final java.lang.Numbercoerce(java.lang.Object obj)

        
        if (isNumber(obj)) {
            return coerce((Number) obj);
        }
        if (obj instanceof String) {
            return coerce((String) obj);
        }
        if (obj == null || "".equals(obj)) {
            return coerce(ZERO);
        }

        Class objType = obj.getClass();
        if (Character.class.equals(objType) || Character.TYPE == objType) {
            return coerce(Short.valueOf((short) ((Character) obj).charValue()));
        }

        throw new IllegalArgumentException(MessageFactory.get("el.convert", obj,
                objType));
    
protected abstract java.lang.Numbercoerce(java.lang.String str)

protected abstract java.lang.Numberdivide(java.lang.Number num0, java.lang.Number num1)

public static final java.lang.Numberdivide(java.lang.Object obj0, java.lang.Object obj1)

        if (obj0 == null && obj1 == null) {
            return ZERO;
        }

        final ELArithmetic delegate;
        if (BIGDECIMAL.matches(obj0, obj1))
            delegate = BIGDECIMAL;
        else if (BIGINTEGER.matches(obj0, obj1))
            delegate = BIGDECIMAL;
        else
            delegate = DOUBLE;

        Number num0 = delegate.coerce(obj0);
        Number num1 = delegate.coerce(obj1);

        return delegate.divide(num0, num1);
    
public static final booleanisNumber(java.lang.Object obj)

        return (obj != null && isNumberType(obj.getClass()));
    
public static final booleanisNumberType(java.lang.Class type)

        return type == (java.lang.Long.class) || type == Long.TYPE || type == (java.lang.Double.class) || type == Double.TYPE || type == (java.lang.Byte.class) || type == Byte.TYPE || type == (java.lang.Short.class) || type == Short.TYPE || type == (java.lang.Integer.class) || type == Integer.TYPE || type == (java.lang.Float.class) || type == Float.TYPE || type == (java.math.BigInteger.class) || type == (java.math.BigDecimal.class);
    
protected abstract booleanmatches(java.lang.Object obj0, java.lang.Object obj1)

protected abstract java.lang.Numbermod(java.lang.Number num0, java.lang.Number num1)

public static final java.lang.Numbermod(java.lang.Object obj0, java.lang.Object obj1)

        if (obj0 == null && obj1 == null) {
            return Long.valueOf(0);
        }

        final ELArithmetic delegate;
        if (BIGDECIMAL.matches(obj0, obj1))
            delegate = BIGDECIMAL;
        else if (DOUBLE.matches(obj0, obj1))
            delegate = DOUBLE;
        else if (BIGINTEGER.matches(obj0, obj1))
            delegate = BIGINTEGER;
        else
            delegate = LONG;

        Number num0 = delegate.coerce(obj0);
        Number num1 = delegate.coerce(obj1);

        return delegate.mod(num0, num1);
    
protected abstract java.lang.Numbermultiply(java.lang.Number num0, java.lang.Number num1)

public static final java.lang.Numbermultiply(java.lang.Object obj0, java.lang.Object obj1)

        if (obj0 == null && obj1 == null) {
            return Long.valueOf(0);
        }

        final ELArithmetic delegate;
        if (BIGDECIMAL.matches(obj0, obj1))
            delegate = BIGDECIMAL;
        else if (DOUBLE.matches(obj0, obj1))
            delegate = DOUBLE;
        else if (BIGINTEGER.matches(obj0, obj1))
            delegate = BIGINTEGER;
        else
            delegate = LONG;

        Number num0 = delegate.coerce(obj0);
        Number num1 = delegate.coerce(obj1);

        return delegate.multiply(num0, num1);
    
protected abstract java.lang.Numbersubtract(java.lang.Number num0, java.lang.Number num1)

public static final java.lang.Numbersubtract(java.lang.Object obj0, java.lang.Object obj1)

        if (obj0 == null && obj1 == null) {
            return Long.valueOf(0);
        }

        final ELArithmetic delegate;
        if (BIGDECIMAL.matches(obj0, obj1))
            delegate = BIGDECIMAL;
        else if (DOUBLE.matches(obj0, obj1))
            delegate = DOUBLE;
        else if (BIGINTEGER.matches(obj0, obj1))
            delegate = BIGINTEGER;   
        else
            delegate = LONG;

        Number num0 = delegate.coerce(obj0);
        Number num1 = delegate.coerce(obj1);

        return delegate.subtract(num0, num1);