net.fortuna.ical4j.model

Class Period

Implemented Interfaces:
Comparable, Serializable

public class Period
extends java.lang.Object
implements Serializable, Comparable

$Id: Period.java,v 1.25 2008/12/16 12:34:52 fortuna Exp $ [Apr 14, 2004] 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.

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(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)
Uses EqualsBuilder 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(Date date)
Determines if the specified date occurs within this period (inclusive of period start and end).
boolean
includes(Date date, boolean inclusive)
Deprecated. use Period.includes(Date, int) instead.
boolean
includes(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.
String
toString()

Field Details

INCLUSIVE_END

public static final int INCLUSIVE_END
Field Value:
2

INCLUSIVE_START

public static final int INCLUSIVE_START
Field Value:
1

Constructor Details

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

Period

public Period(String aValue)
            throws ParseException
Constructor.
Parameters:
aValue - a string representation of a period

Method Details

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

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

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

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

compareTo

public final int compareTo(Object arg0)

compareTo

public final int compareTo(Period arg0)
Compares the specified period with this period.
Parameters:
arg0 -
Returns:

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

equals

public final boolean equals(Object o)
Uses EqualsBuilder to test equality.
Parameters:
o - object being compared for equality
Returns:
true if the objects are equal, false otherwise

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.

hashCode

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

includes

public final boolean includes(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(Date date,
                              boolean inclusive)

Deprecated. use Period.includes(Date, int) instead.

Parameters:
date -
inclusive -
Returns:

includes

public final boolean includes(Date date,
                              int inclusiveMask)
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

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.

isEmpty

public final boolean isEmpty()
An empty period is one that consumes no time.
Returns:
true if this period consumes no time, otherwise false

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 -

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 -

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.

toString

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