Skip to content

Commit 8cc5001

Browse files
committed
Reapplied SPR-6666 to branch, made code Java 5 compliant and extended manifests to make build runnable again
1 parent 2def068 commit 8cc5001

File tree

6 files changed

+163
-70
lines changed

6 files changed

+163
-70
lines changed

org.springframework.beans/src/main/java/org/springframework/beans/factory/config/AbstractMapScope.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.beans.factory.config;
1717

18-
import java.io.Serializable;
1918
import java.util.Map;
2019

2120
import org.springframework.beans.factory.ObjectFactory;
@@ -25,12 +24,12 @@
2524
* state of the scope and also supporting destruction callbacks. It might be
2625
* used as the base for any other scope implementation or in tests to easily
2726
* register a scope based on a map implementation.
28-
*
27+
*
2928
* @author Micha Kiener
3029
* @since 3.1
3130
*/
3231
public abstract class AbstractMapScope extends DestructionAwareAttributeMap
33-
implements Scope, Serializable {
32+
implements Scope {
3433

3534
/**
3635
* @return a map based representation of the state of this scope
@@ -56,7 +55,6 @@ public Object get(String name, ObjectFactory<?> objectFactory) {
5655
/**
5756
* @see org.springframework.beans.factory.config.Scope#remove(java.lang.String)
5857
*/
59-
@Override
6058
public Object remove(String name) {
6159
return super.removeAttribute(name);
6260
}

org.springframework.context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Date;
2424
import java.util.GregorianCalendar;
2525
import java.util.List;
26+
import java.util.TimeZone;
2627

2728
import org.springframework.util.StringUtils;
2829

@@ -66,13 +67,17 @@ class CronSequenceGenerator {
6667

6768
private final String expression;
6869

70+
private final TimeZone timeZone;
71+
6972
/**
7073
* Construct a {@link CronSequenceGenerator} from the pattern provided.
7174
* @param expression a space-separated list of time fields
75+
* @param timeZone the TimeZone to use for generated trigger times
7276
* @throws IllegalArgumentException if the pattern cannot be parsed
7377
*/
74-
public CronSequenceGenerator(String expression) {
78+
public CronSequenceGenerator(String expression, TimeZone timeZone) {
7579
this.expression = expression;
80+
this.timeZone = timeZone;
7681
parse(expression);
7782
}
7883

@@ -106,6 +111,7 @@ public Date next(Date date) {
106111
*/
107112

108113
Calendar calendar = new GregorianCalendar();
114+
calendar.setTimeZone(timeZone);
109115
calendar.setTime(date);
110116

111117
// Truncate to the next whole second
@@ -122,21 +128,21 @@ private void doNext(Calendar calendar) {
122128

123129
int second = calendar.get(Calendar.SECOND);
124130
List<Integer> emptyList = Collections.<Integer> emptyList();
125-
int updateSecond = findNext(this.seconds, second, 60, calendar, Calendar.SECOND, emptyList);
131+
int updateSecond = findNext(this.seconds, second, calendar, Calendar.SECOND, Calendar.MINUTE, emptyList);
126132
if (second == updateSecond) {
127133
resets.add(Calendar.SECOND);
128134
}
129135

130136
int minute = calendar.get(Calendar.MINUTE);
131-
int updateMinute = findNext(this.minutes, minute, 60, calendar, Calendar.MINUTE, resets);
137+
int updateMinute = findNext(this.minutes, minute, calendar, Calendar.MINUTE, Calendar.HOUR_OF_DAY, resets);
132138
if (minute == updateMinute) {
133139
resets.add(Calendar.MINUTE);
134140
} else {
135141
doNext(calendar);
136142
}
137143

138144
int hour = calendar.get(Calendar.HOUR_OF_DAY);
139-
int updateHour = findNext(this.hours, hour, 24, calendar, Calendar.HOUR_OF_DAY, resets);
145+
int updateHour = findNext(this.hours, hour, calendar, Calendar.HOUR_OF_DAY, Calendar.DAY_OF_WEEK, resets);
140146
if (hour == updateHour) {
141147
resets.add(Calendar.HOUR_OF_DAY);
142148
} else {
@@ -153,7 +159,7 @@ private void doNext(Calendar calendar) {
153159
}
154160

155161
int month = calendar.get(Calendar.MONTH);
156-
int updateMonth = findNext(this.months, month, 12, calendar, Calendar.MONTH, resets);
162+
int updateMonth = findNext(this.months, month, calendar, Calendar.MONTH, Calendar.YEAR, resets);
157163
if (month != updateMonth) {
158164
doNext(calendar);
159165
}
@@ -183,19 +189,19 @@ private int findNextDay(Calendar calendar, BitSet daysOfMonth, int dayOfMonth, B
183189
* and reset the calendar.
184190
* @param bits a {@link BitSet} representing the allowed values of the field
185191
* @param value the current value of the field
186-
* @param max the largest value that the field can have
187192
* @param calendar the calendar to increment as we move through the bits
188193
* @param field the field to increment in the calendar (@see
189194
* {@link Calendar} for the static constants defining valid fields)
190195
* @param lowerOrders the Calendar field ids that should be reset (i.e. the
191196
* ones of lower significance than the field of interest)
192197
* @return the value of the calendar field that is next in the sequence
193198
*/
194-
private int findNext(BitSet bits, int value, int max, Calendar calendar, int field, List<Integer> lowerOrders) {
199+
private int findNext(BitSet bits, int value, Calendar calendar, int field, int nextField, List<Integer> lowerOrders) {
195200
int nextValue = bits.nextSetBit(value);
196201
// roll over if needed
197202
if (nextValue == -1) {
198-
calendar.add(field, max - value);
203+
calendar.add(nextField, 1);
204+
calendar.set(field, 0);
199205
nextValue = bits.nextSetBit(0);
200206
}
201207
if (nextValue != value) {

org.springframework.context/src/main/java/org/springframework/scheduling/support/CronTrigger.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.scheduling.support;
1818

1919
import java.util.Date;
20+
import java.util.TimeZone;
2021

2122
import org.springframework.scheduling.Trigger;
2223
import org.springframework.scheduling.TriggerContext;
@@ -33,16 +34,24 @@ public class CronTrigger implements Trigger {
3334

3435
private final CronSequenceGenerator sequenceGenerator;
3536

36-
3737
/**
3838
* Build a {@link CronTrigger} from the pattern provided.
3939
* @param cronExpression a space-separated list of time fields,
4040
* following cron expression conventions
41+
* @param timeZone a time zone in which the trigger times will be generated
4142
*/
42-
public CronTrigger(String cronExpression) {
43-
this.sequenceGenerator = new CronSequenceGenerator(cronExpression);
43+
public CronTrigger(String cronExpression, TimeZone timeZone) {
44+
this.sequenceGenerator = new CronSequenceGenerator(cronExpression, timeZone);
4445
}
4546

47+
/**
48+
* Build a {@link CronTrigger} from the pattern provided in the default time zone.
49+
* @param cronExpression a space-separated list of time fields,
50+
* following cron expression conventions
51+
*/
52+
public CronTrigger(String cronExpression) {
53+
this(cronExpression, TimeZone.getDefault());
54+
}
4655

4756
public Date nextExecutionTime(TriggerContext triggerContext) {
4857
Date date = triggerContext.lastCompletionTime();
@@ -52,12 +61,10 @@ public Date nextExecutionTime(TriggerContext triggerContext) {
5261
return this.sequenceGenerator.next(date);
5362
}
5463

55-
5664
@Override
5765
public boolean equals(Object obj) {
58-
return (this == obj ||
59-
(obj instanceof CronTrigger &&
60-
this.sequenceGenerator.equals(((CronTrigger) obj).sequenceGenerator)));
66+
return (this == obj || (obj instanceof CronTrigger && this.sequenceGenerator
67+
.equals(((CronTrigger) obj).sequenceGenerator)));
6168
}
6269

6370
@Override

0 commit comments

Comments
 (0)