Skip to content

Commit f35e13c

Browse files
authored
Merge pull request #26 from lunasaw/2.5.8
2.5.8 版本升级,code clean up
2 parents ec6f8b3 + 3aad8a6 commit f35e13c

File tree

11 files changed

+185
-149
lines changed

11 files changed

+185
-149
lines changed

pom.xml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>io.github.lunasaw</groupId>
88
<artifactId>luna-common</artifactId>
99
<name>luna-common</name>
10-
<version>2.5.7</version>
10+
<version>2.5.8</version>
1111
<description>common is project which contains common utils</description>
1212
<url>https://github.com/lunasaw/luna-common</url>
1313

@@ -21,14 +21,14 @@
2121
<!--dependencies-->
2222
<commons-collections4.version>4.4</commons-collections4.version>
2323
<commons-lang3.version>3.14.0</commons-lang3.version>
24-
<commons-codec.version>1.16.0</commons-codec.version>
25-
<commons-io.version>2.15.1</commons-io.version>
26-
<httpclient-5.version>5.2.1</httpclient-5.version>
24+
<commons-codec.version>1.16.1</commons-codec.version>
25+
<commons-io.version>2.16.1</commons-io.version>
26+
<httpclient-5.version>5.3.1</httpclient-5.version>
2727
<guava.version>32.1.3-jre</guava.version>
28-
<fast-json.version>2.0.26</fast-json.version>
28+
<fast-json2.version>2.0.48</fast-json2.version>
2929
<oshi.version>6.4.9</oshi.version>
3030
<junit.version>4.13.2</junit.version>
31-
<lombok.version>1.18.30</lombok.version>
31+
<lombok.version>1.18.32</lombok.version>
3232
<validation-api.version>3.0.2</validation-api.version>
3333
<slf4j-simple.version>2.0.9</slf4j-simple.version>
3434
</properties>
@@ -102,9 +102,9 @@
102102
<version>${oshi.version}</version> <!-- 这个版本不要随便升级,和JNA的环境有关 -->
103103
</dependency>
104104
<dependency>
105-
<groupId>com.alibaba</groupId>
106-
<artifactId>fastjson</artifactId>
107-
<version>${fast-json.version}</version>
105+
<groupId>com.alibaba.fastjson2</groupId>
106+
<artifactId>fastjson2</artifactId>
107+
<version>${fast-json2.version}</version>
108108
</dependency>
109109
<dependency>
110110
<groupId>jakarta.validation</groupId>
@@ -116,6 +116,11 @@
116116
<artifactId>lombok</artifactId>
117117
<version>${lombok.version}</version>
118118
</dependency>
119+
<dependency>
120+
<groupId>org.glassfish.jaxb</groupId>
121+
<artifactId>jaxb-runtime</artifactId>
122+
<version>4.0.5</version> <!-- 最新版本 -->
123+
</dependency>
119124
<dependency>
120125
<groupId>org.slf4j</groupId>
121126
<artifactId>slf4j-simple</artifactId>

src/main/java/com/luna/common/cache/SimpleGuavaCache.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import java.util.concurrent.Callable;
66
import java.util.concurrent.ConcurrentMap;
77
import java.util.concurrent.TimeUnit;
8+
import java.util.function.Function;
89
import java.util.stream.Collectors;
910

10-
import com.alibaba.fastjson.JSON;
11+
import com.alibaba.fastjson2.JSON;
1112
import com.google.common.cache.*;
1213
import com.google.common.collect.ImmutableMap;
1314

@@ -66,7 +67,8 @@ public void put(K key, V value) {
6667
cache.put(key, value);
6768
}
6869

