Skip to content

Commit 1610067

Browse files
committed
修改 类名
1 parent 8aca013 commit 1610067

File tree

11 files changed

+117
-76
lines changed

11 files changed

+117
-76
lines changed

csharp/ToolGood.Algorithm2/Internals/CharUtil.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public static bool Equals(string left, string arg1, string arg2)
6363

6464
public static bool Equals(string left, string arg1, string arg2, string arg3)
6565
{
66-
if (left == null) return false;
6766
if (left == null) return false;
6867
if (arg1 != null && EqualsOnce(left, arg1))
6968
return true;

csharp/ToolGood.Algorithm2/Internals/MathVisitor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public Operand VisitAndOr_fun(mathParser.AndOr_funContext context)
298298
var t = context.op.Text;
299299
var first = this.Visit(context.expr(0)).ToBoolean($"Function '{t}' parameter 1 is error!");
300300
if (first.IsError) { return first; }
301-
if (CharUtil.Equals(t, "&&") || t.Equals("and", StringComparison.OrdinalIgnoreCase)) {
301+
if (CharUtil.Equals(t, "&&", "and")) {
302302
if (first.BooleanValue == false) return Operand.False;
303303
} else {
304304
if (first.BooleanValue) return Operand.True;
@@ -2923,15 +2923,15 @@ private double F_base_sumif(List<double> dbs, string s, List<double> sumdbs)
29232923
}
29242924
private bool F_base_compare(double a, double b, string ss)
29252925
{
2926-
if (ss == "<") {
2926+
if (CharUtil.Equals(ss, "<")) {
29272927
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) < 0;
2928-
} else if (ss == "<=") {
2928+
} else if (CharUtil.Equals(ss, "<=")) {
29292929
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) <= 0;
2930-
} else if (ss == ">") {
2930+
} else if (CharUtil.Equals(ss, ">")) {
29312931
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) > 0;
2932-
} else if (ss == ">=") {
2932+
} else if (CharUtil.Equals(ss, ">=")) {
29332933
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) >= 0;
2934-
} else if (ss == "=" || ss == "==") {
2934+
} else if (CharUtil.Equals(ss, "=", "==", "===")) {
29352935
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) == 0;
29362936
}
29372937
return Math.Round(a - b, 12, MidpointRounding.AwayFromZero) != 0;

java/toolgood.algorithm/src/main/java/toolgood/algorithm/AlgorithmEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.function.Function;
88

99
import toolgood.algorithm.internals.AntlrErrorListener;
10-
import toolgood.algorithm.internals.CaseChangingCharStream;
10+
import toolgood.algorithm.internals.AntlrCharStream;
1111
import toolgood.algorithm.internals.MathVisitor;
1212
import toolgood.algorithm.internals.MyFunction;
1313
import toolgood.algorithm.litJson.JsonData;
@@ -130,7 +130,7 @@ public boolean Parse(final String exp) throws RecognitionException {
130130
return false;
131131
}
132132
// try {
133-
final CaseChangingCharStream stream = new CaseChangingCharStream(CharStreams.fromString(exp));
133+
final AntlrCharStream stream = new AntlrCharStream(CharStreams.fromString(exp));
134134
final mathLexer lexer = new mathLexer(stream);
135135
final CommonTokenStream tokens = new CommonTokenStream(lexer);
136136
final mathParser parser = new mathParser(tokens);

java/toolgood.algorithm/src/main/java/toolgood/algorithm/ConditionCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import toolgood.algorithm.math.mathParser;
1212
import toolgood.algorithm.math.mathParser2.ProgContext;
1313
import toolgood.algorithm.internals.AntlrErrorListener;
14-
import toolgood.algorithm.internals.CaseChangingCharStream;
14+
import toolgood.algorithm.internals.AntlrCharStream;
1515
import toolgood.algorithm.internals.ConditionCacheInfo;
1616

