Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit 7b96cdb

Browse files
committed
工具类禁止new对象
1 parent 4e77c47 commit 7b96cdb

19 files changed

+800
-439
lines changed

src/main/java/com/zhazhapan/modules/constant/Values.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,71 +14,59 @@ public class Values {
1414
* 用户的主目录
1515
*/
1616
public static final String USER_HOME = System.getProperty("user.home");
17-
1817
/**
1918
* 系统分隔符
2019
*/
2120
public static final String SEPARATOR = File.separator;
22-
2321
/**
2422
* KB大小,相对B
2523
*/
2624
public static final long KB = 1024;
27-
2825
/**
2926
* MB大小,相对B
3027
*/
3128
public static final long MB = KB * 1024;
32-
3329
/**
3430
* GB大小,相对B
3531
*/
3632
public static final long GB = MB * 1024;
37-
3833
/**
3934
* TB大小,相对B
4035
*/
4136
public static final long TB = GB * 1024;
42-
4337
/**
4438
* 请求头
4539
*/
4640
public static final String USER_AGENT = "mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/59.0.3071.115 safari/537.36";
47-
4841
public static final int DEFAULT_DOWNLOAD_REMAINING_CENTER = 1048576;
49-
5042
/**
5143
* 网页响应200
5244
*/
5345
public static final int RESPONSE_OK = 200;
54-
5546
/**
5647
* 数字 2
5748
*/
5849
public static final int TWO_INT = 2;
59-
6050
/**
6151
* 数字 3
6252
*/
6353
public static final int THREE_INT = 3;
64-
6554
/**
6655
* 数字 100
6756
*/
6857
public static final int ONE_HUNDRED_INT = 100;
69-
7058
/**
7159
* 英文点号
7260
*/
7361
public static final String DOT_SIGN = ".";
74-
7562
/**
7663
* 美元符号
7764
*/
7865
public static final String DOLLAR_SIGN = "$";
79-
8066
/**
8167
* 符号“-.”
8268
*/
8369
public static final String NEGATIVE_DOT_SIGN = "-.";
70+
71+
private Values() {}
8472
}

