Skip to content

Commit fe1b374

Browse files
authored
Merge pull request #1256 from bcode2/quartz-2.4.x-fix-redundant-if-statements
refactor: simplify if/else statements
2 parents 2ab89e9 + 2b3ee3d commit fe1b374

File tree

13 files changed

+26
-78
lines changed

13 files changed

+26
-78
lines changed

quartz/src/main/java/org/quartz/CronExpression.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,10 +1433,7 @@ public Date getTimeAfter(Date afterTime) {
14331433
daysToAdd = dow + (7 - cDow);
14341434
}
14351435

1436-
boolean dayShifted = false;
1437-
if (daysToAdd > 0) {
1438-
dayShifted = true;
1439-
}
1436+
boolean dayShifted = daysToAdd > 0;
14401437

14411438
day += daysToAdd;
14421439
int weekOfMonth = day / 7;

quartz/src/main/java/org/quartz/impl/JobDetailImpl.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,8 @@ public boolean equals(Object obj) {
423423

424424
if(other.getKey() == null || getKey() == null)
425425
return false;
426-
427-
if (!other.getKey().equals(getKey())) {
428-
return false;
429-
}
430-
431-
return true;
426+
427+
return other.getKey().equals(getKey());
432428
}
433429

434430
@Override

quartz/src/main/java/org/quartz/impl/calendar/BaseCalendar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public boolean isTimeIncluded(long timeStamp) {
173173
}
174174

175175
if (baseCalendar != null) {
176-
if (!baseCalendar.isTimeIncluded(timeStamp)) { return false; }
176+
return baseCalendar.isTimeIncluded(timeStamp);
177177
}
178178

179179
return true;

quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,10 +2361,7 @@ public void resumeTrigger(Connection conn,
23612361
return;
23622362
}
23632363

2364-
boolean blocked = false;
2365-
if(STATE_PAUSED_BLOCKED.equals(status.getStatus())) {
2366-
blocked = true;
2367-
}
2364+
boolean blocked = STATE_PAUSED_BLOCKED.equals(status.getStatus());
23682365

23692366
String newState = checkBlockedState(conn, status.getJobKey(), STATE_WAITING);
23702367

quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -775,11 +775,7 @@ public boolean jobExists(Connection conn, JobKey jobKey)
775775
ps.setString(1, jobKey.getName());
776776
ps.setString(2, jobKey.getGroup());
777777
rs = ps.executeQuery();
778-
if (rs.next()) {
779-
return true;
780-
} else {
781-
return false;
782-
}
778+
return rs.next();
783779
} finally {
784780
closeResultSet(rs);
785781
closeStatement(ps);
@@ -1288,11 +1284,7 @@ public boolean triggerExists(Connection conn, TriggerKey triggerKey) throws SQLE
12881284
ps.setString(2, triggerKey.getGroup());
12891285
rs = ps.executeQuery();
12901286

1291-
if (rs.next()) {
1292-
return true;
1293-
} else {
1294-
return false;
1295-
}
1287+
return rs.next();
12961288
} finally {
12971289
closeResultSet(rs);
12981290
closeStatement(ps);
@@ -2304,11 +2296,7 @@ public boolean calendarExists(Connection conn, String calendarName)
23042296
ps.setString(1, calendarName);
23052297
rs = ps.executeQuery();
23062298

2307-
if (rs.next()) {
2308-
return true;
2309-
} else {
2310-
return false;
2311-
}
2299+
return rs.next();
23122300
} finally {
23132301
closeResultSet(rs);
23142302
closeStatement(ps);
@@ -2375,11 +2363,7 @@ public boolean calendarIsReferenced(Connection conn, String calendarName)
23752363
ps.setString(1, calendarName);
23762364
rs = ps.executeQuery();
23772365

2378-
if (rs.next()) {
2379-
return true;
2380-
} else {
2381-
return false;
2382-
}
2366+
return rs.next();
23832367
} finally {
23842368
closeResultSet(rs);
23852369
closeStatement(ps);

quartz/src/main/java/org/quartz/impl/matchers/AndMatcher.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,8 @@ public boolean equals(Object obj) {
8686
} else if (!leftOperand.equals(other.leftOperand))
8787
return false;
8888
if (rightOperand == null) {
89-
if (other.rightOperand != null)
90-
return false;
91-
} else if (!rightOperand.equals(other.rightOperand))
92-
return false;
93-
return true;
89+
return other.rightOperand == null;
90+
} else return rightOperand.equals(other.rightOperand);
9491
}
9592

9693
}