1717
public class ConditionCache {
@@ -139,7 +139,7 @@ private ProgContext Parse(String exp) {
139139
return null;
140140
}
141141
try {
142-
final CaseChangingCharStream stream = new CaseChangingCharStream(CharStreams.fromString(exp));
142+
final AntlrCharStream stream = new AntlrCharStream(CharStreams.fromString(exp));
143143
final mathLexer lexer = new mathLexer(stream);
144144
final CommonTokenStream tokens = new CommonTokenStream(lexer);
145145
final mathParser parser = new mathParser(tokens);

java/toolgood.algorithm/src/main/java/toolgood/algorithm/Operand.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import toolgood.algorithm.litJson.JsonData;
1313

1414
public abstract class Operand {
15-
public final static Operand True = Create(true);
16-
public final static Operand False = Create(false);
15+
public final static Operand True = new OperandBoolean(true);
16+
public final static Operand False = new OperandBoolean(false);
17+
public final static Operand One = Operand.Create(1);
18+
public final static Operand Zero = Operand.Create(0);
1719

1820
public boolean IsNull() {
1921
return false;
@@ -147,7 +149,7 @@ public Operand ToNumber(final String errorMessage) {
147149
return this;
148150
}
149151
if (Type() == OperandType.BOOLEAN) {
150-
return Create(BooleanValue() ? 1.0 : 0.0);
152+
return BooleanValue() ? One : Zero;
151153
}
152154
if (Type() == OperandType.DATE) {
153155
return Create((double) DateValue().ToNumber());

java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/CaseChangingCharStream.java renamed to java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/AntlrCharStream.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import org.antlr.v4.runtime.CharStream;
44
import org.antlr.v4.runtime.misc.Interval;
55

6-
public class CaseChangingCharStream implements CharStream {
6+
public class AntlrCharStream implements CharStream {
77
final CharStream stream;
88

9-
public CaseChangingCharStream(CharStream stream) {
9+
public AntlrCharStream(CharStream stream) {
1010
this.stream = stream;
1111
}
1212

@@ -26,28 +26,7 @@ public int LA(int i) {
2626
if (c <= 0) {
2727
return c;
2828
}
29-
char o = (char)c;
30-
if (o == '‘') {
31-
o = '\'';
32-
} else if (o == '’') {
33-
o = '\'';
34-
} else if (o == '“') {
35-
o = '"';
36-
} else if (o == '”') {
37-
o = '"';
38-
} else if (o == '〔') {
39-
o = '(';
40-
} else if (o == '〕') {
41-
o = ')';
42-
}
43-
44-
if (c == 12288) {
45-
o = (char)32;
46-
} else if (c > 65280 && c < 65375) {
47-
o = (char)(c - 65248);
48-
}
49-
50-
return Character.toUpperCase(o);
29+
return CharUtil.StandardChar((char)c);
5130
}
5231

5332
@Override

java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/LookupAlgorithmEngine.java renamed to java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/AntlrLookupEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import toolgood.algorithm.Operand;
55
import toolgood.algorithm.litJson.JsonData;
66

7-
public class LookupAlgorithmEngine extends AlgorithmEngine {
7+
public class AntlrLookupEngine extends AlgorithmEngine {
88
public Operand Json;
99

1010
@Override
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package toolgood.algorithm.internals;
2+
3+
public class CharUtil {
4+
public static char StandardChar(char c)
5+
{
6+
if (c <= 0) return c;
7+
char o = (char)c;
8+
if (o == '‘') return '\'';
9+
if (o == '’') return '\'';
10+
if (o == '“') return '"';
11+
if (o == '”') return '"';
12+
if (o == '〔') return '(';
13+
if (o == '〕') return ')';
14+
if (o == '=') return '=';
15+
if (o == '+') return '+';
16+
if (o == '-') return '-';
17+
if (o == '×') return '*';
18+
if (o == '÷') return '/';
19+
if (o == '/') return '/';
20+
21+
if (c == 12288) {
22+
o = (char)32;
23+
} else if (c > 65280 && c < 65375) {
24+
o = (char)(c - 65248);
25+
}
26+
return Character.toUpperCase(o);
27+
}
28+
29+
private static boolean EqualsOnce(String left, String right)
30+
{
31+
if (left.length() != right.length()) return false;
32+
for (int i = 0; i < left.length(); i++) {
33+
if (left.charAt(i) != right.charAt(i)) {
34+
char a = StandardChar(left.charAt(i));
35+
char b = StandardChar(right.charAt(i));
36+
if (a != b) return false;
37+
}
38+
}
39+
return true;
40+
}
41+
42+
public static boolean Equals(String left, String right)
43+
{
44+
if (left == null) return false;
45+
if (right == null) return false;
46+
return EqualsOnce(left, right);
47+
}
48+
public static boolean Equals(String left, String arg1, String arg2)
49+
{
50+
if (left == null) return false;
51+
if (arg1 != null && EqualsOnce(left, arg1))
52+
return true;
53+
if (arg2 != null && EqualsOnce(left, arg2))
54+
return true;
55+
return false;
56+
}
57+
58+
public static boolean Equals(String left, String arg1, String arg2, String arg3)
59+
{
60+
if (left == null) return false;
61+
if (arg1 != null && EqualsOnce(left, arg1))
62+
return true;
63+
if (arg2 != null && EqualsOnce(left, arg2))
64+
return true;
65+
if (arg3 != null && EqualsOnce(left, arg3))
66+
return true;
67+
return false;
68+
}
69+
70+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ProgContext Parse(final String exp) {
4949
return null;
5050
}
5151
try {
52-
final CaseChangingCharStream stream = new CaseChangingCharStream(CharStreams.fromString(exp));
52+
final AntlrCharStream stream = new AntlrCharStream(CharStreams.fromString(exp));
5353
final mathLexer lexer = new mathLexer(stream);
5454
final CommonTokenStream tokens = new CommonTokenStream(lexer);
5555
final mathParser parser = new mathParser(tokens);

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ public static String GetHmacSha512String(final byte[] buffer, final String secre
8888
return byteArrayToHexString(result);
8989
}
9090

91-
// private static byte[] toLH(int n) {
92-
// byte[] b = new byte[4];
93-
// b[0] = (byte) (n & 0xff);
94-
// b[1] = (byte) (n >> 8 & 0xff);
95-
// b[2] = (byte) (n >> 16 & 0xff);
96-
// b[3] = (byte) (n >> 24 & 0xff);
97-
// return b;
98-
// }
9991
private static byte[] toHH(int n) {
10092
byte[] b = new byte[4];
10193
b[3] = (byte) (n & 0xff);

0 commit comments

Comments
 (0)