for (String operador: operadores)
if (!operador.equals(""))
if (delimiters.contains(operador))
numOperadores++;
else
throw new PatternSyntaxException("the follow delimiter not defined", operador, expresion.indexOf(operador));
// Determino expresi�n
String patternStr = "";
if (delimiters.size() > 1)
for (Object delimiter: delimiters.toArray())
patternStr += "[" + delimiter + "]";
else
patternStr = delimiters.get(0);
// Determino operandos
int numOperandos = 0;
patternStr = "[" + patternStr + "]";
String[] operandos = expresion.split(patternStr);
for (String operando : operandos)
if (!operando.equals("")) numOperandos++;
// Valido la correspondencia entre operandos y operadores (cadena vacia no se procesa)
if ((numOperandos > 0) && (numOperandos - 1 != numOperadores))
throw new PatternSyntaxException("the following input is NOT ok", expresion, 0);
for (String numStr : operandos) {
if (numStr.equals("")) continue;
try {
int num = Integer.parseInt(numStr);
if (num < 0)
throw new PatternSyntaxException("negatives not allowed", expresion, expresion.indexOf(numStr));
else if (num <= 1000) // the numbers bigger than 1000 should be ignored
result += num;
} catch (NumberFormatException ex) {
// On exceptions numStr equal zero