feat: 增加比较器和比较符
parent
37d435c952
commit
b215354046
@ -0,0 +1,54 @@
|
||||
package com.xydl.cac.comparator;
|
||||
|
||||
|
||||
public class FloatCompare extends Comparator {
|
||||
|
||||
private float IgnoreValueN = -0.00001f;
|
||||
private float IgnoreValue = 0.00001f;
|
||||
|
||||
@Override
|
||||
public boolean compare(Object source, String threshold) {
|
||||
if (source != null) {
|
||||
float s1 = (float) source;
|
||||
|
||||
if ("BTW".equalsIgnoreCase(operator)) {
|
||||
String[] strs = threshold.split(",");
|
||||
float t1 = Float.parseFloat(strs[0]);
|
||||
float t3 = Float.parseFloat(strs[1]);
|
||||
if (t1 < s1 && s1 < t3) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
float t2 = Float.parseFloat(threshold);
|
||||
float dif = s1 - t2;
|
||||
|
||||
if ("EQU".equalsIgnoreCase(operator)) {
|
||||
if (IgnoreValueN < dif && dif < IgnoreValue) {
|
||||
return true;
|
||||
}
|
||||
} else if ("NEQ".equalsIgnoreCase(operator)) {
|
||||
if (IgnoreValueN > dif || dif > IgnoreValue) {
|
||||
return true;
|
||||
}
|
||||
} else if ("LSS".equalsIgnoreCase(operator)) {
|
||||
if (IgnoreValueN > dif) {
|
||||
return true;
|
||||
}
|
||||
} else if ("LEQ".equalsIgnoreCase(operator)) {
|
||||
if (IgnoreValue > dif) {
|
||||
return true;
|
||||
}
|
||||
} else if ("GTR".equalsIgnoreCase(operator)) {
|
||||
if (dif > IgnoreValue) {
|
||||
return true;
|
||||
}
|
||||
} else if ("GEQ".equalsIgnoreCase(operator)) {
|
||||
if (dif > IgnoreValueN) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.xydl.cac.comparator;
|
||||
|
||||
|
||||
public class IntCompare extends Comparator {
|
||||
|
||||
@Override
|
||||
public boolean compare(Object source, String threshold) {
|
||||
if (source != null) {
|
||||
int s1 = (int) source;
|
||||
|
||||
if ("BTW".equalsIgnoreCase(operator)) {
|
||||
String[] strs = threshold.split(",");
|
||||
int t1 = Integer.parseInt(strs[0]);
|
||||
int t3 = Integer.parseInt(strs[1]);
|
||||
if (t1 < s1 && s1 < t3) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
int t2 = Integer.parseInt(threshold);
|
||||
|
||||
if ("EQU".equalsIgnoreCase(operator) && s1 == t2) {
|
||||
return true;
|
||||
} else if ("NEQ".equalsIgnoreCase(operator) && s1 != t2) {
|
||||
return true;
|
||||
} else if ("LSS".equalsIgnoreCase(operator) && s1 < t2) {
|
||||
return true;
|
||||
} else if ("LEQ".equalsIgnoreCase(operator) && s1 <= t2) {
|
||||
return true;
|
||||
} else if ("GTR".equalsIgnoreCase(operator) && s1 > t2) {
|
||||
return true;
|
||||
} else if ("GEQ".equalsIgnoreCase(operator) && s1 >= t2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.xydl.cac.task;
|
||||
|
||||
import com.xydl.cac.comparator.FloatCompare;
|
||||
import com.xydl.cac.comparator.IntCompare;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RuleCheckTask {
|
||||
public static FloatCompare floatCompare = new FloatCompare();
|
||||
public static IntCompare intCompare = new IntCompare();
|
||||
}
|
Loading…
Reference in New Issue