com.moneydance.apps.md.model.time
Class SimpleFrequency

java.lang.Object
  extended by com.moneydance.apps.md.model.time.SimpleFrequency
All Implemented Interfaces:
Frequency, Stringifyable

public class SimpleFrequency
extends java.lang.Object
implements Frequency, Stringifyable

The SimpleFrequency class is an implementation of Frequency that uses a multiple of a given TimeUnit to calculate next and previous dates.

Note: When using month,quarter or year time units, you may not get the intended results. Moving forward a month means moving the month portion of the date forward while leaving the date the same. Since the result won't always be a valid date, the date will be resolved in the same manner as GregorianCalendar.add(int, int).

This class is immutable.

Author:
Jay Detwiler

Constructor Summary
SimpleFrequency(TimeUnit unit)
          Creates a SimpleFrequency based on a single TimeUnit
SimpleFrequency(TimeUnit unit, int num)
          Creates a SimpleFrequency based on a multiple of a TimeUnit
 
Method Summary
 boolean equals(java.lang.Object o)
           
static SimpleFrequency fromString(java.lang.String string)
           
 java.lang.String getDescription()
          Returns a human readable description of the Frequency.
 int getNumberOfUnits()
           
 TimeUnit getUnit()
           
 int hashCode()
           
 MDDate next(MDDate date)
          Returns the next date in the sequency based on this frequency.
 MDDate previous(MDDate date)
          Returns the previous date in the sequency based on this frequency.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleFrequency

public SimpleFrequency(TimeUnit unit)
Creates a SimpleFrequency based on a single TimeUnit

Parameters:
unit - a TimeUnit

SimpleFrequency

public SimpleFrequency(TimeUnit unit,
                       int num)
Creates a SimpleFrequency based on a multiple of a TimeUnit

Parameters:
unit - a TimeUnit
num - a positive number
Method Detail

next

public MDDate next(MDDate date)
Returns the next date in the sequency based on this frequency.

Specified by:
next in interface Frequency
Parameters:
date - the initial MDDate
Returns:
the next date in the sequency based on this frequency.

previous

public MDDate previous(MDDate date)
Returns the previous date in the sequency based on this frequency.

Specified by:
previous in interface Frequency
Parameters:
date - the initial MDDate
Returns:
the previous date in the sequency based on this frequency

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

fromString

public static SimpleFrequency fromString(java.lang.String string)

getUnit

public TimeUnit getUnit()

getNumberOfUnits

public int getNumberOfUnits()

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getDescription

public java.lang.String getDescription()
Description copied from interface: Frequency
Returns a human readable description of the Frequency.

Specified by:
getDescription in interface Frequency
Returns:
a human readable description of the Frequency.