1
zj
2025-06-23 dc9bd22833255bc602dd42c7f603ecb50842ab35
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package project.data.websocket.utils;
 
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
import project.data.websocket.exception.SDKException;
 
public class InputChecker {
 
    private static final String regEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\t";
 
    public static final String ALL_STR = "*";
 
    private static final InputChecker checkerInst;
 
    static {
        checkerInst = new InputChecker();
    }
 
    private InputChecker() {
    }
 
    public static InputChecker checker() {
        return checkerInst;
    }
 
    private boolean isSpecialChar(String str) {
 
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.find();
    }
 
    public <T> InputChecker shouldNotNull(T value, String name) {
        if (value == null) {
            throw new SDKException(SDKException.INPUT_ERROR, "[Input] " + name + " should not be null");
        }
        return checkerInst;
    }
 
    public <T> InputChecker shouldNull(T value, String name) {
        if (value != null) {
            throw new SDKException(SDKException.INPUT_ERROR, "[Input] " + name + " should be null");
        }
        return checkerInst;
    }
 
    public InputChecker checkSymbol(String symbol) {
        if (symbol == null || "".equals(symbol)) {
            throw new SDKException(SDKException.INPUT_ERROR, "[Input] Symbol is mandatory");
        }
 
        if (ALL_STR.equals(symbol)) {
            return checkerInst;
        }
 
        if (isSpecialChar(symbol)) {
            throw new SDKException(SDKException.INPUT_ERROR, "[Input] " + symbol + " is invalid symbol");
        }
        return checkerInst;
    }
 
    public InputChecker checkCurrency(String currency) {
        if (currency == null || "".equals(currency)) {
            throw new SDKException(SDKException.INPUT_ERROR, "[Input] Currency is mandatory");
        }
        if (isSpecialChar(currency)) {
            throw new SDKException(SDKException.INPUT_ERROR, "[Input] " + currency + " is invalid currency");
        }
        return checkerInst;
    }
 
    public InputChecker checkETF(String symbol) {
        if (!"hb10".equals(symbol)) {
            throw new SDKException(SDKException.INPUT_ERROR, "currently only support hb10 :-)");
        }
        return checkerInst;
    }
 
    public InputChecker checkRange(int size, int min, int max, String name) {
        if (!(min <= size && size <= max)) {
            throw new SDKException(SDKException.INPUT_ERROR,
                    "[Input] " + name + " is out of bound. " + size + " is not in [" + min + "," + max + "]");
        }
        return checkerInst;
    }
 
    public InputChecker checkSymbolList(List<String> symbols) {
        if (symbols == null || symbols.size() == 0) {
            throw new SDKException(SDKException.INPUT_ERROR, "[Input] Symbol is mandatory");
        }
        for (String symbol : symbols) {
            checkSymbol(symbol);
        }
        return checkerInst;
    }
 
    public InputChecker checkRange(Integer size, int min, int max, String name) {
        if (size != null) {
            checkRange(size.intValue(), min, max, name);
        }
        return checkerInst;
    }
 
    public InputChecker greaterOrEqual(Integer value, int base, String name) {
        if (value != null && value < base) {
            throw new SDKException(SDKException.INPUT_ERROR, "[Input] " + name + " should be greater than " + base);
        }
        return checkerInst;
    }
 
    public <T> InputChecker checkList(List<T> list, int min, int max, String name) {
        if (list != null) {
            if (list.size() > max) {
                throw new SDKException(SDKException.INPUT_ERROR,
                        "[Input] " + name + " is out of bound, the max size is " + max);
            } else if (list.size() < min) {
                throw new SDKException(SDKException.INPUT_ERROR,
                        "[Input] " + name + " should contain " + min + " item(s) at least");
            }
        }
        return checkerInst;
    }
}