Back to index

wims  3.65+svn20090927
Static Public Member Functions | Static Private Member Functions
fr.ove.openmath.jome.model.evaluation.Evaluator Class Reference

List of all members.

Static Public Member Functions

static String evaluate (String operand1, String operand2, String anOperator)
static String evaluate (String function, String argument)
static int type (String argument)

Static Private Member Functions

static boolean isNumber (String token)
 Analyzes a token and determines whether it is a number or not.
static String removeBrackets (String token)
 
 

static String cutDecimal (double value)
 
 


Detailed Description

Definition at line 31 of file Evaluator.java.


Member Function Documentation

static String fr.ove.openmath.jome.model.evaluation.Evaluator.cutDecimal ( double  value) [inline, static, private]

 

Definition at line 145 of file Evaluator.java.

                                                   {
        if ((value - Math.floor(value)) < 10e-5)
            return "" + (int) Math.floor(value);
        else
            return "" + value;
    }

Here is the caller graph for this function:

static String fr.ove.openmath.jome.model.evaluation.Evaluator.evaluate ( String  operand1,
String  operand2,
String  anOperator 
) [inline, static]

Definition at line 32 of file Evaluator.java.

                                                                                       {
        String oper1 = removeBrackets(operand1);
        String oper2 = removeBrackets(operand2);
        
        double result;
        
        if (anOperator.equals("+")) {
            if (isNumber(oper1) && isNumber(oper2))
                return cutDecimal((Double.valueOf(oper1)).doubleValue() + (Double.valueOf(oper2)).doubleValue());
            else
                // Si la seconde opérande est un -, alors il ne faudra pas insérer le + entre les 2
                anOperator = (oper2.charAt(0) == '-') ? "" : anOperator;
        }
        else if (anOperator.equals("-")) {
            if (isNumber(oper1) && isNumber(oper2))
                return cutDecimal((Double.valueOf(oper1)).doubleValue() - (Double.valueOf(oper2)).doubleValue());
        }
        else if (anOperator.equals("*")) {
            if (isNumber(oper1) && isNumber(oper2))
                return cutDecimal((Double.valueOf(oper1)).doubleValue() * (Double.valueOf(oper2)).doubleValue());
        }
        else if (anOperator.equals("/")) {
            if (isNumber(oper1) && isNumber(oper2))
                return cutDecimal((Double.valueOf(oper1)).doubleValue() / (Double.valueOf(oper2)).doubleValue());
        }
        else if (anOperator.equals("^")) {
            if (isNumber(oper1) && isNumber(oper2))
                return cutDecimal(Math.pow((Double.valueOf(oper1)).doubleValue(), (Double.valueOf(oper2)).doubleValue()));
        }
            
        return operand1 + anOperator + operand2;
    }

Here is the call graph for this function:

static String fr.ove.openmath.jome.model.evaluation.Evaluator.evaluate ( String  function,
String  argument 
) [inline, static]

Definition at line 65 of file Evaluator.java.

                                                                    {
        function = function.toLowerCase();
        
        argument = removeBrackets(argument);
        
        if (function.equals("sin")) {
            if (isNumber(argument))
                return cutDecimal(Math.sin((Double.valueOf(argument)).doubleValue()));
        }
        if (function.equals("arcsin")) {
            if (isNumber(argument))
                return cutDecimal(Math.asin((Double.valueOf(argument)).doubleValue()));
        }
        if (function.equals("cos")) {
            if (isNumber(argument))
                return cutDecimal(Math.cos((Double.valueOf(argument)).doubleValue()));
        }
        if (function.equals("arccos")) {
            if (isNumber(argument))
                return cutDecimal(Math.acos((Double.valueOf(argument)).doubleValue()));
        }
        if (function.equals("tan")) {
            if (isNumber(argument))
                return cutDecimal(Math.tan((Double.valueOf(argument)).doubleValue()));
        }
        if (function.equals("arctan")) {
            if (isNumber(argument))
                return cutDecimal(Math.atan((Double.valueOf(argument)).doubleValue()));
        }
        if (function.equals("sqrt")) {
            if (isNumber(argument))
                return cutDecimal(Math.sqrt((Double.valueOf(argument)).doubleValue()));
        }
            
        return function + "(" + argument + ")";
    }

Here is the call graph for this function:

static boolean fr.ove.openmath.jome.model.evaluation.Evaluator.isNumber ( String  token) [inline, static, private]

Analyzes a token and determines whether it is a number or not.


Parameters:
tokenthe token to analyze.
Returns:
true if the token is a number. false otherwise.

Definition at line 118 of file Evaluator.java.

                                                  {
        char oneChar;
        
        token = removeBrackets(token);
        
        for (int i = 0; i < token.length(); i++) {
            oneChar = token.charAt(i);
            if (!Character.isDigit(oneChar) && (oneChar != '.'))
                if (!((i == 0) && (oneChar == '-')))
                    return false;
        }
        return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static String fr.ove.openmath.jome.model.evaluation.Evaluator.removeBrackets ( String  token) [inline, static, private]

 

Definition at line 135 of file Evaluator.java.

                                                       {
        if ((token.charAt(0) == '(') && (token.charAt(token.length() - 1) == ')'))
            return token.substring(1, token.length() - 1);
        else
            return token;
    }

Here is the caller graph for this function:

static int fr.ove.openmath.jome.model.evaluation.Evaluator.type ( String  argument) [inline, static]

Definition at line 102 of file Evaluator.java.

                                            {

        argument = removeBrackets(argument);
        
        if (isNumber(argument))
            return 0;
        else
            return 1;
    }

Here is the call graph for this function:


The documentation for this class was generated from the following file: