Skip to content

Commit

Permalink
Merge pull request #26 from lunasaw/2.5.8
Browse files Browse the repository at this point in the history
2.5.8 版本升级,code clean up
  • Loading branch information
lunasaw authored Apr 10, 2024
2 parents ec6f8b3 + 3aad8a6 commit f35e13c
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 149 deletions.
23 changes: 14 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.github.lunasaw</groupId>
<artifactId>luna-common</artifactId>
<name>luna-common</name>
<version>2.5.7</version>
<version>2.5.8</version>
<description>common is project which contains common utils</description>
<url>https://github.com/lunasaw/luna-common</url>

Expand All @@ -21,14 +21,14 @@
<!--dependencies-->
<commons-collections4.version>4.4</commons-collections4.version>
<commons-lang3.version>3.14.0</commons-lang3.version>
<commons-codec.version>1.16.0</commons-codec.version>
<commons-io.version>2.15.1</commons-io.version>
<httpclient-5.version>5.2.1</httpclient-5.version>
<commons-codec.version>1.16.1</commons-codec.version>
<commons-io.version>2.16.1</commons-io.version>
<httpclient-5.version>5.3.1</httpclient-5.version>
<guava.version>32.1.3-jre</guava.version>
<fast-json.version>2.0.26</fast-json.version>
<fast-json2.version>2.0.48</fast-json2.version>
<oshi.version>6.4.9</oshi.version>
<junit.version>4.13.2</junit.version>
<lombok.version>1.18.30</lombok.version>
<lombok.version>1.18.32</lombok.version>
<validation-api.version>3.0.2</validation-api.version>
<slf4j-simple.version>2.0.9</slf4j-simple.version>
</properties>
Expand Down Expand Up @@ -102,9 +102,9 @@
<version>${oshi.version}</version> <!-- 这个版本不要随便升级,和JNA的环境有关 -->
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fast-json.version}</version>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>${fast-json2.version}</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
Expand All @@ -116,6 +116,11 @@
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.5</version> <!-- 最新版本 -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/luna/common/cache/SimpleGuavaCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.google.common.cache.*;
import com.google.common.collect.ImmutableMap;

Expand Down Expand Up @@ -66,7 +67,8 @@ public void put(K key, V value) {
cache.put(key, value);
}

