com.opensymphony.oscache.util
Class FastCronParser

java.lang.Object
  extended by com.opensymphony.oscache.util.FastCronParser

public class FastCronParser
extends Object

Parses cron expressions and determines at what time in the past is the most recent match for the supplied expression.

Version:
$Revision: 340 $
Author:
Chris Miller, $Author: ltorunski $

Constructor Summary
FastCronParser()
          Creates a FastCronParser that uses a default cron expression of "* * * * *".
FastCronParser(String cronExpression)
          Constructs a new FastCronParser based on the supplied expression.
 
Method Summary
 String getCronExpression()
          Retrieves the current cron expression.
 String getExpressionSummary()
          Recreates the original human-readable cron expression based on the internal datastructure values.
 long getTimeBefore(long time)
          Find the most recent time that matches this cron expression.
 boolean hasMoreRecentMatch(long time)
          Determines whether this cron expression matches a date/time that is more recent than the one supplied.
 void setCronExpression(String cronExpression)
          Resets the cron expression to the value supplied.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FastCronParser

public FastCronParser()
Creates a FastCronParser that uses a default cron expression of "* * * * *". This will match any time that is supplied.


FastCronParser

public FastCronParser(String cronExpression)
               throws ParseException
Constructs a new FastCronParser based on the supplied expression.

Throws:
ParseException - if the supplied expression is not a valid cron expression.
Method Detail

setCronExpression

public void setCronExpression(String cronExpression)
                       throws ParseException
Resets the cron expression to the value supplied.

Parameters:
cronExpression - the new cron expression.
Throws:
ParseException - if the supplied expression is not a valid cron expression.

getCronExpression

public String getCronExpression()
Retrieves the current cron expression.

Returns:
the current cron expression.

hasMoreRecentMatch

public boolean hasMoreRecentMatch(long time)
Determines whether this cron expression matches a date/time that is more recent than the one supplied.

Parameters:
time - The time to compare the cron expression against.
Returns:
true if the cron expression matches a time that is closer to the current time than the supplied time is, false otherwise.

getTimeBefore

public long getTimeBefore(long time)
Find the most recent time that matches this cron expression. This time will always be in the past, ie a lower value than the supplied time.

Parameters:
time - The time (in milliseconds) that we're using as our upper bound.
Returns:
The time (in milliseconds) when this cron event last occurred.

getExpressionSummary

public String getExpressionSummary()
Recreates the original human-readable cron expression based on the internal datastructure values.

Returns:
A cron expression that corresponds to the current state of the internal data structure.

OSCache Project Page