Skip to content

Commit d4d8c3e

Browse files
committed
fix
1 parent 389e850 commit d4d8c3e

File tree

2 files changed

+75
-46
lines changed

2 files changed

+75
-46
lines changed

java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/MathVisitor.java

Lines changed: 75 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
import java.util.regex.Pattern;
2828

2929
public class MathVisitor extends AbstractParseTreeVisitor<Operand> implements mathVisitor<Operand> {
30-
private static final Pattern sumifRegex = Pattern.compile("(<|<=|>|>=|=|==|===|!=|!==|<>) *([-+]?\\d+(\\.(\\d+)?)?)");
30+
private static final Pattern sumifRegex = Pattern
31+
.compile("(<|<=|>|>=|=|==|===|!=|!==|<>) *([-+]?\\d+(\\.(\\d+)?)?)");
3132
private static final Pattern bit_2 = Pattern.compile("^[01]+");
3233
private static final Pattern bit_8 = Pattern.compile("^[0-8]+");
3334
private static final Pattern bit_16 = Pattern.compile("^[0-9a-fA-F]+");
@@ -146,7 +147,8 @@ public Operand visitMulDiv_fun(final MulDiv_funContext context) {
146147
if (secondValue.NumberValue().compareTo(new BigDecimal(0)) == 0) {
147148
return Operand.Error("Div 0 is error!");
148149
}
149-
return Operand.Create(firstValue.NumberValue().divideAndRemainder(secondValue.NumberValue(), MathContext.DECIMAL32)[1]);
150+
return Operand.Create(
151+
firstValue.NumberValue().divideAndRemainder(secondValue.NumberValue(), MathContext.DECIMAL32)[1]);
150152
}
151153
return Operand.Error("Function '" + t + "' parameter is error!");
152154
}
@@ -314,7 +316,8 @@ public Operand visitJudge_fun(final Judge_funContext context) {
314316
if (secondValue.IsError()) {
315317
return secondValue;
316318
}
317-
r = firstValue.NumberValue().setScale(12, RoundingMode.HALF_UP).compareTo(secondValue.NumberValue().setScale(12, RoundingMode.HALF_UP));
319+
r = firstValue.NumberValue().setScale(12, RoundingMode.HALF_UP)
320+
.compareTo(secondValue.NumberValue().setScale(12, RoundingMode.HALF_UP));
318321
}
319322
} else if ((firstValue.Type() == OperandType.DATE && secondValue.Type() == OperandType.TEXT)
320323
|| (secondValue.Type() == OperandType.DATE && firstValue.Type() == OperandType.TEXT)
@@ -355,7 +358,8 @@ public Operand visitJudge_fun(final Judge_funContext context) {
355358
if (secondValue.IsError()) {
356359
return secondValue;
357360
}
358-
r = firstValue.NumberValue().setScale(12, RoundingMode.HALF_UP).compareTo(secondValue.NumberValue().setScale(12, RoundingMode.HALF_UP));
361+
r = firstValue.NumberValue().setScale(12, RoundingMode.HALF_UP)
362+
.compareTo(secondValue.NumberValue().setScale(12, RoundingMode.HALF_UP));
359363
}
360364
if (CharUtil.Equals(type, "<")) {
361365
return Operand.Create(r == -1);
@@ -619,7 +623,8 @@ public Operand visitQUOTIENT_fun(final QUOTIENT_funContext context) {
619623
if (secondValue.NumberValue().compareTo(new BigDecimal(0)) == 0) {
620624
return Operand.Error("Function QUOTIENT div 0 error!");
621625
}
622-
return Operand.Create((double) (int) (firstValue.NumberValue().doubleValue() / secondValue.NumberValue().doubleValue()));
626+
return Operand.Create(
627+
(double) (int) (firstValue.NumberValue().doubleValue() / secondValue.NumberValue().doubleValue()));
623628
}
624629

625630
public Operand visitMOD_fun(final MOD_funContext context) {
@@ -986,7 +991,8 @@ public Operand visitATAN2_fun(final ATAN2_funContext context) {
986991
final Operand firstValue = args.get(0);
987992
final Operand secondValue = args.get(1);
988993

989-
return Operand.Create(Math.atan2(secondValue.NumberValue().doubleValue(), firstValue.NumberValue().doubleValue()));
994+
return Operand
995+
.Create(Math.atan2(secondValue.NumberValue().doubleValue(), firstValue.NumberValue().doubleValue()));
990996
}
991997

992998
public Operand visitFIXED_fun(final FIXED_funContext context) {
@@ -1543,7 +1549,6 @@ public Operand visitRAND_fun(final RAND_funContext context) {
15431549
return Operand.Create(rand.nextDouble());
15441550
}
15451551

1546-
15471552
public Operand visitRANDBETWEEN_fun(final RANDBETWEEN_funContext context) {
15481553
final List<Operand> args = new ArrayList<Operand>();
15491554
int index = 1;
@@ -1561,7 +1566,8 @@ public Operand visitRANDBETWEEN_fun(final RANDBETWEEN_funContext context) {
15611566
final long tick = DateTime.now().getMillis();
15621567
final Random rand = new Random((int) (tick & 0xffffffffL) | (int) (tick >> 32));
15631568
return Operand.Create(
1564-
rand.nextDouble() * (secondValue.NumberValue().doubleValue() - firstValue.NumberValue().doubleValue()) + firstValue.NumberValue().doubleValue());
1569+
rand.nextDouble() * (secondValue.NumberValue().doubleValue() - firstValue.NumberValue().doubleValue())
1570+
+ firstValue.NumberValue().doubleValue());
15651571
}
15661572

15671573
public Operand visitFACT_fun(final FACT_funContext context) {
@@ -1612,7 +1618,8 @@ public Operand visitPOWER_fun(final POWER_funContext context) {
16121618
final Operand firstValue = args.get(0);
16131619
final Operand secondValue = args.get(1);
16141620

1615-
return Operand.Create(Math.pow(firstValue.NumberValue().doubleValue(), secondValue.NumberValue().doubleValue()));
1621+
return Operand
1622+
.Create(Math.pow(firstValue.NumberValue().doubleValue(), secondValue.NumberValue().doubleValue()));
16161623
}
16171624

16181625
public Operand visitEXP_fun(final EXP_funContext context) {
@@ -1644,7 +1651,8 @@ public Operand visitLOG_fun(final LOG_funContext context) {
16441651
}
16451652

16461653
if (args.size() > 1) {
1647-
return Operand.Create(log(args.get(0).NumberValue().doubleValue(), args.get(1).NumberValue().doubleValue()));
1654+
return Operand
1655+
.Create(log(args.get(0).NumberValue().doubleValue(), args.get(1).NumberValue().doubleValue()));
16481656
}
16491657
return Operand.Create(Math.log10(args.get(0).NumberValue().doubleValue()));
16501658
}
@@ -2060,7 +2068,8 @@ public Operand visitRIGHT_fun(final RIGHT_funContext context) {
20602068
if (secondValue.IsError()) {
20612069
return secondValue;
20622070
}
2063-
return Operand.Create(firstValue.TextValue().substring(firstValue.TextValue().length() - secondValue.IntValue()));
2071+
return Operand
2072+
.Create(firstValue.TextValue().substring(firstValue.TextValue().length() - secondValue.IntValue()));
20642073
}
20652074

20662075
public Operand visitRMB_fun(final RMB_funContext context) {
@@ -2268,15 +2277,15 @@ private String F_base_ToDBC(final String input) {
22682277
return sb.toString();
22692278
}
22702279

2271-
static final String[] CN_UPPER_NUMBER = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
2272-
static final String[] CN_UPPER_MONETRAY_UNIT = {"分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰",
2273-
"仟", "兆", "拾", "佰", "仟"};
2280+
static final String[] CN_UPPER_NUMBER = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
2281+
static final String[] CN_UPPER_MONETRAY_UNIT = { "分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰",
2282+
"仟", "兆", "拾", "佰", "仟" };
22742283
static final String CN_FULL = "整";
22752284
static final String CN_NEGATIVE = "负";
22762285
static final int MONEY_PRECISION = 2;
22772286
static final String CN_ZEOR_FULL = "零元" + CN_FULL;
22782287

2279-
@SuppressWarnings("deprecation")
2288+
//@SuppressWarnings("deprecation")
22802289
private String F_base_ToChineseRMB(final BigDecimal numberOfMoney) {
22812290
StringBuffer sb = new StringBuffer();
22822291
int signum = numberOfMoney.signum();
@@ -2438,9 +2447,11 @@ public Operand visitTIMESTAMP_fun(TIMESTAMP_funContext context) {
24382447
}
24392448
DateTime firstValue;
24402449
if (useLocalTime) {
2441-
firstValue = args.get(0).ToDate("Function TIMESTAMP parameter 1 is error!").DateValue().ToDateTime(DateTimeZone.getDefault());
2450+
firstValue = args.get(0).ToDate("Function TIMESTAMP parameter 1 is error!").DateValue()
2451+
.ToDateTime(DateTimeZone.getDefault());
24422452
} else {
2443-
firstValue = args.get(0).ToDate("Function TIMESTAMP parameter 1 is error!").DateValue().ToDateTime(DateTimeZone.UTC);
2453+
firstValue = args.get(0).ToDate("Function TIMESTAMP parameter 1 is error!").DateValue()
2454+
.ToDateTime(DateTimeZone.UTC);
24442455
}
24452456
if (type == 0) {
24462457
firstValue.getMillis();
@@ -2527,7 +2538,8 @@ public Operand visitERROR_fun(ERROR_funContext context) {
25272538
Operand args1 = this.visit(context.expr());
25282539
if (args1.Type() != OperandType.TEXT) {
25292540
args1 = args1.ToText("");
2530-
if (args1.IsError()) return args1;
2541+
if (args1.IsError())
2542+
return args1;
25312543
}
25322544
return Operand.Error(args1.TextValue());
25332545
}
@@ -3260,7 +3272,6 @@ public Operand visitLARGE_fun(final LARGE_funContext context) {
32603272
return Operand.Create(list.get(list.size() - 1 - (secondValue.IntValue() - excelIndex)));
32613273
}
32623274

3263-
32643275
public Operand visitSMALL_fun(final SMALL_funContext context) {
32653276
final List<Operand> args = new ArrayList<Operand>();
32663277
for (final ExprContext item : context.expr()) {
@@ -3447,7 +3458,8 @@ public Operand visitPARAM_fun(PARAM_funContext context) {
34473458
Operand args1 = this.visit(exprs.get(0));
34483459
if (args1.Type() != OperandType.TEXT) {
34493460
args1 = args1.ToText("");
3450-
if (args1.IsError()) return args1;
3461+
if (args1.IsError())
3462+
return args1;
34513463
}
34523464
Operand result = GetParameter.apply(args1.TextValue());
34533465
if (result.IsError()) {
@@ -3947,7 +3959,8 @@ public Operand visitBINOMDIST_fun(final BINOMDIST_funContext context) {
39473959
if (fourthValue.IsError())
39483960
return fourthValue;
39493961

3950-
if (!(thirdValue.NumberValue().doubleValue() >= 0.0 && thirdValue.NumberValue().doubleValue() <= 1.0 && secondValue.NumberValue().doubleValue() >= 0)) {
3962+
if (!(thirdValue.NumberValue().doubleValue() >= 0.0 && thirdValue.NumberValue().doubleValue() <= 1.0
3963+
&& secondValue.NumberValue().doubleValue() >= 0)) {
39513964
return Operand.Error("Function BINOMDIST parameter error!");
39523965
}
39533966
return Operand.Create(ExcelFunctions.BinomDist(firstValue.IntValue(), secondValue.IntValue(),
@@ -3978,7 +3991,8 @@ public Operand visitEXPONDIST_fun(final EXPONDIST_funContext context) {
39783991
return Operand.Error("Function EXPONDIST parameter error!");
39793992
}
39803993

3981-
return Operand.Create(ExcelFunctions.ExponDist(firstValue.NumberValue().doubleValue(), secondValue.NumberValue().doubleValue(),
3994+
return Operand.Create(ExcelFunctions.ExponDist(firstValue.NumberValue().doubleValue(),
3995+
secondValue.NumberValue().doubleValue(),
39823996
thirdValue.BooleanValue()));
39833997
}
39843998

@@ -4150,7 +4164,8 @@ public Operand visitLOGINV_fun(final LOGINV_funContext context) {
41504164
return Operand.Error("Function LOGINV parameter error!");
41514165
}
41524166
return Operand.Create(
4153-
ExcelFunctions.LogInv(args.get(0).NumberValue().doubleValue(), args.get(1).NumberValue().doubleValue(), args.get(2).NumberValue().doubleValue()));
4167+
ExcelFunctions.LogInv(args.get(0).NumberValue().doubleValue(), args.get(1).NumberValue().doubleValue(),
4168+
args.get(2).NumberValue().doubleValue()));
41544169
}
41554170

41564171
public Operand visitLOGNORMDIST_fun(final LOGNORMDIST_funContext context) {
@@ -4167,15 +4182,17 @@ public Operand visitLOGNORMDIST_fun(final LOGNORMDIST_funContext context) {
41674182
if (args.get(2).NumberValue().doubleValue() < 0.0) {
41684183
return Operand.Error("Function LOGNORMDIST parameter error!");
41694184
}
4170-
return Operand.Create(ExcelFunctions.LognormDist(args.get(0).NumberValue().doubleValue(), args.get(1).NumberValue().doubleValue(),
4185+
return Operand.Create(ExcelFunctions.LognormDist(args.get(0).NumberValue().doubleValue(),
4186+
args.get(1).NumberValue().doubleValue(),
41714187
args.get(2).NumberValue().doubleValue()));
41724188
}
41734189

41744190
public Operand visitNEGBINOMDIST_fun(final NEGBINOMDIST_funContext context) {
41754191
final List<Operand> args = new ArrayList<Operand>();
41764192
int index = 1;
41774193
for (final ExprContext item : context.expr()) {
4178-
final Operand aa = item.accept(this).ToNumber("Function NEGBINOMDIST parameter " + (index++) + " is error!");
4194+
final Operand aa = item.accept(this)
4195+
.ToNumber("Function NEGBINOMDIST parameter " + (index++) + " is error!");
41794196
if (aa.IsError()) {
41804197
return aa;
41814198
}
@@ -4532,7 +4549,8 @@ public Operand visitBASE64URLTOTEXT_fun(final BASE64URLTOTEXT_funContext context
45324549
final List<Operand> args = new ArrayList<Operand>();
45334550
int index = 1;
45344551
for (final ExprContext item : context.expr()) {
4535-
final Operand a = item.accept(this).ToText("Function BASE64URLTOTEXT parameter " + (index++) + " is error!");
4552+
final Operand a = item.accept(this)
4553+
.ToText("Function BASE64URLTOTEXT parameter " + (index++) + " is error!");
45364554
if (a.IsError()) {
45374555
return a;
45384556
}
@@ -4582,7 +4600,8 @@ public Operand visitTEXTTOBASE64URL_fun(final TEXTTOBASE64URL_funContext context
45824600
final List<Operand> args = new ArrayList<Operand>();
45834601
int index = 1;
45844602
for (final ExprContext item : context.expr()) {
4585-
final Operand a = item.accept(this).ToText("Function TEXTTOBASE64URL parameter " + (index++) + " is error!");
4603+
final Operand a = item.accept(this)
4604+
.ToText("Function TEXTTOBASE64URL parameter " + (index++) + " is error!");
45864605
if (a.IsError()) {
45874606
return a;
45884607
}
@@ -4907,7 +4926,7 @@ public Operand visitTRIMSTART_fun(final TRIMSTART_funContext context) {
49074926
String text = args.get(0).TextValue();
49084927
if (args.size() == 2) {
49094928
text = Pattern.compile(
4910-
"^[" + args.get(1).TextValue().replace("[", "\\[").replace("]", "\\]").replace("\\", "\\\\") + "]*")
4929+
"^[" + args.get(1).TextValue().replace("[", "\\[").replace("]", "\\]").replace("\\", "\\\\") + "]*")
49114930
.matcher(text).replaceAll("");
49124931
return Operand.Create(text);
49134932
}
@@ -4929,7 +4948,7 @@ public Operand visitTRIMEND_fun(final TRIMEND_funContext context) {
49294948
String text = args.get(0).TextValue();
49304949
if (args.size() == 2) {
49314950
text = Pattern.compile(
4932-
"[" + args.get(1).TextValue().replace("[", "\\[").replace("]", "\\]").replace("\\", "\\\\") + "]*$")
4951+
"[" + args.get(1).TextValue().replace("[", "\\[").replace("]", "\\]").replace("\\", "\\\\") + "]*$")
49334952
.matcher(text).replaceAll("");
49344953
return Operand.Create(text);
49354954
}
@@ -5191,7 +5210,8 @@ public Operand visitISNULLOREMPTY_fun(final ISNULLOREMPTY_funContext context) {
51915210
}
51925211

51935212
public Operand visitISNULLORWHITESPACE_fun(final ISNULLORWHITESPACE_funContext context) {
5194-
final Operand firstValue = context.expr().accept(this).ToText("Function ISNULLORWHITESPACE parameter 1 is error!");
5213+
final Operand firstValue = context.expr().accept(this)
5214+
.ToText("Function ISNULLORWHITESPACE parameter 1 is error!");
51955215
if (firstValue.IsError()) {
51965216
return firstValue;
51975217
}
@@ -5421,7 +5441,8 @@ public Operand visitLOOKUP_fun(final LOOKUP_funContext context) {
54215441
}
54225442
range = t.BooleanValue();
54235443
}
5424-
Operand operand = ((Operand.OperandKeyValueList) firstValue).TryGetValueFloor(secondValue.NumberValue().doubleValue(), range);
5444+
Operand operand = ((Operand.OperandKeyValueList) firstValue)
5445+
.TryGetValueFloor(secondValue.NumberValue().doubleValue(), range);
54255446
if (operand != null) {
54265447
return operand;
54275448
}
@@ -5493,12 +5514,14 @@ public Operand visitBracket_fun(final Bracket_funContext context) {
54935514
public Operand visitNUM_fun(final NUM_funContext context) {
54945515
final String t = context.num().getText();
54955516
BigDecimal d = new BigDecimal(t);
5496-
if (context.unit() == null) return Operand.Create(d);
5517+
if (context.unit() == null)
5518+
return Operand.Create(d);
54975519
String unit = context.unit().getText().toUpperCase();
54985520
Map<String, NumberUnitType> dict = NumberUnitTypeHelper.GetUnitTypedict();
54995521

55005522
try {
5501-
d = NumberUnitTypeHelper.TransformationUnit(d, dict.get(unit), DistanceUnit, AreaUnit, VolumeUnit, MassUnit);
5523+
d = NumberUnitTypeHelper.TransformationUnit(d, dict.get(unit), DistanceUnit, AreaUnit, VolumeUnit,
5524+
MassUnit);
55025525
return Operand.Create(d);
55035526
} catch (Exception e) {
55045527
return Operand.Error(e.getMessage());
@@ -5531,10 +5554,10 @@ public Operand visitArrayJson_fun(ArrayJson_funContext context) {
55315554
public Operand visitArrayJson(ArrayJsonContext context) {
55325555
Operand.KeyValue keyValue = new Operand.KeyValue();
55335556
if (context.NUM() != null) {
5534-
Integer key = Integer.parseInt(context.NUM().getText());
5535-
if (key != null) {
5557+
try {
5558+
Integer key = Integer.parseInt(context.NUM().getText());
55365559
keyValue.Key = key.toString();
5537-
} else {
5560+
} catch (Exception e) {
55385561
return Operand.Error("Json key '" + context.NUM().getText() + "' is error!");
55395562
}
55405563
}
@@ -5546,13 +5569,20 @@ public Operand visitArrayJson(ArrayJsonContext context) {
55465569
char c = opd.charAt(index++);
55475570
if (c == '\\') {
55485571
char c2 = opd.charAt(index++);
5549-
if (c2 == 'n') sb.append('\n');
5550-
else if (c2 == 'r') sb.append('\r');
5551-
else if (c2 == 't') sb.append('\t');
5552-
else if (c2 == '0') sb.append('\0');
5553-
else if (c2 == 'b') sb.append('\b');
5554-
else if (c2 == 'f') sb.append('\f');
5555-
else sb.append(opd.charAt(index++));
5572+
if (c2 == 'n')
5573+
sb.append('\n');
5574+
else if (c2 == 'r')
5575+
sb.append('\r');
5576+
else if (c2 == 't')
5577+
sb.append('\t');
5578+
else if (c2 == '0')
5579+
sb.append('\0');
5580+
else if (c2 == 'b')
5581+
sb.append('\b');
5582+
else if (c2 == 'f')
5583+
sb.append('\f');
5584+
else
5585+
sb.append(opd.charAt(index++));
55565586
} else {
55575587
sb.append(c);
55585588
}
@@ -5703,8 +5733,8 @@ else if (c2 == 't')
57035733
sb.append('\t');
57045734
else if (c2 == '0')
57055735
sb.append('\0');
5706-
// else if (c2 == 'v') sb.append('\v');
5707-
// else if (c2 == 'a') sb.append('\a');
5736+
// else if (c2 == 'v') sb.append('\v');
5737+
// else if (c2 == 'a') sb.append('\a');
57085738
else if (c2 == 'b')
57095739
sb.append('\b');
57105740
else if (c2 == 'f')

java/toolgood.algorithm/src/main/java/toolgood/algorithm/unitConversion/UnitFactors.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.math.BigDecimal;
44
import java.util.HashMap;
5-
import java.util.TreeMap;
65

76
public class UnitFactors extends HashMap<UnitFactorSynonyms, BigDecimal> {
87

0 commit comments

Comments
 (0)