190
190
public final class CronExpression implements Serializable , Cloneable {
191
191
192
192
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 );
207
207
private static final long serialVersionUID = 12423409423L ;
208
208
209
209
static {
@@ -230,20 +230,20 @@ public final class CronExpression implements Serializable, Cloneable {
230
230
}
231
231
232
232
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 ;
247
247
private TimeZone timeZone = null ;
248
248
249
249
/**
@@ -319,7 +319,7 @@ public static void main(String[] args) throws ParseException {
319
319
CronExpression cronExpression = new CronExpression (cronStr );
320
320
321
321
Date date = new Date ();
322
- System .out .println (date . toString () );
322
+ System .out .println (date );
323
323
for (int i = 0 ; i < 10 ; i ++) {
324
324
date = cronExpression .getNextValidTimeAfter (date );
325
325
System .out .println (date .toString ());
@@ -436,7 +436,7 @@ public String toString() {
436
436
return cronExpression ;
437
437
}
438
438
439
- protected void buildExpression (String expression ) throws ParseException {
439
+ private void buildExpression (String expression ) throws ParseException {
440
440
expressionParsed = true ;
441
441
442
442
try {
@@ -518,11 +518,11 @@ protected void buildExpression(String expression) throws ParseException {
518
518
throw pe ;
519
519
} catch (Exception e ) {
520
520
throw new ParseException ("Illegal cron expression format ("
521
- + e . toString () + ")" , 0 );
521
+ + e + ")" , 0 );
522
522
}
523
523
}
524
524
525
- protected int storeExpressionVals (int pos , String s , int type )
525
+ private int storeExpressionVals (int pos , String s , int type )
526
526
throws ParseException {
527
527
528
528
int incr = 0 ;
@@ -717,7 +717,7 @@ private void checkIncrementRange(int incr, int type, int idxPos) throws ParseExc
717
717
}
718
718
}
719
719
720
- protected int checkNext (int pos , String s , int val , int type )
720
+ private int checkNext (int pos , String s , int val , int type )
721
721
throws ParseException {
722
722
723
723
int end = -1 ;
@@ -859,46 +859,45 @@ public String getCronExpression() {
859
859
}
860
860
861
861
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 " );
897
862
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 ;
899
898
}
900
899
901
- protected String getExpressionSetSummary (java .util .Set <Integer > set ) {
900
+ private String getExpressionSetSummary (java .util .Set <Integer > set ) {
902
901
903
902
if (set .contains (NO_SPEC )) {
904
903
return "?" ;
@@ -924,7 +923,7 @@ protected String getExpressionSetSummary(java.util.Set<Integer> set) {
924
923
return buf .toString ();
925
924
}
926
925
927
- protected String getExpressionSetSummary (java .util .ArrayList <Integer > list ) {
926
+ private String getExpressionSetSummary (java .util .ArrayList <Integer > list ) {
928
927
929
928
if (list .contains (NO_SPEC )) {
930
929
return "?" ;
@@ -950,23 +949,21 @@ protected String getExpressionSetSummary(java.util.ArrayList<Integer> list) {
950
949
return buf .toString ();
951
950
}
952
951
953
- protected int skipWhiteSpace (int i , String s ) {
952
+ private int skipWhiteSpace (int i , String s ) {
954
953
for (; i < s .length () && (s .charAt (i ) == ' ' || s .charAt (i ) == '\t' ); i ++) {
955
- ;
956
954
}
957
955
958
956
return i ;
959
957
}
960
958
961
- protected int findNextWhiteSpace (int i , String s ) {
959
+ private int findNextWhiteSpace (int i , String s ) {
962
960
for (; i < s .length () && (s .charAt (i ) != ' ' || s .charAt (i ) != '\t' ); i ++) {
963
- ;
964
961
}
965
962
966
963
return i ;
967
964
}
968
965
969
- protected void addToSet (int val , int end , int incr , int type )
966
+ private void addToSet (int val , int end , int incr , int type )
970
967
throws ParseException {
971
968
972
969
TreeSet <Integer > set = getSet (type );
@@ -1134,7 +1131,7 @@ TreeSet<Integer> getSet(int type) {
1134
1131
}
1135
1132
}
1136
1133
1137
- protected ValueSet getValue (int v , String s , int i ) {
1134
+ private ValueSet getValue (int v , String s , int i ) {
1138
1135
char c = s .charAt (i );
1139
1136
StringBuilder s1 = new StringBuilder (String .valueOf (v ));
1140
1137
while (c >= '0' && c <= '9' ) {
@@ -1152,13 +1149,13 @@ protected ValueSet getValue(int v, String s, int i) {
1152
1149
return val ;
1153
1150
}
1154
1151
1155
- protected int getNumericValue (String s , int i ) {
1152
+ private int getNumericValue (String s , int i ) {
1156
1153
int endOfVal = findNextWhiteSpace (i , s );
1157
1154
String val = s .substring (i , endOfVal );
1158
1155
return Integer .parseInt (val );
1159
1156
}
1160
1157
1161
- protected int getMonthNumber (String s ) {
1158
+ private int getMonthNumber (String s ) {
1162
1159
Integer integer = monthMap .get (s );
1163
1160
1164
1161
if (integer == null ) {
@@ -1174,7 +1171,7 @@ protected int getMonthNumber(String s) {
1174
1171
//
1175
1172
////////////////////////////////////////////////////////////////////////////
1176
1173
1177
- protected int getDayOfWeekNumber (String s ) {
1174
+ private int getDayOfWeekNumber (String s ) {
1178
1175
Integer integer = dayMap .get (s );
1179
1176
1180
1177
if (integer == null ) {
@@ -1443,10 +1440,7 @@ public Date getTimeAfter(Date afterTime) {
1443
1440
daysToAdd = dow + (7 - cDow );
1444
1441
}
1445
1442
1446
- boolean dayShifted = false ;
1447
- if (daysToAdd > 0 ) {
1448
- dayShifted = true ;
1449
- }
1443
+ boolean dayShifted = daysToAdd > 0 ;
1450
1444
1451
1445
day += daysToAdd ;
1452
1446
int weekOfMonth = day / 7 ;
@@ -1594,7 +1588,7 @@ public Date getTimeAfter(Date afterTime) {
1594
1588
* @param cal the calendar to operate on
1595
1589
* @param hour the hour to set
1596
1590
*/
1597
- protected void setCalendarHour (Calendar cal , int hour ) {
1591
+ private void setCalendarHour (Calendar cal , int hour ) {
1598
1592
cal .set (java .util .Calendar .HOUR_OF_DAY , hour );
1599
1593
if (cal .get (java .util .Calendar .HOUR_OF_DAY ) != hour && hour != 24 ) {
1600
1594
cal .set (java .util .Calendar .HOUR_OF_DAY , hour + 1 );
@@ -1619,11 +1613,11 @@ public Date getFinalFireTime() {
1619
1613
return null ;
1620
1614
}
1621
1615
1622
- protected boolean isLeapYear (int year ) {
1616
+ private boolean isLeapYear (int year ) {
1623
1617
return ((year % 4 == 0 && year % 100 != 0 ) || (year % 400 == 0 ));
1624
1618
}
1625
1619
1626
- protected int getLastDayOfMonth (int monthNum , int year ) {
1620
+ private int getLastDayOfMonth (int monthNum , int year ) {
1627
1621
1628
1622
switch (monthNum ) {
1629
1623
case 1 :
0 commit comments