quartz/src/main/java/org/quartz/impl/matchers/KeyMatcher.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,8 @@ public boolean equals(Object obj) {
7070
return false;
7171
KeyMatcher<?> other = (KeyMatcher<?>) obj;
7272
if (compareTo == null) {
73-
if (other.compareTo != null)
74-
return false;
75-
} else if (!compareTo.equals(other.compareTo))
76-
return false;
77-
return true;
73+
return other.compareTo == null;
74+
} else return compareTo.equals(other.compareTo);
7875
}
7976

8077
}

quartz/src/main/java/org/quartz/impl/matchers/NotMatcher.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ public boolean equals(Object obj) {
7272
return false;
7373
NotMatcher<?> other = (NotMatcher<?>) obj;
7474
if (operand == null) {
75-
if (other.operand != null)
76-
return false;
77-
} else if (!operand.equals(other.operand))
78-
return false;
79-
return true;
75+
return other.operand == null;
76+
} else return operand.equals(other.operand);
8077
}
8178
}

quartz/src/main/java/org/quartz/impl/matchers/OrMatcher.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,8 @@ public boolean equals(Object obj) {
8686
} else if (!leftOperand.equals(other.leftOperand))
8787
return false;
8888
if (rightOperand == null) {
89-
if (other.rightOperand != null)
90-
return false;
91-
} else if (!rightOperand.equals(other.rightOperand))
92-
return false;
93-
return true;
89+
return other.rightOperand == null;
90+
} else return rightOperand.equals(other.rightOperand);
9491
}
9592

9693
}

quartz/src/main/java/org/quartz/impl/matchers/StringMatcher.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,8 @@ public boolean equals(Object obj) {
115115
} else if (!compareTo.equals(other.compareTo))
116116
return false;
117117
if (compareWith == null) {
118-
if (other.compareWith != null)
119-
return false;
120-
} else if (!compareWith.equals(other.compareWith))
121-
return false;
122-
return true;
118+
return other.compareWith == null;
119+
} else return compareWith.equals(other.compareWith);
123120
}
124121

125122
public String getCompareToValue() {

quartz/src/main/java/org/quartz/simpl/RAMJobStore.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,9 +1420,7 @@ protected boolean applyMisfire(TriggerWrapper tw) {
14201420
synchronized (lock) {
14211421
timeTriggers.remove(tw);
14221422
}
1423-
} else if (tnft.equals(tw.trigger.getNextFireTime())) {
1424-
return false;
1425-
}
1423+
} else return !tnft.equals(tw.trigger.getNextFireTime());
14261424

14271425
return true;
14281426
}
@@ -1794,9 +1792,7 @@ class JobWrapper {
17941792
public boolean equals(Object obj) {
17951793
if (obj instanceof JobWrapper) {
17961794
JobWrapper jw = (JobWrapper) obj;
1797-
if (jw.key.equals(this.key)) {
1798-
return true;
1799-
}
1795+
return jw.key.equals(this.key);
18001796
}
18011797

18021798
return false;
@@ -1847,9 +1843,7 @@ class TriggerWrapper {
18471843
public boolean equals(Object obj) {
18481844
if (obj instanceof TriggerWrapper) {
18491845
TriggerWrapper tw = (TriggerWrapper) obj;
1850-
if (tw.key.equals(this.key)) {
1851-
return true;
1852-
}
1846+
return tw.key.equals(this.key);
18531847
}
18541848

18551849
return false;

quartz/src/main/java/org/quartz/utils/Key.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,8 @@ public boolean equals(Object obj) {
136136
} else if (!group.equals(other.group))
137137
return false;
138138
if (name == null) {
139-
if (other.name != null)
140-
return false;
141-
} else if (!name.equals(other.name))
142-
return false;
143-
return true;
139+
return other.name == null;
140+
} else return name.equals(other.name);
144141
}
145142

146143
public int compareTo(Key<T> o) {

quartz/src/main/java/org/quartz/xml/XMLSchedulingDataProcessor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,10 +1059,8 @@ protected void scheduleJobs(Scheduler sched)
10591059

10601060

10611061
if(dupeJ != null || detail.isDurable()) {
1062-
if (triggersOfJob != null && !triggersOfJob.isEmpty())
1063-
sched.addJob(detail, true, true); // add the job regardless is durable or not b/c we have trigger to add
1064-
else
1065-
sched.addJob(detail, true, false); // add the job only if a replacement or durable, else exception will throw!
1062+
// add the job only if a replacement or durable, else exception will throw!
1063+
sched.addJob(detail, true, triggersOfJob != null && !triggersOfJob.isEmpty()); // add the job regardless is durable or not b/c we have trigger to add
10661064
}
10671065
else {
10681066
boolean addJobWithFirstSchedule = true;

0 commit comments

Comments
 (0)