net.fortuna.ical4j.model
Class Period

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

public class Period
extends java.lang.Object
implements java.io.Serializable, java.lang.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

Field Summary
static int INCLUSIVE_END
           
static int INCLUSIVE_START
           
 
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(java.lang.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(java.lang.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(java.lang.Object o)
          Uses ObjectUtils to test equality.
 Dur getDuration()
          Returns the duration of this period.
 DateTime getEnd()
          Returns the end date of this period.
 DateTime getStart()
           
 int hashCode()
          Uses HashCodeBuilder to build hashcode.
 boolean includes(java.util.Date date)
          Determines if the specified date occurs within this period (inclusive of period start and end).
 boolean includes(java.util.Date date, boolean inclusive)
          Deprecated. use includes(Date, int) instead.
 boolean includes(java.util.Date date, int inclusiveMask)
          Decides whether a date falls within this period.
 boolean intersects(Period period)
          Decides whether this period intersects with another one.
 boolean isEmpty()
          An empty period is one that consumes no time.
 void setTimeZone(TimeZone timezone)
          Updates the start and (possible) end times of this period to reflect the specified timezone status.
 void setUtc(boolean utc)
          Updates the start and (possible) end times of this period to reflect the specified UTC timezone status.
 PeriodList subtract(Period period)
          Creates a set of periods resulting from the subtraction of the specified period from this one.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INCLUSIVE_START

public static final int INCLUSIVE_START
See Also:
Constant Field Values

INCLUSIVE_END

public static final int INCLUSIVE_END
See Also:
Constant Field Values
Constructor Detail

Period

public Period(java.lang.String aValue)
       throws java.text.ParseException
Constructor.

Parameters:
aValue - a string representation of a period
Throws:
java.text.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(java.util.Date date)
Determines if the specified date occurs within this period (inclusive of period start and end).

Parameters:
date -
Returns:
true if the specified date occurs within the current period

includes

public final boolean includes(java.util.Date date,
                              boolean inclusive)
Deprecated. use includes(Date, int) instead.

Parameters:
date -
inclusive -
Returns:

includes

public final boolean includes(java.util.Date date,
                              int inclusiveMask)
Decides whether a date falls within this period.

Parameters:
date - the date to be tested
inclusive - specifies whether period start and end are included in the calculation
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

subtract

public final PeriodList subtract(Period period)
Creates a set of periods resulting from the subtraction of the specified period from this one. If the specified period is completely contained in this period, the resulting list will contain two periods. Otherwise it will contain one. If the specified period does not interest this period a list containing this period is returned. If this period is completely contained within the specified period an empty period list is returned.

Parameters:
period -
Returns:
a list containing zero, one or two periods.

isEmpty

public final boolean isEmpty()
An empty period is one that consumes no time.

Returns:
true if this period consumes no time, otherwise false

setUtc

public void setUtc(boolean utc)
Updates the start and (possible) end times of this period to reflect the specified UTC timezone status.

Parameters:
utc -

setTimeZone

public final void setTimeZone(TimeZone timezone)
Updates the start and (possible) end times of this period to reflect the specified timezone status.

Parameters:
timezone -

toString

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

compareTo

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

compareTo

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

Parameters:
arg0 -
Returns:

equals

public final boolean equals(java.lang.Object o)
Uses ObjectUtils to test equality.

Overrides:
equals in class java.lang.Object
Parameters:
o - object being compared for equality
Returns:
true if the objects are equal, false otherwise

hashCode

public final int hashCode()
Uses HashCodeBuilder to build hashcode.

Overrides:
hashCode in class java.lang.Object


Copyright © 2004-2007 Modularity. All Rights Reserved.