Skip to content

Commit

Permalink
Fixing the 'if condition' in Java 8. Issue #251
Browse files Browse the repository at this point in the history
  • Loading branch information
itaiag committed Nov 5, 2015
1 parent 99d553f commit 6d1a6f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ self.setValue(result); // the result for the condition
* Parse a given expression, using optional operators array
*/
function parseExpression(expression, optionalOperators){
// This is done for compatability with Java 8
expression = expression.replaceAll(separator,"");
for (var i=0 ; i<optionalOperators.length ; i++){
if (expression.contains(optionalOperators[i])){
var temp = expression.split(optionalOperators[i]);
if (temp.length < 2){
return false;
}

return [temp[0].trim(),temp[1].trim()];
}
}

return false;
}

Expand All @@ -39,7 +40,7 @@ function getComparisonTypeAndRest(expression){
* Evaluate a mathematical comparison expression
*/
function evaluateMath(expression){
var numbers = parseExpression(expression, ['>=','<=','=','!=','<','>']);
var numbers = parseExpression(expression, ['>=','<=','!=','=','<','>']);

if (numbers == false || isNaN(numbers[0]) || isNaN(numbers[1])){
print("Not a mathematical expression: " + expression);
Expand All @@ -49,6 +50,8 @@ function evaluateMath(expression){
numbers[0] = parseFloat(numbers[0]);
numbers[1] = parseFloat(numbers[1]);

// This is done for compatability with Java 8
expression = expression.replaceAll(separator,"");
if (expression.contains(">=")){
return (numbers[0] >= numbers[1]);
}
Expand Down Expand Up @@ -84,6 +87,8 @@ function evaluateString(expression,isCaseSensitive){
numbers[0] = numbers[0].toLowerCase();
numbers[1] = numbers[1].toLowerCase();
}
// This is done for compatability with Java 8
expression = expression.replaceAll(separator,"");
if (expression.contains("NOT_EQUALS")){
return (!numbers[0].equals(numbers[1]));
}
Expand Down
11 changes: 8 additions & 3 deletions jsystem-core-projects/jsystemApp/scripts/ifScriptCondition.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ self.setValue(result); // the result for the condition
* Parse a given expression, using optional operators array
*/
function parseExpression(expression, optionalOperators){
// This is done for compatability with Java 8
expression = expression.replaceAll(separator,"");
for (var i=0 ; i<optionalOperators.length ; i++){
if (expression.contains(optionalOperators[i])){
var temp = expression.split(optionalOperators[i]);
if (temp.length < 2){
return false;
}

return [temp[0].trim(),temp[1].trim()];
}
}

return false;
}

Expand All @@ -39,7 +40,7 @@ function getComparisonTypeAndRest(expression){
* Evaluate a mathematical comparison expression
*/
function evaluateMath(expression){
var numbers = parseExpression(expression, ['>=','<=','=','!=','<','>']);
var numbers = parseExpression(expression, ['>=','<=','!=','=','<','>']);

if (numbers == false || isNaN(numbers[0]) || isNaN(numbers[1])){
print("Not a mathematical expression: " + expression);
Expand All @@ -49,6 +50,8 @@ function evaluateMath(expression){
numbers[0] = parseFloat(numbers[0]);
numbers[1] = parseFloat(numbers[1]);

// This is done for compatability with Java 8
expression = expression.replaceAll(separator,"");
if (expression.contains(">=")){
return (numbers[0] >= numbers[1]);
}
Expand Down Expand Up @@ -84,6 +87,8 @@ function evaluateString(expression,isCaseSensitive){
numbers[0] = numbers[0].toLowerCase();
numbers[1] = numbers[1].toLowerCase();
}
// This is done for compatability with Java 8
expression = expression.replaceAll(separator,"");
if (expression.contains("NOT_EQUALS")){
return (!numbers[0].equals(numbers[1]));
}
Expand Down

0 comments on commit 6d1a6f3

Please sign in to comment.