|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -29,7 +29,8 @@ import java.util.TimeZone;
@@ -29,7 +29,8 @@ import java.util.TimeZone;
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Date sequence generator for a <a href="http://www.manpagez.com/man/5/crontab/">Crontab pattern</a>, |
|
|
|
|
* Date sequence generator for a |
|
|
|
|
* <a href="http://www.manpagez.com/man/5/crontab/">Crontab pattern</a>, |
|
|
|
|
* allowing clients to specify a pattern that the sequence matches. |
|
|
|
|
* |
|
|
|
|
* <p>The pattern is a list of six single space-separated fields: representing |
|
|
|
@ -53,21 +54,21 @@ import org.springframework.util.StringUtils;
@@ -53,21 +54,21 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
*/ |
|
|
|
|
public class CronSequenceGenerator { |
|
|
|
|
|
|
|
|
|
private final BitSet seconds = new BitSet(60); |
|
|
|
|
|
|
|
|
|
private final BitSet minutes = new BitSet(60); |
|
|
|
|
private final String expression; |
|
|
|
|
|
|
|
|
|
private final BitSet hours = new BitSet(24); |
|
|
|
|
private final TimeZone timeZone; |
|
|
|
|
|
|
|
|
|
private final BitSet daysOfWeek = new BitSet(7); |
|
|
|
|
private final BitSet months = new BitSet(12); |
|
|
|
|
|
|
|
|
|
private final BitSet daysOfMonth = new BitSet(31); |
|
|
|
|
|
|
|
|
|
private final BitSet months = new BitSet(12); |
|
|
|
|
private final BitSet daysOfWeek = new BitSet(7); |
|
|
|
|
|
|
|
|
|
private final String expression; |
|
|
|
|
private final BitSet hours = new BitSet(24); |
|
|
|
|
|
|
|
|
|
private final TimeZone timeZone; |
|
|
|
|
private final BitSet minutes = new BitSet(60); |
|
|
|
|
|
|
|
|
|
private final BitSet seconds = new BitSet(60); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -95,6 +96,14 @@ public class CronSequenceGenerator {
@@ -95,6 +96,14 @@ public class CronSequenceGenerator {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the cron pattern that this sequence generator has been built for. |
|
|
|
|
*/ |
|
|
|
|
String getExpression() { |
|
|
|
|
return this.expression; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the next {@link Date} in the sequence matching the Cron pattern and |
|
|
|
|
* after the value provided. The return value will have a whole number of |
|
|
|
@ -271,9 +280,9 @@ public class CronSequenceGenerator {
@@ -271,9 +280,9 @@ public class CronSequenceGenerator {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Replace the values in the commaSeparatedList (case insensitive) with |
|
|
|
|
* their index in the list. |
|
|
|
|
* @return a new string with the values from the list replaced |
|
|
|
|
* Replace the values in the comma-separated list (case insensitive) |
|
|
|
|
* with their index in the list. |
|
|
|
|
* @return a new String with the values from the list replaced |
|
|
|
|
*/ |
|
|
|
|
private String replaceOrdinals(String value, String commaSeparatedList) { |
|
|
|
|
String[] list = StringUtils.commaDelimitedListToStringArray(commaSeparatedList); |
|
|
|
@ -332,6 +341,10 @@ public class CronSequenceGenerator {
@@ -332,6 +341,10 @@ public class CronSequenceGenerator {
|
|
|
|
|
range[1] = max - 1; |
|
|
|
|
} |
|
|
|
|
int delta = Integer.valueOf(split[1]); |
|
|
|
|
if (delta <= 0) { |
|
|
|
|
throw new IllegalArgumentException("Incrementer delta must be 1 or higher: '" + |
|
|
|
|
field + "' in expression \"" + this.expression + "\""); |
|
|
|
|
} |
|
|
|
|
for (int i = range[0]; i <= range[1]; i += delta) { |
|
|
|
|
bits.set(i); |
|
|
|
|
} |
|
|
|
@ -369,30 +382,30 @@ public class CronSequenceGenerator {
@@ -369,30 +382,30 @@ public class CronSequenceGenerator {
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String getExpression() { |
|
|
|
|
return this.expression; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean equals(Object obj) { |
|
|
|
|
if (!(obj instanceof CronSequenceGenerator)) { |
|
|
|
|
public boolean equals(Object other) { |
|
|
|
|
if (this == other) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
if (!(other instanceof CronSequenceGenerator)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
CronSequenceGenerator cron = (CronSequenceGenerator) obj; |
|
|
|
|
return cron.months.equals(this.months) && cron.daysOfMonth.equals(this.daysOfMonth) |
|
|
|
|
&& cron.daysOfWeek.equals(this.daysOfWeek) && cron.hours.equals(this.hours) |
|
|
|
|
&& cron.minutes.equals(this.minutes) && cron.seconds.equals(this.seconds); |
|
|
|
|
CronSequenceGenerator otherCron = (CronSequenceGenerator) other; |
|
|
|
|
return (this.months.equals(otherCron.months) && this.daysOfMonth.equals(otherCron.daysOfMonth) && |
|
|
|
|
this.daysOfWeek.equals(otherCron.daysOfWeek) && this.hours.equals(otherCron.hours) && |
|
|
|
|
this.minutes.equals(otherCron.minutes) && this.seconds.equals(otherCron.seconds)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int hashCode() { |
|
|
|
|
return 37 + 17 * this.months.hashCode() + 29 * this.daysOfMonth.hashCode() + 37 * this.daysOfWeek.hashCode() |
|
|
|
|
+ 41 * this.hours.hashCode() + 53 * this.minutes.hashCode() + 61 * this.seconds.hashCode(); |
|
|
|
|
return (17 * this.months.hashCode() + 29 * this.daysOfMonth.hashCode() + 37 * this.daysOfWeek.hashCode() + |
|
|
|
|
41 * this.hours.hashCode() + 53 * this.minutes.hashCode() + 61 * this.seconds.hashCode()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String toString() { |
|
|
|
|
return getClass().getSimpleName() + ": " + this.expression; |
|
|
|
|
return (getClass().getSimpleName() + ": " + this.expression); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|