src/main/java/com/zhazhapan/util/ArraySort.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
public class ArraySort {
99

10+
private ArraySort() {}
11+
1012
/**
1113
* 堆排序
1214
*

src/main/java/com/zhazhapan/util/Calculator.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ public class Calculator {
2424

2525
private static final Pattern FORMULA_REPLACE_PATTERN = Pattern.compile(CALCULATION_FORMULA_PATTERN_STRING);
2626

27-
private static final Pattern CALCULATION_FORMULA_PATTERN = Pattern.compile(
28-
CALCULATION_FORMULA_PATTERN_STRING.substring(2, CALCULATION_FORMULA_PATTERN_STRING.length() - 2) + "=?");
29-
27+
private static final Pattern CALCULATION_FORMULA_PATTERN = Pattern.compile(CALCULATION_FORMULA_PATTERN_STRING.substring(2, CALCULATION_FORMULA_PATTERN_STRING.length() - 2) + "=?");
3028
/**
3129
* 默认精度
3230
*/
3331
private static int precision = 100;
3432

33+
private Calculator() {}
34+
3535
/**
3636
* 连续计算,使用默认精度(100)
3737
*
3838
* @param formula 表达式
39+
*
3940
* @return {@link BigDecimal}
41+
*
4042
* @throws Exception 异常
4143
*/
4244
public static BigDecimal calculate(String formula) throws Exception {
@@ -52,6 +54,7 @@ public static BigDecimal calculate(String formula) throws Exception {
5254
* 验证第计算式是否合法
5355
*
5456
* @param formula 计算式
57+
*
5558
* @return {@link Boolean}
5659
*/
5760
public static boolean isFormula(String formula) {
@@ -65,7 +68,9 @@ public static boolean isFormula(String formula) {
6568
* 开始计算
6669
*
6770
* @param formula 表达式
71+
*
6872
* @return {@link BigDecimal}
73+
*
6974
* @throws Exception 异常
7075
*/
7176
private static BigDecimal doCalculate(String formula) throws Exception {
@@ -80,8 +85,7 @@ private static BigDecimal doCalculate(String formula) throws Exception {
8085
char c = formula.charAt(i);
8186
if (Character.isDigit(c)) {
8287
BigDecimal num = new BigDecimal(c - '0');
83-
number = isDecimal ? number.add(num.multiply(decimalSign))
84-
: num.add(number.multiply(BigDecimal.valueOf(10)));
88+
number = isDecimal ? number.add(num.multiply(decimalSign)) : num.add(number.multiply(BigDecimal.valueOf(10)));
8589
decimalSign = decimalSign.multiply(BigDecimal.valueOf(0.1));
8690
} else if (c == '.') {
8791
isDecimal = true;
@@ -116,9 +120,11 @@ private static BigDecimal doCalculate(String formula) throws Exception {
116120
/**
117121
* 计算()内的表达式
118122
*
119-
* @param start 开始位置
123+
* @param start 开始位置
120124
* @param formula 表达式
125+
*
121126
* @return 长度为2的{@link BigDecimal}数组,位置0表示计算结果,位置1表示结束位置
127+
*
122128
* @throws Exception 异常
123129
*/
124130
private static BigDecimal[] calculateInlineFormula(int start, String formula) throws Exception {
@@ -145,7 +151,9 @@ private static BigDecimal[] calculateInlineFormula(int start, String formula) th
145151
* 连续计算,可能导致数据失真
146152
*
147153
* @param formula 表达式
154+
*
148155
* @return {@link Double}
156+
*
149157
* @throws ScriptException 异常
150158
*/
151159
public static Object calculateUseEval(String formula) throws ScriptException {

src/main/java/com/zhazhapan/util/Checker.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public class Checker {
1616
/**
1717
* 超链接匹配,忽略大小写
1818
*/
19-
public static final Pattern HYPER_LINK_PATTERN = Pattern
20-
.compile("^(https*://)?([^\\s&;\"':<>]+\\.)+[a-z0-9]+(/[^\\s]*)*$", Pattern.CASE_INSENSITIVE);
19+
public static final Pattern HYPER_LINK_PATTERN = Pattern.compile("^(https*://)?([^\\s&;\"':<>]+\\.)+[a-z0-9]+(/[^\\s]*)*$", Pattern.CASE_INSENSITIVE);
2120
/**
2221
* 日期匹配
2322
*/
@@ -33,13 +32,15 @@ public class Checker {
3332
/**
3433
* 邮箱匹配,忽略大小写
3534
*/
36-
public static final Pattern EMAIL_PATTERN = Pattern
37-
.compile("^[0-9a-z]+([0-9a-z]|(\\.[0-9a-z]+))*@[0-9a-z]+(\\.{1}[0-9a-z]+)+$", Pattern.CASE_INSENSITIVE);
35+
public static final Pattern EMAIL_PATTERN = Pattern.compile("^[0-9a-z]+([0-9a-z]|(\\.[0-9a-z]+))*@[0-9a-z]+(\\.{1}[0-9a-z]+)+$", Pattern.CASE_INSENSITIVE);
36+
37+
private Checker() {}
3838

3939
/**
4040
* 检查数组是否已经排好序
4141
*
4242
* @param nums 数组
43+
*
4344
* @return {@link Boolean}
4445
*/
4546
public static boolean isSorted(int[] nums) {
@@ -59,6 +60,7 @@ public static boolean isSorted(int[] nums) {
5960
* 是否为日期格式
6061
*
6162
* @param date 需要判断的日期
63+
*
6264
* @return {@link Boolean}
6365
*/
6466
public static boolean isDate(String date) {
@@ -68,9 +70,10 @@ public static boolean isDate(String date) {
6870
/**
6971
* 替换字符之前检查字符串是否为空
7072
*
71-
* @param string 需要检测的字符串
73+
* @param string 需要检测的字符串
7274
* @param oldChar 需要替换的字符
7375
* @param newChar 新的字符
76+
*
7477
* @return {@link String}
7578
*/
7679
public static String replace(String string, char oldChar, char newChar) {
@@ -80,9 +83,10 @@ public static String replace(String string, char oldChar, char newChar) {
8083
/**
8184
* 替换字符串之前检查字符串是否为空
8285
*
83-
* @param string 需要检测的字符串
86+
* @param string 需要检测的字符串
8487
* @param oldString 需要替换的字符串
8588
* @param newString 新的字符串
89+
*
8690
* @return {@link String}
8791
*/
8892
public static String replace(String string, String oldString, String newString) {
@@ -93,6 +97,7 @@ public static String replace(String string, String oldString, String newString)
9397
* 是否为邮箱格式
9498
*
9599
* @param email 需要判断的邮箱地址
100+
*
96101
* @return {@link Boolean}
97102
*/
98103
public static boolean isEmail(String email) {
@@ -103,6 +108,7 @@ public static boolean isEmail(String email) {
103108
* 是否为数字(含小数)格式
104109
*
105110
* @param decimal 需要判断的数字
111+
*
106112
* @return {@link Boolean}
107113
*/
108114
public static boolean isDecimal(String decimal) {
@@ -113,6 +119,7 @@ public static boolean isDecimal(String decimal) {
113119
* 是否为整数格式
114120
*
115121
* @param number 需要判断的整数
122+
*
116123
* @return {@link Boolean}
117124
*/
118125
public static boolean isNumber(String number) {
@@ -123,6 +130,7 @@ public static boolean isNumber(String number) {
123130
* 对象是否为NULL
124131
*
125132
* @param object 需要判断的对象
133+
*
126134
* @return {@link Boolean}
127135
*/
128136
public static boolean isNull(Object object) {
@@ -133,6 +141,7 @@ public static boolean isNull(Object object) {
133141
* 对象是否不为NULL
134142
*
135143
* @param object 需要判断的对象
144+
*
136145
* @return {@link Boolean}
137146
*/
138147
public static boolean isNotNull(Object object) {
@@ -143,6 +152,7 @@ public static boolean isNotNull(Object object) {
143152
* 字符串是否为NULL或空
144153
*
145154
* @param string 需要判断的字符串
155+
*
146156
* @return {@link Boolean}
147157
*/
148158
public static boolean isNullOrEmpty(String string) {
@@ -153,6 +163,7 @@ public static boolean isNullOrEmpty(String string) {
153163
* 字符串是否不为空
154164
*
155165
* @param string 需要判断的字符串
166+
*
156167
* @return {@link Boolean}
157168
*/
158169
public static boolean isNotEmpty(String string) {
@@ -163,6 +174,7 @@ public static boolean isNotEmpty(String string) {
163174
* 检测字符串是否为NULL
164175
*
165176
* @param string 需要检测的字符串
177+
*
166178
* @return {@link String}
167179
*/
168180
public static String checkNull(String string) {
@@ -173,7 +185,9 @@ public static String checkNull(String string) {
173185
* 检测整数是否为NULL
174186
*
175187
* @param longNum 需要检测的整数
188+
*
176189
* @return {@link Long}
190+
*
177191
* @deprecated 这个方法没有作用
178192
*/
179193
public static long checkNull(long longNum) {
@@ -184,6 +198,7 @@ public static long checkNull(long longNum) {
184198
* 判断LIST是否不为空
185199
*
186200
* @param list 需要判断的LIST
201+
*
187202
* @return {@link Boolean}
188203
*/
189204
public static boolean isNotEmpty(List<?> list) {
@@ -194,6 +209,7 @@ public static boolean isNotEmpty(List<?> list) {
194209
* 判断LIST是否为空或NULL
195210
*
196211
* @param list 需要判断的LIST
212+
*
197213
* @return {@link Boolean}
198214
*/
199215
public static boolean isEmpty(List<?> list) {
@@ -204,6 +220,7 @@ public static boolean isEmpty(List<?> list) {
204220
* 判断MAP是否为不空
205221
*
206222
* @param map 需要判断的MAP
223+
*
207224
* @return {@link Boolean}
208225
*/
209226
public static boolean isNotEmpty(Map<?, ?> map) {
@@ -214,6 +231,7 @@ public static boolean isNotEmpty(Map<?, ?> map) {
214231
* 判断MAP是否为空或NULL
215232
*
216233
* @param map 需要判断的MAP
234+
*
217235
* @return {@link Boolean}
218236
*/
219237
public static boolean isEmpty(Map<?, ?> map) {
@@ -224,6 +242,7 @@ public static boolean isEmpty(Map<?, ?> map) {
224242
* 是否为超链接
225243
*
226244
* @param hyperLink 需要匹配超链接
245+
*
227246
* @return {@link Boolean}
228247
*/
229248
public static boolean isHyperLink(String hyperLink) {
@@ -234,6 +253,7 @@ public static boolean isHyperLink(String hyperLink) {
234253
* 检测日期是否为NULL
235254
*
236255
* @param date 需要检测的日期
256+
*
237257
* @return {@link Date}
238258
*/
239259
public static Date checkDate(Date date) {

src/main/java/com/zhazhapan/util/CryptUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ public class CryptUtil {
1414

1515
private static final int THOUSAND = 1000;
1616

17+
private CryptUtil() {}
18+
1719
/**
1820
* 通过获取一个KEY数组
1921
*
2022
* @param key 可自定义一个INT型数值
23+
*
2124
* @return 长度为3的KEY数组
2225
*/
2326
public static int[] getKeys(int key) {
@@ -53,6 +56,7 @@ public static int[] getKeys(int key) {
5356
* 通过字符串获取KEY
5457
*
5558
* @param string 可随机一个字符串
59+
*
5660
* @return INT型KEY
5761
*/
5862
public static int stringToKey(String string) {
@@ -67,5 +71,4 @@ public static int stringToKey(String string) {
6771
}
6872
return key;
6973
}
70-
7174
}

0 commit comments

Comments
 (0)