it.sauronsoftware.cron4j
Class Predictor

java.lang.Object
  extended by it.sauronsoftware.cron4j.Predictor

public class Predictor
extends java.lang.Object

A predictor is able to predict when a scheduling pattern will be matched.

Suppose you want to know when the scheduler will execute a task scheduled with the pattern 0 3 * jan-jun,sep-dec mon-fri. You can predict the next n execution of the task using a Predictor instance:

 String pattern = "0 3 * jan-jun,sep-dec mon-fri";
 Predictor p = new Predictor(pattern);
 for (int i = 0; i < n; i++) {
        System.out.println(p.nextMatchingDate());
 }
 

Since:
1.1
Author:
Carlo Pelliccia

Constructor Summary
Predictor(SchedulingPattern schedulingPattern)
          It builds a predictor with the given scheduling pattern and the current system time as the prediction start time.
Predictor(SchedulingPattern schedulingPattern, java.util.Date start)
          It builds a predictor with the given scheduling pattern and start time.
Predictor(SchedulingPattern schedulingPattern, long start)
          It builds a predictor with the given scheduling pattern and start time.
Predictor(java.lang.String schedulingPattern)
          It builds a predictor with the given scheduling pattern and the current system time as the prediction start time.
Predictor(java.lang.String schedulingPattern, java.util.Date start)
          It builds a predictor with the given scheduling pattern and start time.
Predictor(java.lang.String schedulingPattern, long start)
          It builds a predictor with the given scheduling pattern and start time.
 
Method Summary
 java.util.Date nextMatchingDate()
          It returns the next matching moment as a Date object.
 long nextMatchingTime()
          It returns the next matching moment as a millis value.
 void setTimeZone(java.util.TimeZone timeZone)
          Sets the time zone for predictions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Predictor

public Predictor(java.lang.String schedulingPattern,
                 long start)
          throws InvalidPatternException
It builds a predictor with the given scheduling pattern and start time.

Parameters:
schedulingPattern - The pattern on which the prediction will be based.
start - The start time of the prediction.
Throws:
InvalidPatternException - In the given scheduling pattern isn't valid.

Predictor

public Predictor(java.lang.String schedulingPattern,
                 java.util.Date start)
          throws InvalidPatternException
It builds a predictor with the given scheduling pattern and start time.

Parameters:
schedulingPattern - The pattern on which the prediction will be based.
start - The start time of the prediction.
Throws:
InvalidPatternException - In the given scheduling pattern isn't valid.

Predictor

public Predictor(java.lang.String schedulingPattern)
          throws InvalidPatternException
It builds a predictor with the given scheduling pattern and the current system time as the prediction start time.

Parameters:
schedulingPattern - The pattern on which the prediction will be based.
Throws:
InvalidPatternException - In the given scheduling pattern isn't valid.

Predictor

public Predictor(SchedulingPattern schedulingPattern,
                 long start)
It builds a predictor with the given scheduling pattern and start time.

Parameters:
schedulingPattern - The pattern on which the prediction will be based.
start - The start time of the prediction.
Since:
2.0

Predictor

public Predictor(SchedulingPattern schedulingPattern,
                 java.util.Date start)
It builds a predictor with the given scheduling pattern and start time.

Parameters:
schedulingPattern - The pattern on which the prediction will be based.
start - The start time of the prediction.
Since:
2.0

Predictor

public Predictor(SchedulingPattern schedulingPattern)
It builds a predictor with the given scheduling pattern and the current system time as the prediction start time.

Parameters:
schedulingPattern - The pattern on which the prediction will be based.
Since:
2.0
Method Detail

setTimeZone

public void setTimeZone(java.util.TimeZone timeZone)
Sets the time zone for predictions.

Parameters:
timeZone - The time zone for predictions.
Since:
2.2.5

nextMatchingTime

public long nextMatchingTime()
It returns the next matching moment as a millis value.

Returns:
The next matching moment as a millis value.

nextMatchingDate

public java.util.Date nextMatchingDate()
It returns the next matching moment as a Date object.

Returns:
The next matching moment as a Date object.