de.jaret.util.date.iterator
Class AbstractDateIterator

java.lang.Object
  extended by de.jaret.util.date.iterator.AbstractDateIterator
All Implemented Interfaces:
DateIterator
Direct Known Subclasses:
DayIterator, HourIterator, MillisecondIterator, MinuteIterator, MonthIterator, SecondIterator, WeekIterator, YearIterator

public abstract class AbstractDateIterator
extends Object
implements DateIterator

Abstract base Implementation of a DateIterator.

Version:
$Id: AbstractDateIterator.java 883 2009-10-07 21:03:00Z kliem $
Author:
kliem

Nested Class Summary
 
Nested classes/interfaces inherited from interface de.jaret.util.date.iterator.DateIterator
DateIterator.Format
 
Field Summary
protected  boolean _correctDST
          true if DST should be corrected.
protected  JaretDate _currentDate
          the current date.
protected  JaretDate _endDate
          the last date.
protected  IIteratorFormatter _formatter
          if set this formatter overrides default behaviour.
protected  boolean _lastInDST
          flag for remembering if the last date was in or out DST.
 
Constructor Summary
AbstractDateIterator()
          Default constructor.
AbstractDateIterator(JaretDate startDate, JaretDate endDate)
          Constructor supplying values.
 
Method Summary
protected abstract  void advanceDate(JaretDate date)
          Advance the given date by the amount necessary.
protected abstract  JaretDate correctStartDate(JaretDate date)
          Correct the given date to a clean starting position.
protected abstract  IIteratorFormatter getDefaultFormatter()
          Internal method to retrieve a default formatter.
protected  IIteratorFormatter getFormatter()
          Retrieve the formatter to use.
 String getLabel(JaretDate date, DateIterator.Format format)
          Retrieve a label for a given date.
 JaretDate getNextDate()
          Retrieve the next date from the iterator.
 boolean hasNextDate()
          Check whether the iterator will supply a next date.
 JaretDate previewNextDate()
          Retrieve the next date without modifying the iterator.
 void reInitialize(JaretDate startDate, JaretDate endDate)
          (re)initialize the iterator with a start and an end date.
 void setCorrectDST(boolean correctDST)
          If the correct DST flag is set to true, the iterator will add/remove an hour if the DST switch time has been passed.
 void setFormatter(IIteratorFormatter formatter)
          Set a formatter to be used with this iterator overriding the default formatting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.jaret.util.date.iterator.DateIterator
getApproxStepMilliSeconds
 

Field Detail

_currentDate

protected JaretDate _currentDate
the current date.


_endDate

protected JaretDate _endDate
the last date.


_correctDST

protected boolean _correctDST
true if DST should be corrected.


_lastInDST

protected boolean _lastInDST
flag for remembering if the last date was in or out DST.


_formatter

protected IIteratorFormatter _formatter
if set this formatter overrides default behaviour.

Constructor Detail

AbstractDateIterator

public AbstractDateIterator(JaretDate startDate,
                            JaretDate endDate)
Constructor supplying values.

Parameters:
startDate - start date
endDate - end date. null for unlimited iterating

AbstractDateIterator

public AbstractDateIterator()
Default constructor. Beware: reinitialize has to be called at least once.

Method Detail

correctStartDate

protected abstract JaretDate correctStartDate(JaretDate date)
Correct the given date to a clean starting position.

Parameters:
date - start date
Returns:
clean starting position

advanceDate

protected abstract void advanceDate(JaretDate date)
Advance the given date by the amount necessary.

Parameters:
date - date to be modified

reInitialize

public void reInitialize(JaretDate startDate,
                         JaretDate endDate)
(re)initialize the iterator with a start and an end date.

Specified by:
reInitialize in interface DateIterator
Parameters:
startDate - first date that will be returned in subsequent calls
endDate - last date that will be returned

getNextDate

public JaretDate getNextDate()
Retrieve the next date from the iterator.

Specified by:
getNextDate in interface DateIterator
Returns:
next date

hasNextDate

public boolean hasNextDate()
Check whether the iterator will supply a next date.

Specified by:
hasNextDate in interface DateIterator
Returns:
true if the next call to getNextDate() will return a valid date

previewNextDate

public JaretDate previewNextDate()
Retrieve the next date without modifying the iterator.

Specified by:
previewNextDate in interface DateIterator
Returns:
the next valid date or null if no subsequent date is available

getLabel

public String getLabel(JaretDate date,
                       DateIterator.Format format)
Retrieve a label for a given date.

Specified by:
getLabel in interface DateIterator
Parameters:
date - the date to format
format - short, medium or long
Returns:
label

getFormatter

protected IIteratorFormatter getFormatter()
Retrieve the formatter to use. This is either a set formatter or the default formatter.

Returns:
a formatter to be used.

getDefaultFormatter

protected abstract IIteratorFormatter getDefaultFormatter()
Internal method to retrieve a default formatter.

Returns:
the default formatter of the iterator

setFormatter

public void setFormatter(IIteratorFormatter formatter)
Set a formatter to be used with this iterator overriding the default formatting.

Specified by:
setFormatter in interface DateIterator
Parameters:
formatter - the formatter to use.

setCorrectDST

public void setCorrectDST(boolean correctDST)
If the correct DST flag is set to true, the iterator will add/remove an hour if the DST switch time has been passed. This is false by default and you should only use it if you are knowing what you are doing. This uses the Default TimeZone for determining DST switches.

Specified by:
setCorrectDST in interface DateIterator


Copyright © 2013. All Rights Reserved.