|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.joda.time.base.AbstractInterval
public abstract class AbstractInterval
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.
Constructor Summary | |
---|---|
protected |
AbstractInterval()
Constructor. |
Method Summary | |
---|---|
protected void |
checkInterval(long start,
long end)
Validates an interval. |
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. |
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 |
isEqual(ReadableInterval other)
Is this interval equal to the specified interval ignoring the chronology. |
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 |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.joda.time.ReadableInterval |
---|
getChronology, getEndMillis, getStartMillis |
Constructor Detail |
---|
protected AbstractInterval()
Method Detail |
---|
protected void checkInterval(long start, long end)
start
- the start instant in millisecondsend
- the end instant in milliseconds
IllegalArgumentException
- if the interval is invalidpublic DateTime getStart()
getStart
in interface ReadableInterval
public DateTime getEnd()
getEnd
in interface ReadableInterval
public boolean contains(long millisInstant)
Non-zero duration intervals are inclusive of the start instant and exclusive of the end. A zero duration interval cannot contain anything.
millisInstant
- the instant to compare to,
millisecond instant from 1970-01-01T00:00:00Z
public boolean containsNow()
Non-zero duration intervals are inclusive of the start instant and exclusive of the end. A zero duration interval cannot contain anything.
public boolean contains(ReadableInstant instant)
Non-zero duration intervals are inclusive of the start instant and exclusive of the end. A zero duration interval cannot contain anything.
For example:
[09:00 to 10:00) contains 08:59 = false (before start) [09:00 to 10:00) contains 09:00 = true [09:00 to 10:00) contains 09:59 = true [09:00 to 10:00) contains 10:00 = false (equals end) [09:00 to 10:00) contains 10:01 = false (after end) [14:00 to 14:00) contains 14:00 = false (zero duration contains nothing)Passing in a
null
parameter will have the same effect as
calling containsNow()
.
contains
in interface ReadableInterval
instant
- the instant, null means now
public boolean contains(ReadableInterval interval)
Non-zero duration intervals are inclusive of the start instant and exclusive of the end. The other interval is contained if this interval wholly contains, starts, finishes or equals it. A zero duration interval cannot contain anything.
When two intervals are compared the result is one of three states:
(a) they abut, (b) there is a gap between them, (c) they overlap.
The contains
method is not related to these states.
In particular, a zero duration interval is contained at the start of
a larger interval, but does not overlap (it abuts instead).
For example:
[09:00 to 10:00) contains [09:00 to 10:00) = true [09:00 to 10:00) contains [09:00 to 09:30) = true [09:00 to 10:00) contains [09:30 to 10:00) = true [09:00 to 10:00) contains [09:15 to 09:45) = true [09:00 to 10:00) contains [09:00 to 09:00) = true [09:00 to 10:00) contains [08:59 to 10:00) = false (otherStart before thisStart) [09:00 to 10:00) contains [09:00 to 10:01) = false (otherEnd after thisEnd) [09:00 to 10:00) contains [10:00 to 10:00) = false (otherStart equals thisEnd) [14:00 to 14:00) contains [14:00 to 14:00) = false (zero duration contains nothing)Passing in a
null
parameter will have the same effect as
calling containsNow()
.
contains
in interface ReadableInterval
interval
- the time interval to compare to, null means a zero duration interval now
public boolean overlaps(ReadableInterval interval)
Intervals are inclusive of the start instant and exclusive of the end. An interval overlaps another if it shares some common part of the datetime continuum.
When two intervals are compared the result is one of three states: (a) they abut, (b) there is a gap between them, (c) they overlap. The abuts state takes precedence over the other two, thus a zero duration interval at the start of a larger interval abuts and does not overlap.
For example:
[09:00 to 10:00) overlaps [08:00 to 08:30) = false (completely before) [09:00 to 10:00) overlaps [08:00 to 09:00) = false (abuts before) [09:00 to 10:00) overlaps [08:00 to 09:30) = true [09:00 to 10:00) overlaps [08:00 to 10:00) = true [09:00 to 10:00) overlaps [08:00 to 11:00) = true [09:00 to 10:00) overlaps [09:00 to 09:00) = false (abuts before) [09:00 to 10:00) overlaps [09:00 to 09:30) = true [09:00 to 10:00) overlaps [09:00 to 10:00) = true [09:00 to 10:00) overlaps [09:00 to 11:00) = true [09:00 to 10:00) overlaps [09:30 to 09:30) = true [09:00 to 10:00) overlaps [09:30 to 10:00) = true [09:00 to 10:00) overlaps [09:30 to 11:00) = true [09:00 to 10:00) overlaps [10:00 to 10:00) = false (abuts after) [09:00 to 10:00) overlaps [10:00 to 11:00) = false (abuts after) [09:00 to 10:00) overlaps [10:30 to 11:00) = false (completely after) [14:00 to 14:00) overlaps [14:00 to 14:00) = false (abuts before and after) [14:00 to 14:00) overlaps [13:00 to 15:00) = true
overlaps
in interface ReadableInterval
interval
- the time interval to compare to, null means a zero length interval now
public boolean isEqual(ReadableInterval other)
This compares the underlying instants, ignoring the chronology.
other
- a readable interval to check against
public boolean isBefore(long millisInstant)
Intervals are inclusive of the start instant and exclusive of the end.
millisInstant
- the instant to compare to,
millisecond instant from 1970-01-01T00:00:00Z
public boolean isBeforeNow()
Intervals are inclusive of the start instant and exclusive of the end.
public boolean isBefore(ReadableInstant instant)
Intervals are inclusive of the start instant and exclusive of the end.
isBefore
in interface ReadableInterval
instant
- the instant to compare to, null means now
public boolean isBefore(ReadableInterval interval)
Intervals are inclusive of the start instant and exclusive of the end.
isBefore
in interface ReadableInterval
interval
- the interval to compare to, null means now
public boolean isAfter(long millisInstant)
Intervals are inclusive of the start instant and exclusive of the end.
millisInstant
- the instant to compare to,
millisecond instant from 1970-01-01T00:00:00Z
public boolean isAfterNow()
Intervals are inclusive of the start instant and exclusive of the end.
public boolean isAfter(ReadableInstant instant)
Intervals are inclusive of the start instant and exclusive of the end.
isAfter
in interface ReadableInterval
instant
- the instant to compare to, null means now
public boolean isAfter(ReadableInterval 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.
isAfter
in interface ReadableInterval
interval
- the interval to compare to, null means now
public Interval toInterval()
Interval
object.
toInterval
in interface ReadableInterval
public MutableInterval toMutableInterval()
MutableInterval
.
This will always return a new MutableInterval
with the same interval.
toMutableInterval
in interface ReadableInterval
public long toDurationMillis()
The duration is equal to the end millis minus the start millis.
toDurationMillis
in interface ReadableInterval
ArithmeticException
- if the duration exceeds the capacity of a longpublic Duration toDuration()
The duration is equal to the end millis minus the start millis.
toDuration
in interface ReadableInterval
ArithmeticException
- if the duration exceeds the capacity of a longpublic Period toPeriod()
Period
using the
All period type.
This method should be used to extract the field values describing the difference between the start and end instants.
toPeriod
in interface ReadableInterval
public Period toPeriod(PeriodType type)
Period
using the
specified period type.
This method should be used to extract the field values describing the difference between the start and end instants.
toPeriod
in interface ReadableInterval
type
- the requested type of the duration, null means AllType
public boolean equals(Object readableInterval)
To compare the duration of two time intervals, use toDuration()
to get the durations and compare those.
equals
in interface ReadableInterval
equals
in class Object
readableInterval
- a readable interval to check against
public int hashCode()
hashCode
in interface ReadableInterval
hashCode
in class Object
public String toString()
From version 2.1, the string includes the time zone offset.
toString
in interface ReadableInterval
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |