org.joda.time.base
Class AbstractInterval

java.lang.Object
  extended byorg.joda.time.base.AbstractInterval
All Implemented Interfaces:
ReadableInterval
Direct Known Subclasses:
BaseInterval

public abstract class AbstractInterval
extends Object
implements ReadableInterval

AbstractInterval provides the common behaviour for time intervals.

This class should generally not be used directly by API users. The ReadableInterval interface should be used when different kinds of intervals are to be referenced.

AbstractInterval subclasses may be mutable and not thread-safe.

Since:
1.0
Author:
Brian S O'Neill, Stephen Colebourne

Method Summary
 boolean contains(long millisInstant)
          Does this time interval contain the specified millisecond instant.
 boolean contains(ReadableInstant instant)
          Does this time interval contain the specified instant.
 boolean contains(ReadableInterval interval)
          Does this time interval contain the specified time interval completely.
 boolean containsNow()
          Does this time interval contain the current instant.
 boolean equals(Object readableInterval)
          Compares this object with the specified object for equality based on start and end millis plus the chronology.
 DateTime getEnd()
          Gets the end of this time interval, which is exclusive, as a DateTime.
 DateTime getStart()
          Gets the start of this time interval, which is inclusive, as a DateTime.
 int hashCode()
          Hashcode compatible with equals method.
 boolean isAfter(long millisInstant)
          Is this time interval after the specified millisecond instant.
 boolean isAfter(ReadableInstant instant)
          Is this time interval after the specified instant.
 boolean isAfter(ReadableInterval interval)
          Is this time interval entirely after the specified interval.
 boolean isAfterNow()
          Is this time interval after the current instant.
 boolean isBefore(long millisInstant)
          Is this time interval before the specified millisecond instant.
 boolean isBefore(ReadableInstant instant)
          Is this time interval before the specified instant.
 boolean isBefore(ReadableInterval interval)
          Is this time interval entirely before the specified instant.
 boolean isBeforeNow()
          Is this time interval before the current instant.
 boolean overlaps(ReadableInterval interval)
          Does this time interval overlap the specified time interval.
 Duration toDuration()
          Gets the duration of this time interval.
 long toDurationMillis()
          Gets the duration of this time interval in milliseconds.
 Interval toInterval()
          Get this interval as an immutable Interval object.
 MutableInterval toMutableInterval()
          Get this time interval as a MutableInterval.
 Period toPeriod()
          Converts the duration of the interval to a Period using the All period type.
 Period toPeriod(PeriodType type)
          Converts the duration of the interval to a Period using the specified period type.
 String toString()
          Output a string in ISO8601 interval format.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.time.ReadableInterval
getChronology, getEndMillis, getStartMillis
 

Method Detail

getStart

public DateTime getStart()
Gets the start of this time interval, which is inclusive, as a DateTime.

Specified by:
getStart in interface ReadableInterval
Returns:
the start of the time interval

getEnd

public DateTime getEnd()
Gets the end of this time interval, which is exclusive, as a DateTime.

Specified by:
getEnd in interface ReadableInterval
Returns:
the end of the time interval

contains

public boolean contains(long millisInstant)
Does this time interval contain the specified millisecond instant.

Intervals are inclusive of the start instant and exclusive of the end.

Parameters:
millisInstant - the instant to compare to, millisecond instant from 1970-01-01T00:00:00Z
Returns:
true if this time interval contains the millisecond

containsNow

public boolean containsNow()
Does this time interval contain the current instant.

Intervals are inclusive of the start instant and exclusive of the end.

Returns:
true if this time interval contains the current instant

contains

public boolean contains(ReadableInstant instant)
Does this time interval contain the specified instant.

Intervals are inclusive of the start instant and exclusive of the end.

Specified by:
contains in interface ReadableInterval
Parameters:
instant - the instant, null means now
Returns:
true if this time interval contains the instant

contains

public boolean contains(ReadableInterval interval)
Does this time interval contain the specified time interval completely.

Intervals are inclusive of the start instant and exclusive of the end.

Specified by:
contains in interface ReadableInterval
Parameters:
interval - the time interval to compare to, null means now
Returns:
true if this time interval contains the time interval

overlaps

public boolean overlaps(ReadableInterval interval)
Does this time interval overlap the specified time interval.

The intervals overlap if at least some of the time interval is in common. Intervals are inclusive of the start instant and exclusive of the end.

Specified by:
overlaps in interface ReadableInterval
Parameters:
interval - the time interval to compare to, null means now
Returns:
true if the time intervals overlap

isBefore

public boolean isBefore(long millisInstant)
Is this time interval before the specified millisecond instant.

Intervals are inclusive of the start instant and exclusive of the end.

Parameters:
millisInstant - the instant to compare to, millisecond instant from 1970-01-01T00:00:00Z
Returns:
true if this time interval is before the instant

isBeforeNow

public boolean isBeforeNow()
Is this time interval before the current instant.

Intervals are inclusive of the start instant and exclusive of the end.

Returns:
true if this time interval is before the current instant

isBefore

public boolean isBefore(ReadableInstant instant)
Is this time interval before the specified instant.

Intervals are inclusive of the start instant and exclusive of the end.

Specified by:
isBefore in interface ReadableInterval
Parameters:
instant - the instant to compare to, null means now
Returns:
true if this time interval is before the instant

isBefore

public boolean isBefore(ReadableInterval interval)
Is this time interval entirely before the specified instant.

Intervals are inclusive of the start instant and exclusive of the end.

Specified by:
isBefore in interface ReadableInterval
Parameters:
interval - the interval to compare to, null means now
Returns:
true if this time interval is before the interval specified

isAfter

public boolean isAfter(long millisInstant)
Is this time interval after the specified millisecond instant.

Intervals are inclusive of the start instant and exclusive of the end.

Parameters:
millisInstant - the instant to compare to, millisecond instant from 1970-01-01T00:00:00Z
Returns:
true if this time interval is after the instant

isAfterNow

public boolean isAfterNow()
Is this time interval after the current instant.

Intervals are inclusive of the start instant and exclusive of the end.

Returns:
true if this time interval is after the current instant

isAfter

public boolean isAfter(ReadableInstant instant)
Is this time interval after the specified instant.

Intervals are inclusive of the start instant and exclusive of the end.

Specified by:
isAfter in interface ReadableInterval
Parameters:
instant - the instant to compare to, null means now
Returns:
true if this time interval is after the instant

isAfter

public boolean isAfter(ReadableInterval interval)
Is this time interval entirely after the specified interval.

Intervals are inclusive of the start instant and exclusive of the end. Only the end time of the specified interval is used in the comparison.

Specified by:
isAfter in interface ReadableInterval
Parameters:
interval - the interval to compare to, null means now
Returns:
true if this time interval is after the interval specified

toInterval

public Interval toInterval()
Get this interval as an immutable Interval object.

Specified by:
toInterval in interface ReadableInterval
Returns:
the interval as an Interval object

toMutableInterval

public MutableInterval toMutableInterval()
Get this time interval as a MutableInterval.

This will always return a new MutableInterval with the same interval.

Specified by:
toMutableInterval in interface ReadableInterval
Returns:
the time interval as a MutableInterval object

toDurationMillis

public long toDurationMillis()
Gets the duration of this time interval in milliseconds.

The duration is equal to the end millis minus the start millis.

Specified by:
toDurationMillis in interface ReadableInterval
Returns:
the duration of the time interval in milliseconds
Throws:
ArithmeticException - if the duration exceeds the capacity of a long

toDuration

public Duration toDuration()
Gets the duration of this time interval.

The duration is equal to the end millis minus the start millis.

Specified by:
toDuration in interface ReadableInterval
Returns:
the duration of the time interval
Throws:
ArithmeticException - if the duration exceeds the capacity of a long

toPeriod

public Period toPeriod()
Converts the duration of the interval to a Period using the All period type.

This method should be used to exract the field values describing the difference between the start and end instants.

Specified by:
toPeriod in interface ReadableInterval
Returns:
a time period derived from the interval

toPeriod

public Period toPeriod(PeriodType type)
Converts the duration of the interval to a Period using the specified period type.

This method should be used to exract the field values describing the difference between the start and end instants.

Specified by:
toPeriod in interface ReadableInterval
Parameters:
type - the requested type of the duration, null means AllType
Returns:
a time period derived from the interval

equals

public boolean equals(Object readableInterval)
Compares this object with the specified object for equality based on start and end millis plus the chronology. All ReadableInterval instances are accepted.

To compare the duration of two time intervals, use toDuration() to get the durations and compare those.

Specified by:
equals in interface ReadableInterval
Parameters:
readableInterval - a readable interval to check against
Returns:
true if the start and end millis are equal

hashCode

public int hashCode()
Hashcode compatible with equals method.

Specified by:
hashCode in interface ReadableInterval
Returns:
suitable hashcode

toString

public String toString()
Output a string in ISO8601 interval format.

Specified by:
toString in interface ReadableInterval
Returns:
re-parsable string


Copyright © 2002-2008 Joda.org. All Rights Reserved.