com.github.kagkarlsson.shaded.cronutils.model.CompositeCron Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of db-scheduler Show documentation
Show all versions of db-scheduler Show documentation
Simple persistent scheduler for scheduled tasks, recurring or ad-hoc.
package com.github.kagkarlsson.shaded.cronutils.model;
import com.github.kagkarlsson.shaded.cronutils.mapper.CronMapper;
import com.github.kagkarlsson.shaded.cronutils.model.definition.CronDefinition;
import com.github.kagkarlsson.shaded.cronutils.model.field.CronField;
import com.github.kagkarlsson.shaded.cronutils.model.field.CronFieldName;
import com.github.kagkarlsson.shaded.cronutils.utils.Preconditions;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class CompositeCron implements Cron {
private Pattern split = Pattern.compile("\\|");
private List crons;
private CronDefinition definition;
public CompositeCron(List crons){
this.crons = Collections.unmodifiableList(crons);
Preconditions.checkNotNullNorEmpty(crons, "List of Cron cannot be null or empty");
this.definition = crons.get(0).getCronDefinition();
Preconditions.checkArgument(crons.size()==crons.stream().filter(c->c.getCronDefinition().equals(definition)).count(), "All Cron objects must have same definition for CompositeCron");
}
public List getCrons() {
return crons;
}
@Override
public CronField retrieve(CronFieldName name) {
throw new UnsupportedOperationException("Currently not supported for CompositeCron");
}
@Override
public Map retrieveFieldsAsMap() {
throw new UnsupportedOperationException("Currently not supported for CompositeCron");
}
@Override
public String asString() {
StringBuilder builder = new StringBuilder();
List patterns = crons.stream().map(Cron::asString).collect(Collectors.toList());
int fields = patterns.get(0).split(" ").length;
for(int j=0;j