net.fortuna.ical4j.model
Class Period

java.lang.Object
  extended bynet.fortuna.ical4j.model.Period
All Implemented Interfaces:
Comparable, Serializable

public class Period
extends Object
implements Serializable, Comparable

Defines a period of time. A period may be specified as either a start date and end date, or a start date and duration. NOTE: End dates and durations are implicitly derived when not explicitly specified. This means that you cannot rely on the returned values from the getters to deduce whether a period has an explicit end date or duration.

Author:
Ben Fortuna
See Also:
Serialized Form

Constructor Summary
Period(DateTime start, DateTime end)
          Constructs a new period with the specied start and end date.
Period(DateTime start, Dur duration)
          Constructs a new period with the specified start date and duration.
Period(String aValue)
          Constructor.
 
Method Summary
 Period add(Period period)
          Creates a period that encompasses both this period and another one.
 boolean adjacent(Period period)
          Decides whether these periods are serial without a gap.
 boolean after(Period period)
          Decides whether this period starts after the given period ends.
 boolean before(Period period)
          Decides whether this period is completed before the given period starts.
 int compareTo(Object arg0)
           
 int compareTo(Period arg0)
          Compares the specified period with this period.
 boolean contains(Period period)
          Decides whether the given period is completely contained within this one.
 boolean equals(Object o)
          Overrides the equality test, compares fields of instances for equality.
 Dur getDuration()
          Returns the duration of this period.
 DateTime getEnd()
          Returns the end date of this period.
 DateTime getStart()
           
 int hashCode()
          Override hashCode() with code that checks fields in this object.
 boolean includes(Date date)
          Decides whether a date falls within this period.
 boolean intersects(Period period)
          Decides whether this period intersects with another one.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Period

public Period(String aValue)
       throws ParseException
Constructor.

Parameters:
aValue - a string representation of a period
Throws:
ParseException - where the specified string is not a valid representation

Period

public Period(DateTime start,
              DateTime end)
Constructs a new period with the specied start and end date.

Parameters:
start - the start date of the period
end - the end date of the period

Period

public Period(DateTime start,
              Dur duration)
Constructs a new period with the specified start date and duration.

Parameters:
start - the start date of the period
duration - the duration of the period
Method Detail

getDuration

public final Dur getDuration()
Returns the duration of this period. If an explicit duration is not specified, the duration is derived from the end date.

Returns:
the duration of this period in milliseconds.

getEnd

public final DateTime getEnd()
Returns the end date of this period. If an explicit end date is not specified, the end date is derived from the duration.

Returns:
the end date of this period.

getStart

public final DateTime getStart()
Returns:
Returns the start.

includes

public final boolean includes(Date date)
Decides whether a date falls within this period.

Parameters:
date - the date to be tested
Returns:
true if the date is in the perod, false otherwise

before

public final boolean before(Period period)
Decides whether this period is completed before the given period starts.

Parameters:
period - a period that may or may not start after this period ends
Returns:
true if the specified period starts after this periods ends, otherwise false

after

public final boolean after(Period period)
Decides whether this period starts after the given period ends.

Parameters:
period - a period that may or may not end before this period starts
Returns:
true if the specified period end before this periods starts, otherwise false

intersects

public final boolean intersects(Period period)
Decides whether this period intersects with another one.

Parameters:
period - a possible intersecting period
Returns:
true if the specified period intersects this one, false otherwise.

adjacent

public final boolean adjacent(Period period)
Decides whether these periods are serial without a gap.

Returns:
true if one period immediately follows the other, false otherwise

contains

public final boolean contains(Period period)
Decides whether the given period is completely contained within this one.

Parameters:
period - the period that may be contained by this one
Returns:
true if this period covers all the dates of the specified period, otherwise false

add

public final Period add(Period period)
Creates a period that encompasses both this period and another one. If the other period is null, return a copy of this period. NOTE: Resulting periods are specified by explicitly setting a start date and end date (i.e. durations are implied).

Parameters:
period - the period to add to this one
Returns:
a period

toString

public final String toString()
See Also:
Object.toString()

compareTo

public final int compareTo(Object arg0)
Specified by:
compareTo in interface Comparable

compareTo

public final int compareTo(Period arg0)
Compares the specified period with this period.

Parameters:
arg0 -
Returns:

equals

public final boolean equals(Object o)
Overrides the equality test, compares fields of instances for equality.

Parameters:
o - object being compared for equality
Returns:
true if the objects are equal, false otherwise

hashCode

public final int hashCode()
Override hashCode() with code that checks fields in this object.

Returns:
hascode for this object