-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow quartz expression in cron expression lists
This commit introduces support for lists of quartz cron fields, such as "1L, LW" or "TUE#1, TUE#3, TUE#5". Closes gh-26289
- Loading branch information
Showing
5 changed files
with
238 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
spring-context/src/main/java/org/springframework/scheduling/support/CompositeCronField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2002-2021 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.scheduling.support; | ||
|
||
import java.time.temporal.Temporal; | ||
|
||
import org.springframework.lang.Nullable; | ||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* Extension of {@link CronField} that wraps an array of cron fields. | ||
* | ||
* @author Arjen Poutsma | ||
* @since 5.3.3 | ||
*/ | ||
final class CompositeCronField extends CronField { | ||
|
||
private final CronField[] fields; | ||
|
||
private final String value; | ||
|
||
|
||
private CompositeCronField(Type type, CronField[] fields, String value) { | ||
super(type); | ||
this.fields = fields; | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* Composes the given fields into a {@link CronField}. | ||
*/ | ||
public static CronField compose(CronField[] fields, Type type, String value) { | ||
Assert.notEmpty(fields, "Fields must not be empty"); | ||
Assert.hasLength(value, "Value must not be empty"); | ||
|
||
if (fields.length == 1) { | ||
return fields[0]; | ||
} | ||
else { | ||
return new CompositeCronField(type, fields, value); | ||
} | ||
} | ||
|
||
|
||
@Nullable | ||
@Override | ||
public <T extends Temporal & Comparable<? super T>> T nextOrSame(T temporal) { | ||
T result = null; | ||
for (CronField field : this.fields) { | ||
T candidate = field.nextOrSame(temporal); | ||
if (result == null || | ||
candidate != null && candidate.compareTo(result) < 0) { | ||
result = candidate; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
|
||
@Override | ||
public int hashCode() { | ||
return this.value.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof CompositeCronField)) { | ||
return false; | ||
} | ||
CompositeCronField other = (CompositeCronField) o; | ||
return type() == other.type() && | ||
this.value.equals(other.value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return type() + " '" + this.value + "'"; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.