Skip to content

Commit

Permalink
Merge pull request #1197 from bcode2/refactoring_code_2.5_branch
Browse files Browse the repository at this point in the history
Refactoring code and apply some language migration in branch 2.5.x
  • Loading branch information
jhouserizer authored Oct 15, 2024
2 parents 4602f64 + fec73e4 commit 492b3d5
Show file tree
Hide file tree
Showing 127 changed files with 1,102 additions and 1,447 deletions.
16 changes: 8 additions & 8 deletions quartz/src/main/java/org/quartz/CalendarIntervalTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface CalendarIntervalTrigger extends Trigger {
* fired now by <code>Scheduler</code>.
* </p>
*/
public static final int MISFIRE_INSTRUCTION_FIRE_ONCE_NOW = 1;
int MISFIRE_INSTRUCTION_FIRE_ONCE_NOW = 1;
/**
* <p>
* Instructs the <code>{@link Scheduler}</code> that upon a mis-fire
Expand All @@ -68,12 +68,12 @@ public interface CalendarIntervalTrigger extends Trigger {
* but it does not want to be fired now.
* </p>
*/
public static final int MISFIRE_INSTRUCTION_DO_NOTHING = 2;
int MISFIRE_INSTRUCTION_DO_NOTHING = 2;

/**
* <p>Get the interval unit - the time unit on with the interval applies.</p>
*/
public IntervalUnit getRepeatIntervalUnit();
IntervalUnit getRepeatIntervalUnit();

/**
* <p>
Expand All @@ -82,15 +82,15 @@ public interface CalendarIntervalTrigger extends Trigger {
* next trigger repeat.
* </p>
*/
public int getRepeatInterval();
int getRepeatInterval();

/**
* <p>
* Get the number of times the <code>DateIntervalTrigger</code> has already
* fired.
* </p>
*/
public int getTimesTriggered();
int getTimesTriggered();

/**
* <p>
Expand All @@ -102,7 +102,7 @@ public interface CalendarIntervalTrigger extends Trigger {
* If null, the system default TimeZone will be used.
* </p>
*/
public TimeZone getTimeZone();
TimeZone getTimeZone();


/**
Expand Down Expand Up @@ -131,7 +131,7 @@ public interface CalendarIntervalTrigger extends Trigger {
* @see #getStartTime()
* @see #getTimeZone()
*/
public boolean isPreserveHourOfDayAcrossDaylightSavings();
boolean isPreserveHourOfDayAcrossDaylightSavings();

/**
* If intervals are a day or greater, and
Expand All @@ -153,7 +153,7 @@ public interface CalendarIntervalTrigger extends Trigger {
*
* @see #isPreserveHourOfDayAcrossDaylightSavings()
*/
public boolean isSkipDayIfHourDoesNotExist();
boolean isSkipDayIfHourDoesNotExist();


TriggerBuilder<CalendarIntervalTrigger> getTriggerBuilder();
Expand Down
41 changes: 18 additions & 23 deletions quartz/src/main/java/org/quartz/CronExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ public final class CronExpression implements Serializable, Cloneable {
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);
protected static final Map<String, Integer> monthMap = new HashMap<>(20);
protected static final Map<String, Integer> dayMap = new HashMap<>(60);
static {
monthMap.put("JAN", 0);
monthMap.put("FEB", 1);
Expand Down Expand Up @@ -450,28 +450,28 @@ protected void buildExpression(String expression) throws ParseException {
try {

if (seconds == null) {
seconds = new TreeSet<Integer>();
seconds = new TreeSet<>();
}
if (minutes == null) {
minutes = new TreeSet<Integer>();
minutes = new TreeSet<>();
}
if (hours == null) {
hours = new TreeSet<Integer>();
hours = new TreeSet<>();
}
if (daysOfMonth == null) {
daysOfMonth = new TreeSet<Integer>();
daysOfMonth = new TreeSet<>();
}
if (nearestWeekdays == null) {
nearestWeekdays = new TreeSet<Integer>();
nearestWeekdays = new TreeSet<>();
}
if (months == null) {
months = new TreeSet<Integer>();
months = new TreeSet<>();
}
if (daysOfWeek == null) {
daysOfWeek = new TreeSet<Integer>();
daysOfWeek = new TreeSet<>();
}
if (years == null) {
years = new TreeSet<Integer>();
years = new TreeSet<>();
}

int exprOn = SECOND;
Expand Down Expand Up @@ -525,7 +525,7 @@ protected void buildExpression(String expression) throws ParseException {
throw pe;
} catch (Exception e) {
throw new ParseException("Illegal cron expression format ("
+ e.toString() + ")", 0);
+ e + ")", 0);
}
}

Expand Down Expand Up @@ -958,15 +958,13 @@ protected String getExpressionSetSummary(java.util.ArrayList<Integer> list) {

protected 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) {
for (; i < s.length() && (s.charAt(i) != ' ' || s.charAt(i) != '\t'); i++) {
;
}

return i;
Expand Down Expand Up @@ -1205,7 +1203,7 @@ public Date getTimeAfter(Date afterTime) {

// get second.................................................
st = seconds.tailSet(sec);
if (st != null && st.size() != 0) {
if (st != null && !st.isEmpty()) {
sec = st.first();
} else {
sec = seconds.first();
Expand All @@ -1220,7 +1218,7 @@ public Date getTimeAfter(Date afterTime) {

// get minute.................................................
st = minutes.tailSet(min);
if (st != null && st.size() != 0) {
if (st != null && !st.isEmpty()) {
t = min;
min = st.first();
} else {
Expand All @@ -1241,7 +1239,7 @@ public Date getTimeAfter(Date afterTime) {

// get hour...................................................
st = hours.tailSet(hr);
if (st != null && st.size() != 0) {
if (st != null && !st.isEmpty()) {
t = hr;
hr = st.first();
} else {
Expand Down Expand Up @@ -1381,10 +1379,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 @@ -1418,7 +1413,7 @@ public Date getTimeAfter(Date afterTime) {
int dow = daysOfWeek.first(); // desired
// d-o-w
st = daysOfWeek.tailSet(cDow);
if (st != null && st.size() > 0) {
if (st != null && !st.isEmpty()) {
dow = st.first();
}

Expand Down Expand Up @@ -1472,7 +1467,7 @@ public Date getTimeAfter(Date afterTime) {

// get month...................................................
st = months.tailSet(mon);
if (st != null && st.size() != 0) {
if (st != null && !st.isEmpty()) {
t = mon;
mon = st.first();
} else {
Expand All @@ -1499,7 +1494,7 @@ public Date getTimeAfter(Date afterTime) {

// get year...................................................
st = years.tailSet(year);
if (st != null && st.size() != 0) {
if (st != null && !st.isEmpty()) {
t = year;
year = st.first();
} else {
Expand Down
10 changes: 5 additions & 5 deletions quartz/src/main/java/org/quartz/CronScheduleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
*/
public class CronScheduleBuilder extends ScheduleBuilder<CronTrigger> {

private CronExpression cronExpression;
private final CronExpression cronExpression;
private int misfireInstruction = CronTrigger.MISFIRE_INSTRUCTION_SMART_POLICY;

protected CronScheduleBuilder(CronExpression cronExpression) {
Expand Down Expand Up @@ -210,13 +210,13 @@ public static CronScheduleBuilder atHourAndMinuteOnGivenDaysOfWeek(
DateBuilder.validateHour(hour);
DateBuilder.validateMinute(minute);

String cronExpression = String.format("0 %d %d ? * %d", minute, hour,
daysOfWeek[0]);
StringBuilder cronExpression = new StringBuilder(String.format("0 %d %d ? * %d", minute, hour,
daysOfWeek[0]));

for (int i = 1; i < daysOfWeek.length; i++)
cronExpression = cronExpression + "," + daysOfWeek[i];
cronExpression.append(",").append(daysOfWeek[i]);

return cronScheduleNoParseException(cronExpression);
return cronScheduleNoParseException(cronExpression.toString());
}

/**
Expand Down
12 changes: 6 additions & 6 deletions quartz/src/main/java/org/quartz/CronTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
*/
public interface CronTrigger extends Trigger {

public static final long serialVersionUID = -8644953146451592766L;
long serialVersionUID = -8644953146451592766L;

/**
* <p>
Expand All @@ -180,7 +180,7 @@ public interface CronTrigger extends Trigger {
* by <code>Scheduler</code>.
* </p>
*/
public static final int MISFIRE_INSTRUCTION_FIRE_ONCE_NOW = 1;
int MISFIRE_INSTRUCTION_FIRE_ONCE_NOW = 1;

/**
* <p>
Expand All @@ -191,19 +191,19 @@ public interface CronTrigger extends Trigger {
* but it does not want to be fired now.
* </p>
*/
public static final int MISFIRE_INSTRUCTION_DO_NOTHING = 2;
int MISFIRE_INSTRUCTION_DO_NOTHING = 2;

public String getCronExpression();
String getCronExpression();

/**
* <p>
* Returns the time zone for which the <code>cronExpression</code> of
* this <code>CronTrigger</code> will be resolved.
* </p>
*/
public TimeZone getTimeZone();
TimeZone getTimeZone();

public String getExpressionSummary();
String getExpressionSummary();

TriggerBuilder<CronTrigger> getTriggerBuilder();
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ public class DailyTimeIntervalScheduleBuilder extends ScheduleBuilder<DailyTimeI
public static final Set<Integer> SATURDAY_AND_SUNDAY;

static {
Set<Integer> t = new HashSet<Integer>(7);
Set<Integer> t = new HashSet<>(7);
for(int i=Calendar.SUNDAY; i <= Calendar.SATURDAY; i++)
t.add(i);
ALL_DAYS_OF_THE_WEEK = Collections.unmodifiableSet(t);

t = new HashSet<Integer>(5);
t = new HashSet<>(5);
for(int i=Calendar.MONDAY; i <= Calendar.FRIDAY; i++)
t.add(i);
MONDAY_THROUGH_FRIDAY = Collections.unmodifiableSet(t);

t = new HashSet<Integer>(2);
t = new HashSet<>(2);
t.add(Calendar.SUNDAY);
t.add(Calendar.SATURDAY);
SATURDAY_AND_SUNDAY = Collections.unmodifiableSet(t);
Expand Down Expand Up @@ -233,7 +233,7 @@ public DailyTimeIntervalScheduleBuilder withIntervalInHours(int intervalInHours)
* @return the updated DailyTimeIntervalScheduleBuilder
*/
public DailyTimeIntervalScheduleBuilder onDaysOfTheWeek(Set<Integer> onDaysOfWeek) {
if(onDaysOfWeek == null || onDaysOfWeek.size() == 0)
if(onDaysOfWeek == null || onDaysOfWeek.isEmpty())
throw new IllegalArgumentException("Days of week must be an non-empty set.");
for (Integer day : onDaysOfWeek)
if (!ALL_DAYS_OF_THE_WEEK.contains(day))
Expand All @@ -251,7 +251,7 @@ public DailyTimeIntervalScheduleBuilder onDaysOfTheWeek(Set<Integer> onDaysOfWee
* @return the updated DailyTimeIntervalScheduleBuilder
*/
public DailyTimeIntervalScheduleBuilder onDaysOfTheWeek(Integer ... onDaysOfWeek) {
Set<Integer> daysAsSet = new HashSet<Integer>(12);
Set<Integer> daysAsSet = new HashSet<>(12);
Collections.addAll(daysAsSet, onDaysOfWeek);
return onDaysOfTheWeek(daysAsSet);
}
Expand Down
Loading

0 comments on commit 492b3d5

Please sign in to comment.