CronFieldType.java
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*/
package net.sourceforge.plantuml.error.cron;
/**
* The five fields of a cron expression, in order, with their bounds. Only numbers
* are accepted: there are no names such as {@code JAN} or {@code SUN}.
*/
public enum CronFieldType {
MINUTE("minute", 0, 59, 59), //
HOUR("hour", 0, 23, 23), //
DAY_OF_MONTH("day of month", 1, 31, 31), //
MONTH("month", 1, 12, 12), //
DAY_OF_WEEK("day of week", 0, 7, 6);
private final String label;
private final int min;
private final int max;
private final int starMax;
private CronFieldType(String label, int min, int max, int starMax) {
this.label = label;
this.min = min;
this.max = max;
this.starMax = starMax;
}
public String getLabel() {
return label;
}
public int getMin() {
return min;
}
/**
* Highest value accepted in the expression. For the day of week it is 7, an
* alias of 0 (Sunday).
*/
public int getMax() {
return max;
}
/**
* Highest value covered by {@code *}: 6 for the day of week, so that 7 (an
* alias of Sunday) does not count twice in a step such as <code>*/2</code>.
*/
int getStarMax() {
return starMax;
}
/**
* Maps a value of the expression to the value stored and matched: only the day
* of week changes, 7 becoming 0.
*/
int normalize(int value) {
if (this == DAY_OF_WEEK && value == 7)
return 0;
return value;
}
}