69-
public void invalidate(K... key) {
70+
@SafeVarargs
71+
public final void invalidate(K... key) {
7072
Arrays.stream(key).forEach(cache::invalidate);
7173
}
7274

@@ -102,7 +104,8 @@ public void refresh(K key) {
102104
cache.refresh(key);
103105
}
104106

105-
public ImmutableMap<K, V> getAllPresent(K... keys) {
107+
@SafeVarargs
108+
public final ImmutableMap<K, V> getAllPresent(K... keys) {
106109
return cache.getAllPresent(Arrays.stream(keys).distinct().collect(Collectors.toList()));
107110
}
108111

src/main/java/com/luna/common/calendarist/utils/CalendaristUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ public static int getBitInt(int data, int length, int shift) {
156156
* @return int
157157
*/
158158
public static int getFirstTerm(int solarYear, int solarMonth) {
159-
long times = 31556925974L * (solarYear - 1900)
160-
+ CalendaristConstants.SOLAR_TERM_INFO[(solarMonth - 1) * 2] * 60000L + (0L);
159+
long times = 31556925974L * (solarYear - 1900) + CalendaristConstants.SOLAR_TERM_INFO[(solarMonth - 1) * 2] * 60000L;
161160
Date offDate = new Date(times - 2208549300000L);
162161
// 1、取得本地时间:
163162
Calendar cal = CalendaristUtils.getCalendarInstance();

src/main/java/com/luna/common/cron/CronExpression.java

Lines changed: 81 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,20 @@
190190
public final class CronExpression implements Serializable, Cloneable {
191191

192192
public static final int MAX_YEAR = Calendar.getInstance().get(Calendar.YEAR) + 100;
193-
protected static final int SECOND = 0;
194-
protected static final int MINUTE = 1;
195-
protected static final int HOUR = 2;
196-
protected static final int DAY_OF_MONTH = 3;
197-
protected static final int MONTH = 4;
198-
protected static final int DAY_OF_WEEK = 5;
199-
protected static final int YEAR = 6;
200-
protected static final int ALL_SPEC_INT = 99; // '*'
201-
protected static final int NO_SPEC_INT = 98; // '?'
202-
protected static final Integer ALL_SPEC = ALL_SPEC_INT;
203-
protected static final Integer NO_SPEC = NO_SPEC_INT;
204-
205-
protected static final Map<String, Integer> monthMap = new HashMap<String, Integer>(20);
206-
protected static final Map<String, Integer> dayMap = new HashMap<String, Integer>(60);
193+
private static final int SECOND = 0;
194+
private static final int MINUTE = 1;
195+
private static final int HOUR = 2;
196+
private static final int DAY_OF_MONTH = 3;
197+
private static final int MONTH = 4;
198+
private static final int DAY_OF_WEEK = 5;
199+
private static final int YEAR = 6;
200+
private static final int ALL_SPEC_INT = 99; // '*'
201+
private static final int NO_SPEC_INT = 98; // '?'
202+
private static final Integer ALL_SPEC = ALL_SPEC_INT;
203+
private static final Integer NO_SPEC = NO_SPEC_INT;
204+
205+
private static final Map<String, Integer> monthMap = new HashMap<String, Integer>(20);
206+
private static final Map<String, Integer> dayMap = new HashMap<String, Integer>(60);
207207
private static final long serialVersionUID = 12423409423L;
208208

209209
static {
@@ -230,20 +230,20 @@ public final class CronExpression implements Serializable, Cloneable {
230230
}
231231

232232
private final String cronExpression;
233-
protected transient TreeSet<Integer> seconds;
234-
protected transient TreeSet<Integer> minutes;
235-
protected transient TreeSet<Integer> hours;
236-
protected transient TreeSet<Integer> daysOfMonth;
237-
protected transient TreeSet<Integer> months;
238-
protected transient TreeSet<Integer> daysOfWeek;
239-
protected transient TreeSet<Integer> years;
240-
241-
protected transient boolean lastdayOfWeek = false;
242-
protected transient int nthdayOfWeek = 0;
243-
protected transient boolean lastdayOfMonth = false;
244-
protected transient boolean nearestWeekday = false;
245-
protected transient int lastdayOffset = 0;
246-
protected transient boolean expressionParsed = false;
233+
private transient TreeSet<Integer> seconds;
234+
private transient TreeSet<Integer> minutes;
235+
private transient TreeSet<Integer> hours;
236+
private transient TreeSet<Integer> daysOfMonth;
237+
private transient TreeSet<Integer> months;
238+
private transient TreeSet<Integer> daysOfWeek;
239+
private transient TreeSet<Integer> years;
240+
241+
private transient boolean lastdayOfWeek = false;
242+
private transient int nthdayOfWeek = 0;
243+
private transient boolean lastdayOfMonth = false;
244+
private transient boolean nearestWeekday = false;
245+
private transient int lastdayOffset = 0;
246+
private transient boolean expressionParsed = false;
247247
private TimeZone timeZone = null;
248248

249249
/**
@@ -319,7 +319,7 @@ public static void main(String[] args) throws ParseException {
319319
CronExpression cronExpression = new CronExpression(cronStr);
320320

321321
Date date = new Date();
322-
System.out.println(date.toString());
322+
System.out.println(date);
323323
for (int i = 0; i < 10; i++) {
324324
date = cronExpression.getNextValidTimeAfter(date);
325325
System.out.println(date.toString());
@@ -436,7 +436,7 @@ public String toString() {
436436
return cronExpression;
437437
}
438438

439-
protected void buildExpression(String expression) throws ParseException {
439+
private void buildExpression(String expression) throws ParseException {
440440
expressionParsed = true;
441441

442442
try {
@@ -518,11 +518,11 @@ protected void buildExpression(String expression) throws ParseException {
518518
throw pe;
519519
} catch (Exception e) {
520520
throw new ParseException("Illegal cron expression format ("
521-
+ e.toString() + ")", 0);
521+
+ e + ")", 0);
522522
}
523523
}
524524

525-
protected int storeExpressionVals(int pos, String s, int type)
525+
private int storeExpressionVals(int pos, String s, int type)
526526
throws ParseException {
527527

528528
int incr = 0;
@@ -717,7 +717,7 @@ private void checkIncrementRange(int incr, int type, int idxPos) throws ParseExc
717717
}
718718
}
719719

720-
protected int checkNext(int pos, String s, int val, int type)
720+
private int checkNext(int pos, String s, int val, int type)
721721
throws ParseException {
722722

723723
int end = -1;
@@ -859,46 +859,45 @@ public String getCronExpression() {
859859
}
860860

861861
public String getExpressionSummary() {
862-
StringBuilder buf = new StringBuilder();
863-
864-
buf.append("seconds: ");
865-
buf.append(getExpressionSetSummary(seconds));
866-
buf.append("\n");
867-
buf.append("minutes: ");
868-
buf.append(getExpressionSetSummary(minutes));
869-
buf.append("\n");
870-
buf.append("hours: ");
871-
buf.append(getExpressionSetSummary(hours));
872-
buf.append("\n");
873-
buf.append("daysOfMonth: ");
874-
buf.append(getExpressionSetSummary(daysOfMonth));
875-
buf.append("\n");
876-
buf.append("months: ");
877-
buf.append(getExpressionSetSummary(months));
878-
buf.append("\n");
879-
buf.append("daysOfWeek: ");
880-
buf.append(getExpressionSetSummary(daysOfWeek));
881-
buf.append("\n");
882-
buf.append("lastdayOfWeek: ");
883-
buf.append(lastdayOfWeek);
884-
buf.append("\n");
885-
buf.append("nearestWeekday: ");
886-
buf.append(nearestWeekday);
887-
buf.append("\n");
888-
buf.append("NthDayOfWeek: ");
889-
buf.append(nthdayOfWeek);
890-
buf.append("\n");
891-
buf.append("lastdayOfMonth: ");
892-
buf.append(lastdayOfMonth);
893-
buf.append("\n");
894-
buf.append("years: ");
895-
buf.append(getExpressionSetSummary(years));
896-
buf.append("\n");
897862

898-
return buf.toString();
863+
String buf = "seconds: " +
864+
getExpressionSetSummary(seconds) +
865+
"\n" +
866+
"minutes: " +
867+
getExpressionSetSummary(minutes) +
868+
"\n" +
869+
"hours: " +
870+
getExpressionSetSummary(hours) +
871+
"\n" +
872+
"daysOfMonth: " +
873+
getExpressionSetSummary(daysOfMonth) +
874+
"\n" +
875+
"months: " +
876+
getExpressionSetSummary(months) +
877+
"\n" +
878+
"daysOfWeek: " +
879+
getExpressionSetSummary(daysOfWeek) +
880+
"\n" +
881+
"lastdayOfWeek: " +
882+
lastdayOfWeek +
883+
"\n" +
884+
"nearestWeekday: " +
885+
nearestWeekday +
886+
"\n" +
887+
"NthDayOfWeek: " +
888+
nthdayOfWeek +
889+
"\n" +
890+
"lastdayOfMonth: " +
891+
lastdayOfMonth +
892+
"\n" +
893+
"years: " +
894+
getExpressionSetSummary(years) +
895+
"\n";
896+
897+
return buf;
899898
}
900899

901-
protected String getExpressionSetSummary(java.util.Set<Integer> set) {
900+
private String getExpressionSetSummary(java.util.Set<Integer> set) {
902901

903902
if (set.contains(NO_SPEC)) {
904903
return "?";
@@ -924,7 +923,7 @@ protected String getExpressionSetSummary(java.util.Set<Integer> set) {
924923
return buf.toString();
925924
}
926925

927-
protected String getExpressionSetSummary(java.util.ArrayList<Integer> list) {
926+
private String getExpressionSetSummary(java.util.ArrayList<Integer> list) {
928927

929928
if (list.contains(NO_SPEC)) {
930929
return "?";
@@ -950,23 +949,21 @@ protected String getExpressionSetSummary(java.util.ArrayList<Integer> list) {
950949
return buf.toString();
951950
}
952951

953-
protected int skipWhiteSpace(int i, String s) {
952+
private int skipWhiteSpace(int i, String s) {
954953
for (; i < s.length() && (s.charAt(i) == ' ' || s.charAt(i) == '\t'); i++) {
955-
;
956954
}
957955

958956
return i;
959957
}
960958

961-
protected int findNextWhiteSpace(int i, String s) {
959+
private int findNextWhiteSpace(int i, String s) {
962960
for (; i < s.length() && (s.charAt(i) != ' ' || s.charAt(i) != '\t'); i++) {
963-
;
964961
}
965962

966963
return i;
967964
}
968965

969-
protected void addToSet(int val, int end, int incr, int type)
966+
private void addToSet(int val, int end, int incr, int type)
970967
throws ParseException {
971968

972969
TreeSet<Integer> set = getSet(type);
@@ -1134,7 +1131,7 @@ TreeSet<Integer> getSet(int type) {
11341131
}
11351132
}
11361133

1137-
protected ValueSet getValue(int v, String s, int i) {
1134+
private ValueSet getValue(int v, String s, int i) {
11381135
char c = s.charAt(i);
11391136
StringBuilder s1 = new StringBuilder(String.valueOf(v));
11401137
while (c >= '0' && c <= '9') {
@@ -1152,13 +1149,13 @@ protected ValueSet getValue(int v, String s, int i) {
11521149
return val;
11531150
}
11541151

1155-
protected int getNumericValue(String s, int i) {
1152+
private int getNumericValue(String s, int i) {
11561153
int endOfVal = findNextWhiteSpace(i, s);
11571154
String val = s.substring(i, endOfVal);
11581155
return Integer.parseInt(val);
11591156
}
11601157

1161-
protected int getMonthNumber(String s) {
1158+
private int getMonthNumber(String s) {
11621159
Integer integer = monthMap.get(s);
11631160

11641161
if (integer == null) {
@@ -1174,7 +1171,7 @@ protected int getMonthNumber(String s) {
11741171
//
11751172
////////////////////////////////////////////////////////////////////////////
11761173

1177-
protected int getDayOfWeekNumber(String s) {
1174+
private int getDayOfWeekNumber(String s) {
11781175
Integer integer = dayMap.get(s);
11791176

11801177
if (integer == null) {
@@ -1443,10 +1440,7 @@ public Date getTimeAfter(Date afterTime) {
14431440
daysToAdd = dow + (7 - cDow);
14441441
}
14451442

1446-
boolean dayShifted = false;
1447-
if (daysToAdd > 0) {
1448-
dayShifted = true;
1449-
}
1443+
boolean dayShifted = daysToAdd > 0;
14501444

14511445
day += daysToAdd;
14521446
int weekOfMonth = day / 7;
@@ -1594,7 +1588,7 @@ public Date getTimeAfter(Date afterTime) {
15941588
* @param cal the calendar to operate on
15951589
* @param hour the hour to set
15961590
*/
1597-
protected void setCalendarHour(Calendar cal, int hour) {
1591+
private void setCalendarHour(Calendar cal, int hour) {
15981592
cal.set(java.util.Calendar.HOUR_OF_DAY, hour);
15991593
if (cal.get(java.util.Calendar.HOUR_OF_DAY) != hour && hour != 24) {
16001594
cal.set(java.util.Calendar.HOUR_OF_DAY, hour + 1);
@@ -1619,11 +1613,11 @@ public Date getFinalFireTime() {
16191613
return null;
16201614
}
16211615

1622-
protected boolean isLeapYear(int year) {
1616+
private boolean isLeapYear(int year) {
16231617
return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
16241618
}
16251619

1626-
protected int getLastDayOfMonth(int monthNum, int year) {
1620+
private int getLastDayOfMonth(int monthNum, int year) {
16271621

16281622
switch (monthNum) {
16291623
case 1:

0 commit comments

Comments
 (0)