Maps given cron to target cron definition. @param cron - Instance to be mapped; if null a NullPointerException will be raised @return new Cron instance, never null;
(final Cron cron)
| 74 | * @return new Cron instance, never null; |
| 75 | */ |
| 76 | public Cron map(final Cron cron) { |
| 77 | Preconditions.checkNotNull(cron, "Cron must not be null"); |
| 78 | if(cron instanceof RebootCron){ |
| 79 | if(this.to.getCronNicknames().contains(CronNicknames.REBOOT)){ |
| 80 | return new RebootCron(this.to); |
| 81 | } else { |
| 82 | throw new IllegalArgumentException("The target cron definition does not support @reboot nickname"); |
| 83 | } |
| 84 | } |
| 85 | final List<CronField> fields = new ArrayList<>(); |
| 86 | for (final CronFieldName name : CronFieldName.values()) { |
| 87 | if (mappings.containsKey(name)) { |
| 88 | final CronField field = mappings.get(name).apply(cron.retrieve(name)); |
| 89 | if (field != null) { |
| 90 | fields.add(field); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | return cronRules.apply(new SingleCron(to, fields)).validate(); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Creates a CronMapper that maps a cron4j expression to a quartz expression. |