Package ariba.util.core

Examples of ariba.util.core.ArithmeticOperations


                             !(info instanceof NullTypeInfo)) {
                        // if any of the operands is non-numeric type, then
                        // look for the return type of the arithmetic operations
                        String operandType = getTypeName(operandTypeInfo);
                        String infoType = getTypeName(info);
                        ArithmeticOperations op =
                            getArithmeticOperations(node, operandType, infoType);
                        if (op != null) {
                            Class operandTypeClass = ClassUtil.classForName(operandType, false);
                            Class infoTypeClass = ClassUtil.classForName(infoType, false);
                            if (operandTypeClass != null && infoTypeClass != null) {
View Full Code Here


        operations when the actual operation happens in ExprOps.
    */
    private ArithmeticOperations getArithmeticOperations (
            Node node, String type1, String type2)
    {
        ArithmeticOperations result = null;
        if (node instanceof ASTAdd ||
            node instanceof ASTSubtract) {
            result = ExprOps.getArithmeticOperations(type1, type2);        
        }
        else if (node instanceof ASTMultiply) {
View Full Code Here

                case BIGDEC:
                    result = bigDecValue(v1).compareTo(bigDecValue(v2));
                    break;

                case CUSTOMNUMERICTYPE:
                    ArithmeticOperations operations = (t1 > t2) ?
                            getArithmeticOperations(v1)
                            : getArithmeticOperations(v2);
                    result = operations.compare(v1, v2);
                    break;

                case NONNUMERIC:
                    if ((t1 == NONNUMERIC || v1 == null) &&
                        (t2 == NONNUMERIC || v2 == null)) {
View Full Code Here

            case DOUBLE:    return newReal( type, doubleValue(v1) + doubleValue(v2) );
            case NONNUMERIC:
            {
                // if this is modified, please modify the getArithmeticOperations
                // in TypeChecker as well
                ArithmeticOperations ops = getArithmeticOperations(v1Type, v2Type);
                if (ops != null) {
                    return ops.add(v1, v2);
                }

                // Now the operands are not numeric and they do not support
                // ArithmeticOperations.  The addition becomes concatenation.
                return concatenate(v1, v2);
            }
            case CUSTOMNUMERICTYPE:
                ArithmeticOperations operations =
                        getArithmeticOperations(v1Type, v2Type);
                return operations.add(v1, v2);
            default:
                return newInteger( type, longValue(v1) + longValue(v2) );
          }
    }
View Full Code Here

            case FLOAT:
            case DOUBLE:    return newReal( type, doubleValue(v1) - doubleValue(v2) );
            case NONNUMERIC :
                // if this is modified, please modify the getArithmeticOperations
                // in TypeChecker as well
                ArithmeticOperations ops = getArithmeticOperations(v1Type, v2Type);
                if (ops != null) {
                    return ops.substract(v1, v2);
                }
                return newReal( type, doubleValue(v1) - doubleValue(v2) );
            case CUSTOMNUMERICTYPE:
                ArithmeticOperations operations =
                        getArithmeticOperations(v1Type, v2Type);
                return operations.substract(v1, v2);
            default:
                return newInteger( type, longValue(v1) - longValue(v2) );
        }
    }
View Full Code Here

            Object v2,
            String v1Type,
            String v2Type)
    {
        int type = getNumericType(v1, v2, v1Type, v2Type, true);
        ArithmeticOperations ops;
        switch ( type )
        {
            case BIGINT:    return bigIntValue(v1).multiply(bigIntValue(v2));
            case BIGDEC:    return bigDecValue(v1).multiply(bigDecValue(v2));
            case FLOAT:
            case DOUBLE:    return newReal(type, doubleValue(v1) * doubleValue(v2));
            case NONNUMERIC:
                // if this is modified, please modify the getArithmeticOperations
                // in TypeChecker as well
                ops = getArithmeticOperations(v1Type);
                if (ops != null) {
                    return ops.multiply(v1, bigDecValue(v2));
                }
                else {
                    ops = getArithmeticOperations(v2Type);
                    if (ops != null) {
                        return ops.multiply(v2, bigDecValue(v1));
                    }
                }
                return newReal(type, doubleValue(v1) * doubleValue(v2));
            case CUSTOMNUMERICTYPE:
                int t1 = getNumericType(v1), t2 = getNumericType(v2);
                ops = getArithmeticOperations(v1Type, v2Type);
                if (t1 > t2) {
                    return ops.multiply(v1, bigDecValue(v2));
                }
                else if (t2 > t1) {
                    return ops.multiply(v2, bigDecValue(v1));
                }
                // otherwise let the default case handle it
            default :
                return newInteger(type, longValue(v1) * longValue(v2));
        }
View Full Code Here

            Object v1,
            Object v2,
            String v1Type)
    {
        int type = getNumericType(v1, v2, v1Type, null, true);
        ArithmeticOperations ops;
        switch ( type )
        {
            case BIGINT:
                return bigIntValue(v1).divide(bigIntValue(v2));
            case BIGDEC:
                return bigDecValue(v1).divide(bigDecValue(v2),
                        BigDecimal.ROUND_HALF_EVEN);
            case FLOAT:
            case DOUBLE:
                return newReal(type, doubleValue(v1) / doubleValue(v2));
            case NONNUMERIC :
                // if this is modified, please modify the getArithmeticOperations
                // in TypeChecker as well
                ops = getArithmeticOperations(v1Type);
                if (ops != null) {
                    return ops.divide(v1, v2);
                }
                return newReal(type, doubleValue(v1) / doubleValue(v2));
            case CUSTOMNUMERICTYPE:
                // support money/BigDecimal and
                // money/money as in getting percentage
                ops = getArithmeticOperations(v1Type);
                return ops.divide(v1, v2);
            default :
                return newInteger(type, longValue(v1) / longValue(v2));
        }
    }
View Full Code Here

        <code>obj1</code> and <code>obj2</code>.
    */
    private static ArithmeticOperations getArithmeticOperations (
        Object obj1, Object obj2)
    {
        ArithmeticOperations op1 = getArithmeticOperations(obj1);
        ArithmeticOperations op2 = getArithmeticOperations(obj2);
        return getArithmeticOperationsInternal(op1, op2);
    }
View Full Code Here

        <code>obj</code>.  If there is no {@link ArithmeticOperations}
        for the given <code>obj</code>, <code>null</code> is returned.
    */
    private static ArithmeticOperations getArithmeticOperations (Object obj)
    {
        ArithmeticOperations op = null;
        if (obj != null) {
            op = ArithmeticOperations.get(obj);
        }
        return op;
    }
View Full Code Here

        @aribaapi private
    */
    public static ArithmeticOperations getArithmeticOperations (
            String type1, String type2)
    {
        ArithmeticOperations op1 = getArithmeticOperations(type1);
        ArithmeticOperations op2 = getArithmeticOperations(type2);
        return getArithmeticOperationsInternal(op1, op2);
    }
View Full Code Here

TOP

Related Classes of ariba.util.core.ArithmeticOperations

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.