Class Expression

java.lang.Object
org.aoju.bus.cron.Expression
All Implemented Interfaces:
Serializable, Cloneable

public final class Expression extends Object implements Serializable, Cloneable
类似unix cron表达式提供解析器和执行器 Crontab表达式提供了指定复杂时间组合的能力
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Field Details

    • MAX_YEAR

      public static final int MAX_YEAR
    • SECOND

      protected static final int SECOND
      See Also:
    • MINUTE

      protected static final int MINUTE
      See Also:
    • HOUR

      protected static final int HOUR
      See Also:
    • DAY_OF_MONTH

      protected static final int DAY_OF_MONTH
      See Also:
    • MONTH

      protected static final int MONTH
      See Also:
    • DAY_OF_WEEK

      protected static final int DAY_OF_WEEK
      See Also:
    • YEAR

      protected static final int YEAR
      See Also:
    • ALL_SPEC_INT

      protected static final int ALL_SPEC_INT
      See Also:
    • NO_SPEC_INT

      protected static final int NO_SPEC_INT
      See Also:
    • ALL_SPEC

      protected static final Integer ALL_SPEC
    • NO_SPEC

      protected static final Integer NO_SPEC
    • monthMap

      protected static final Map<String,Integer> monthMap
    • dayMap

      protected static final Map<String,Integer> dayMap
    • seconds

      protected transient TreeSet<Integer> seconds
    • minutes

      protected transient TreeSet<Integer> minutes
    • hours

      protected transient TreeSet<Integer> hours
    • daysOfMonth

      protected transient TreeSet<Integer> daysOfMonth
    • months

      protected transient TreeSet<Integer> months
    • daysOfWeek

      protected transient TreeSet<Integer> daysOfWeek
    • years

      protected transient TreeSet<Integer> years
    • lastdayOfWeek

      protected transient boolean lastdayOfWeek
    • nthdayOfWeek

      protected transient int nthdayOfWeek
    • lastdayOfMonth

      protected transient boolean lastdayOfMonth
    • nearestWeekday

      protected transient boolean nearestWeekday
    • lastdayOffset

      protected transient int lastdayOffset
    • expressionParsed

      protected transient boolean expressionParsed
  • Constructor Details

    • Expression

      public Expression(String cronExpression) throws ParseException
      根据指定的参数构造一个新的 CronExpression
      Parameters:
      cronExpression - 新对象应表示的cron表达式的字符串表示形式
      Throws:
      ParseException - 如果字符串表达式不能解析为有效的 CronExpression
    • Expression

      public Expression(Expression expression)
      构造一个新的CronExpression作为现有*实例的副本
      Parameters:
      expression - 要复制的现有cron表达式
  • Method Details

    • isValidExpression

      public static boolean isValidExpression(String cronExpression)
      指示是否可以将指定的cron表达式解析为有效的cron表达式
      Parameters:
      cronExpression - 要评估的表达式
      Returns:
      指示给定表达式是否为有效cron表达式的布尔值
    • validateExpression

      public static void validateExpression(String cronExpression) throws ParseException
      Throws:
      ParseException
    • isSatisfiedBy

      public boolean isSatisfiedBy(Date date)
      指示给定的日期是否满足cron表达式 请注意,毫秒将被忽略,因此两个日期在同一秒的不同毫秒 处始终具有相同的结果
      Parameters:
      date - 评估日期
      Returns:
      指示给定日期是否满足cron 表达式的布尔值
    • getNextValidTimeAfter

      public Date getNextValidTimeAfter(Date date)
    • getNextInvalidTimeAfter

      public Date getNextInvalidTimeAfter(Date date)
    • getTimeZone

      public TimeZone getTimeZone()
    • setTimeZone

      public void setTimeZone(TimeZone timeZone)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • buildExpression

      protected void buildExpression(String expression) throws ParseException
      Throws:
      ParseException
    • storeExpressionVals

      protected int storeExpressionVals(int pos, String s, int type) throws ParseException
      Throws:
      ParseException
    • checkNext

      protected int checkNext(int pos, String s, int val, int type) throws ParseException
      Throws:
      ParseException
    • getCronExpression

      public String getCronExpression()
    • getExpressionSummary

      public String getExpressionSummary()
    • getExpressionSetSummary

      protected String getExpressionSetSummary(Set<Integer> set)
    • getExpressionSetSummary

      protected String getExpressionSetSummary(ArrayList<Integer> list)
    • skipWhiteSpace

      protected int skipWhiteSpace(int i, String s)
    • findNextWhiteSpace

      protected int findNextWhiteSpace(int i, String s)
    • addToSet

      protected void addToSet(int val, int end, int incr, int type) throws ParseException
      Throws:
      ParseException
    • getValue

      protected org.aoju.bus.cron.Expression.ValueSet getValue(int v, String s, int i)
    • getNumericValue

      protected int getNumericValue(String s, int i)
    • getMonthNumber

      protected int getMonthNumber(String s)
    • getDayOfWeekNumber

      protected int getDayOfWeekNumber(String s)
    • getTimeAfter

      public Date getTimeAfter(Date afterTime)
    • setCalendarHour

      protected void setCalendarHour(Calendar cal, int hour)
      Advance the calendar to the particular hour paying particular attention to daylight saving problems.
      Parameters:
      cal - the calendar to operate on
      hour - the hour to set
    • getTimeBefore

      public Date getTimeBefore(Date endTime)
      NOT YET IMPLEMENTED: Returns the time before the given time that the CronExpression matches.
      Parameters:
      endTime - end time
      Returns:
      date
    • getFinalFireTime

      public Date getFinalFireTime()
      NOT YET IMPLEMENTED: Returns the final time that the CronExpression will match.
      Returns:
      time
    • getLastDayOfMonth

      protected int getLastDayOfMonth(int monthNum, int year)