diff --git a/org.springframework.integration/.classpath b/org.springframework.integration/.classpath
index 8cfdd6f039..0b17768ab2 100644
--- a/org.springframework.integration/.classpath
+++ b/org.springframework.integration/.classpath
@@ -9,6 +9,7 @@
+
diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/CronSequenceGenerator.java b/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/CronSequenceGenerator.java
index b6e556beef..b4e5686841 100644
--- a/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/CronSequenceGenerator.java
+++ b/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/CronSequenceGenerator.java
@@ -29,7 +29,8 @@ import org.springframework.util.StringUtils;
* client to specify a pattern that the sequence matches. The pattern is a list
* of 6 single space separated fields representing (second, minute, hour, day,
* month, weekday). Month and weekday names can be given as the first three
- * letters of the English names.
+ * letters of the English names.
+ *
*
* Example patterns
*
@@ -59,7 +60,6 @@ public class CronSequenceGenerator {
private final String pattern;
-
/**
* Construct a {@link CronSequenceGenerator} from the pattern provided.
*
@@ -72,7 +72,6 @@ public class CronSequenceGenerator {
parse(pattern);
}
-
/**
* 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
@@ -146,17 +145,17 @@ public class CronSequenceGenerator {
* @return the value of the calendar field that is next in the sequence
*/
private int findNext(BitSet bits, int value, int max, Calendar calendar, int field, int... lowerOrders) {
- // TODO: more efficient to use BitSet.nextSet(int)
- int count = 0;
- while (!bits.get(value) && count++ < max) {
- calendar.add(field, 1);
- value = calendar.get(field);
+ int nextValue = bits.nextSetBit(value);
+ //roll over if needed
+ if (nextValue == -1) {
+ calendar.add(field, max - value);
+ nextValue = bits.nextSetBit(0);
+ }
+ if (nextValue != value) {
+ calendar.set(field, nextValue);
reset(calendar, lowerOrders);
}
- if (count > max) {
- throw new IllegalStateException(String.format("Overflow in field=%d for expression=%s", field, pattern));
- }
- return value;
+ return nextValue;
}
/**
@@ -177,9 +176,8 @@ public class CronSequenceGenerator {
private void parse(String expression) throws IllegalArgumentException {
String[] fields = StringUtils.tokenizeToStringArray(expression, " ");
if (fields.length != 6) {
- throw new IllegalArgumentException(String.format("" +
- "cron expression must consist of 6 fields (found %d in %s)",
- fields.length, expression));
+ throw new IllegalArgumentException(String.format(""
+ + "cron expression must consist of 6 fields (found %d in %s)", fields.length, expression));
}
setNumberHits(seconds, fields[0], 60);
setNumberHits(minutes, fields[1], 60);