public void invalidate(K... key) {
@SafeVarargs
public final void invalidate(K... key) {
Arrays.stream(key).forEach(cache::invalidate);
}

Expand Down Expand Up @@ -102,7 +104,8 @@ public void refresh(K key) {
cache.refresh(key);
}

public ImmutableMap<K, V> getAllPresent(K... keys) {
@SafeVarargs
public final ImmutableMap<K, V> getAllPresent(K... keys) {
return cache.getAllPresent(Arrays.stream(keys).distinct().collect(Collectors.toList()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ public static int getBitInt(int data, int length, int shift) {
* @return int
*/
public static int getFirstTerm(int solarYear, int solarMonth) {
long times = 31556925974L * (solarYear - 1900)
+ CalendaristConstants.SOLAR_TERM_INFO[(solarMonth - 1) * 2] * 60000L + (0L);
long times = 31556925974L * (solarYear - 1900) + CalendaristConstants.SOLAR_TERM_INFO[(solarMonth - 1) * 2] * 60000L;
Date offDate = new Date(times - 2208549300000L);
// 1、取得本地时间:
Calendar cal = CalendaristUtils.getCalendarInstance();
Expand Down
168 changes: 81 additions & 87 deletions src/main/java/com/luna/common/cron/CronExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,20 @@
public final class CronExpression implements Serializable, Cloneable {

public static final int MAX_YEAR = Calendar.getInstance().get(Calendar.YEAR) + 100;
protected static final int SECOND = 0;
protected static final int MINUTE = 1;
protected static final int HOUR = 2;
protected static final int DAY_OF_MONTH = 3;
protected static final int MONTH = 4;
protected static final int DAY_OF_WEEK = 5;
protected static final int YEAR = 6;
protected static final int ALL_SPEC_INT = 99; // '*'
protected static final int NO_SPEC_INT = 98; // '?'
protected static final Integer ALL_SPEC = ALL_SPEC_INT;
protected static final Integer NO_SPEC = NO_SPEC_INT;

protected static final Map<String, Integer> monthMap = new HashMap<String, Integer>(20);
protected static final Map<String, Integer> dayMap = new HashMap<String, Integer>(60);
private static final int SECOND = 0;
private static final int MINUTE = 1;
private static final int HOUR = 2;
private static final int DAY_OF_MONTH = 3;
private static final int MONTH = 4;
private static final int DAY_OF_WEEK = 5;
private static final int YEAR = 6;
private static final int ALL_SPEC_INT = 99; // '*'
private static final int NO_SPEC_INT = 98; // '?'
private static final Integer ALL_SPEC = ALL_SPEC_INT;
private static final Integer NO_SPEC = NO_SPEC_INT;

private static final Map<String, Integer> monthMap = new HashMap<String, Integer>(20);
private static final Map<String, Integer> dayMap = new HashMap<String, Integer>(60);
private static final long serialVersionUID = 12423409423L;

static {
Expand All @@ -230,20 +230,20 @@ public final class CronExpression implements Serializable, Cloneable {
}

private final String cronExpression;
protected transient TreeSet<Integer> seconds;
protected transient TreeSet<Integer> minutes;
protected transient TreeSet<Integer> hours;
protected transient TreeSet<Integer> daysOfMonth;
protected transient TreeSet<Integer> months;
protected transient TreeSet<Integer> daysOfWeek;
protected transient TreeSet<Integer> years;

protected transient boolean lastdayOfWeek = false;
protected transient int nthdayOfWeek = 0;
protected transient boolean lastdayOfMonth = false;
protected transient boolean nearestWeekday = false;
protected transient int lastdayOffset = 0;
protected transient boolean expressionParsed = false;
private transient TreeSet<Integer> seconds;
private transient TreeSet<Integer> minutes;
private transient TreeSet<Integer> hours;
private transient TreeSet<Integer> daysOfMonth;
private transient TreeSet<Integer> months;
private transient TreeSet<Integer> daysOfWeek;
private transient TreeSet<Integer> years;

private transient boolean lastdayOfWeek = false;
private transient int nthdayOfWeek = 0;
private transient boolean lastdayOfMonth = false;
private transient boolean nearestWeekday = false;
private transient int lastdayOffset = 0;
private transient boolean expressionParsed = false;
private TimeZone timeZone = null;

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

Date date = new Date();
System.out.println(date.toString());
System.out.println(date);
for (int i = 0; i < 10; i++) {
date = cronExpression.getNextValidTimeAfter(date);
System.out.println(date.toString());
Expand Down Expand Up @@ -436,7 +436,7 @@ public String toString() {
return cronExpression;
}

protected void buildExpression(String expression) throws ParseException {
private void buildExpression(String expression) throws ParseException {
expressionParsed = true;

try {
Expand Down Expand Up @@ -518,11 +518,11 @@ protected void buildExpression(String expression) throws ParseException {
throw pe;
} catch (Exception e) {
throw new ParseException("Illegal cron expression format ("
+ e.toString() + ")", 0);
+ e + ")", 0);
}
}

protected int storeExpressionVals(int pos, String s, int type)
private int storeExpressionVals(int pos, String s, int type)
throws ParseException {

int incr = 0;
Expand Down Expand Up @@ -717,7 +717,7 @@ private void checkIncrementRange(int incr, int type, int idxPos) throws ParseExc
}
}

protected int checkNext(int pos, String s, int val, int type)
private int checkNext(int pos, String s, int val, int type)
throws ParseException {

int end = -1;
Expand Down Expand Up @@ -859,46 +859,45 @@ public String getCronExpression() {
}

public String getExpressionSummary() {
StringBuilder buf = new StringBuilder();

buf.append("seconds: ");
buf.append(getExpressionSetSummary(seconds));
buf.append("\n");
buf.append("minutes: ");
buf.append(getExpressionSetSummary(minutes));
buf.append("\n");
buf.append("hours: ");
buf.append(getExpressionSetSummary(hours));
buf.append("\n");
buf.append("daysOfMonth: ");
buf.append(getExpressionSetSummary(daysOfMonth));
buf.append("\n");
buf.append("months: ");
buf.append(getExpressionSetSummary(months));
buf.append("\n");
buf.append("daysOfWeek: ");
buf.append(getExpressionSetSummary(daysOfWeek));
buf.append("\n");
buf.append("lastdayOfWeek: ");
buf.append(lastdayOfWeek);
buf.append("\n");
buf.append("nearestWeekday: ");
buf.append(nearestWeekday);
buf.append("\n");
buf.append("NthDayOfWeek: ");
buf.append(nthdayOfWeek);
buf.append("\n");
buf.append("lastdayOfMonth: ");
buf.append(lastdayOfMonth);
buf.append("\n");
buf.append("years: ");
buf.append(getExpressionSetSummary(years));
buf.append("\n");

return buf.toString();
String buf = "seconds: " +
getExpressionSetSummary(seconds) +
"\n" +
"minutes: " +
getExpressionSetSummary(minutes) +
"\n" +
"hours: " +
getExpressionSetSummary(hours) +
"\n" +
"daysOfMonth: " +
getExpressionSetSummary(daysOfMonth) +
"\n" +
"months: " +
getExpressionSetSummary(months) +
"\n" +
"daysOfWeek: " +
getExpressionSetSummary(daysOfWeek) +
"\n" +
"lastdayOfWeek: " +
lastdayOfWeek +
"\n" +
"nearestWeekday: " +
nearestWeekday +
"\n" +
"NthDayOfWeek: " +
nthdayOfWeek +
"\n" +
"lastdayOfMonth: " +
lastdayOfMonth +
"\n" +
"years: " +
getExpressionSetSummary(years) +
"\n";

return buf;
}

protected String getExpressionSetSummary(java.util.Set<Integer> set) {
private String getExpressionSetSummary(java.util.Set<Integer> set) {

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

protected String getExpressionSetSummary(java.util.ArrayList<Integer> list) {
private String getExpressionSetSummary(java.util.ArrayList<Integer> list) {

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

protected int skipWhiteSpace(int i, String s) {
private int skipWhiteSpace(int i, String s) {
for (; i < s.length() && (s.charAt(i) == ' ' || s.charAt(i) == '\t'); i++) {
;
}

return i;
}

protected int findNextWhiteSpace(int i, String s) {
private int findNextWhiteSpace(int i, String s) {
for (; i < s.length() && (s.charAt(i) != ' ' || s.charAt(i) != '\t'); i++) {
;
}

return i;
}

protected void addToSet(int val, int end, int incr, int type)
private void addToSet(int val, int end, int incr, int type)
throws ParseException {

TreeSet<Integer> set = getSet(type);
Expand Down Expand Up @@ -1134,7 +1131,7 @@ TreeSet<Integer> getSet(int type) {
}
}

protected ValueSet getValue(int v, String s, int i) {
private ValueSet getValue(int v, String s, int i) {
char c = s.charAt(i);
StringBuilder s1 = new StringBuilder(String.valueOf(v));
while (c >= '0' && c <= '9') {
Expand All @@ -1152,13 +1149,13 @@ protected ValueSet getValue(int v, String s, int i) {
return val;
}

protected int getNumericValue(String s, int i) {
private int getNumericValue(String s, int i) {
int endOfVal = findNextWhiteSpace(i, s);
String val = s.substring(i, endOfVal);
return Integer.parseInt(val);
}

protected int getMonthNumber(String s) {
private int getMonthNumber(String s) {
Integer integer = monthMap.get(s);

if (integer == null) {
Expand All @@ -1174,7 +1171,7 @@ protected int getMonthNumber(String s) {
//
////////////////////////////////////////////////////////////////////////////

protected int getDayOfWeekNumber(String s) {
private int getDayOfWeekNumber(String s) {
Integer integer = dayMap.get(s);

if (integer == null) {
Expand Down Expand Up @@ -1443,10 +1440,7 @@ public Date getTimeAfter(Date afterTime) {
daysToAdd = dow + (7 - cDow);
}

boolean dayShifted = false;
if (daysToAdd > 0) {
dayShifted = true;
}
boolean dayShifted = daysToAdd > 0;

day += daysToAdd;
int weekOfMonth = day / 7;
Expand Down Expand Up @@ -1594,7 +1588,7 @@ public Date getTimeAfter(Date afterTime) {
* @param cal the calendar to operate on
* @param hour the hour to set
*/
protected void setCalendarHour(Calendar cal, int hour) {
private void setCalendarHour(Calendar cal, int hour) {
cal.set(java.util.Calendar.HOUR_OF_DAY, hour);
if (cal.get(java.util.Calendar.HOUR_OF_DAY) != hour && hour != 24) {
cal.set(java.util.Calendar.HOUR_OF_DAY, hour + 1);
Expand All @@ -1619,11 +1613,11 @@ public Date getFinalFireTime() {
return null;
}

protected boolean isLeapYear(int year) {
private boolean isLeapYear(int year) {
return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
}

protected int getLastDayOfMonth(int monthNum, int year) {
private int getLastDayOfMonth(int monthNum, int year) {

switch (monthNum) {
case 1:
Expand Down
Loading

0 comments on commit f35e13c

Please sign in to comment.