|
@@ -1,11 +1,13 @@
|
|
package com.jfireel.expression.node.impl;
|
|
package com.jfireel.expression.node.impl;
|
|
|
|
|
|
|
|
+import com.jfireel.expression.Expression;
|
|
import com.jfireel.expression.token.Operator;
|
|
import com.jfireel.expression.token.Operator;
|
|
import com.jfireel.expression.util.number.SubtractUtil;
|
|
import com.jfireel.expression.util.number.SubtractUtil;
|
|
import com.mixsmart.utils.CustomFunction;
|
|
import com.mixsmart.utils.CustomFunction;
|
|
import com.mixsmart.utils.StringUtils;
|
|
import com.mixsmart.utils.StringUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
public class MinusNode extends OperatorResultNode {
|
|
public class MinusNode extends OperatorResultNode {
|
|
@@ -17,9 +19,12 @@ public class MinusNode extends OperatorResultNode {
|
|
public Object calculate(Map<String, Object> variables) {
|
|
public Object calculate(Map<String, Object> variables) {
|
|
Object leftValue = leftOperand.calculate(variables);
|
|
Object leftValue = leftOperand.calculate(variables);
|
|
Object rightValue = rightOperand.calculate(variables);
|
|
Object rightValue = rightOperand.calculate(variables);
|
|
- String reg = "[0-9.-]+(\\*[0-9.-]+)+";
|
|
|
|
- if (StringUtils.handleNull(leftValue).matches(reg) && StringUtils.handleNull(rightValue).matches(reg)) {
|
|
|
|
|
|
+ String leftStr=StringUtils.handleNull(leftValue);
|
|
|
|
+ String rightStr=StringUtils.handleNull(rightValue);
|
|
|
|
+ if (leftStr.matches(DXD_REG) && rightStr.matches(DXD_REG)) {
|
|
return CustomFunction.dXd(rightValue, leftValue);
|
|
return CustomFunction.dXd(rightValue, leftValue);
|
|
|
|
+ }else if(leftStr.contains(COLON)&&rightStr.contains(COLON)){
|
|
|
|
+ return fraction(leftStr)-fraction(rightStr);
|
|
}
|
|
}
|
|
if (leftValue instanceof String && StringUtils.isNumber(leftValue)) {
|
|
if (leftValue instanceof String && StringUtils.isNumber(leftValue)) {
|
|
leftValue = new BigDecimal(leftValue.toString());
|
|
leftValue = new BigDecimal(leftValue.toString());
|
|
@@ -36,13 +41,17 @@ public class MinusNode extends OperatorResultNode {
|
|
return SubtractUtil.calculate((Number) leftValue, (Number) rightValue);
|
|
return SubtractUtil.calculate((Number) leftValue, (Number) rightValue);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static double fraction(String s){
|
|
|
|
+ String[] arr = s.split(COLON);
|
|
|
|
+ return Double.parseDouble(arr[0])/Double.parseDouble(arr[1]);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
/* public static void main(String[] args) {
|
|
/* public static void main(String[] args) {
|
|
Map<String,Object> map = new HashMap<>();
|
|
Map<String,Object> map = new HashMap<>();
|
|
- map.put("A","1*2");
|
|
|
|
- map.put("B","1*2");
|
|
|
|
- System.out.println(Expression.parse("A*B").calculate(map).toString());
|
|
|
|
|
|
+ map.put("A","1:2.36");
|
|
|
|
+ map.put("B","1:4");
|
|
|
|
+ System.out.println(Expression.parse("A-B").calculate(map).toString());
|
|
}*/
|
|
}*/
|
|
|
|
|
|
// public Object calculateOld(Map<String, Object> variables) {
|
|
// public Object calculateOld(Map<String, Object> variables) {
|