Class AbstractInterval
- All Implemented Interfaces:
ReadableInterval
- Direct Known Subclasses:
BaseInterval
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckInterval(long start, long end) Validates an interval.booleancontains(long millisInstant) Does this time interval contain the specified millisecond instant.booleancontains(ReadableInstant instant) Does this time interval contain the specified instant.booleancontains(ReadableInterval interval) Does this time interval contain the specified time interval.booleanDoes this time interval contain the current instant.booleanCompares this object with the specified object for equality based on start and end millis plus the chronology.getEnd()Gets the end of this time interval, which is exclusive, as a DateTime.getStart()Gets the start of this time interval, which is inclusive, as a DateTime.inthashCode()Hashcode compatible with equals method.booleanisAfter(long millisInstant) Is this time interval after the specified millisecond instant.booleanisAfter(ReadableInstant instant) Is this time interval after the specified instant.booleanisAfter(ReadableInterval interval) Is this time interval entirely after the specified interval.booleanIs this time interval after the current instant.booleanisBefore(long millisInstant) Is this time interval before the specified millisecond instant.booleanisBefore(ReadableInstant instant) Is this time interval before the specified instant.booleanisBefore(ReadableInterval interval) Is this time interval entirely before the specified instant.booleanIs this time interval before the current instant.booleanisEqual(ReadableInterval other) Is this interval equal to the specified interval ignoring the chronology.booleanoverlaps(ReadableInterval interval) Does this time interval overlap the specified time interval.Gets the duration of this time interval.longGets the duration of this time interval in milliseconds.Get this interval as an immutableIntervalobject.Get this time interval as aMutableInterval.toPeriod()Converts the duration of the interval to aPeriodusing the All period type.toPeriod(PeriodType type) Converts the duration of the interval to aPeriodusing the specified period type.toString()Output a string in ISO8601 interval format.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.joda.time.ReadableInterval
getChronology, getEndMillis, getStartMillis
-
Constructor Details
-
AbstractInterval
protected AbstractInterval()Constructor.
-
-
Method Details
-
checkInterval
protected void checkInterval(long start, long end) Validates an interval.- Parameters:
start- the start instant in millisecondsend- the end instant in milliseconds- Throws:
IllegalArgumentException- if the interval is invalid
-
getStart
Gets the start of this time interval, which is inclusive, as a DateTime.- Specified by:
getStartin interfaceReadableInterval- Returns:
- the start of the time interval
-
getEnd
Gets the end of this time interval, which is exclusive, as a DateTime.- Specified by:
getEndin interfaceReadableInterval- Returns:
- the end of the time interval
-
contains
public boolean contains(long millisInstant) Does this time interval contain the specified millisecond instant.Non-zero duration intervals are inclusive of the start instant and exclusive of the end. A zero duration interval cannot contain anything.
- 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.Non-zero duration intervals are inclusive of the start instant and exclusive of the end. A zero duration interval cannot contain anything.
- Returns:
- true if this time interval contains the current instant
-
contains
Does this time interval contain the specified 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 anullparameter will have the same effect as callingcontainsNow().- Specified by:
containsin interfaceReadableInterval- Parameters:
instant- the instant, null means now- Returns:
- true if this time interval contains the instant
-
contains
Does this time interval contain the specified time 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
containsmethod 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 anullparameter will have the same effect as callingcontainsNow().- Specified by:
containsin interfaceReadableInterval- Parameters:
interval- the time interval to compare to, null means a zero duration interval now- Returns:
- true if this time interval contains the time interval
-
overlaps
Does this time interval overlap the specified time 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
- Specified by:
overlapsin interfaceReadableInterval- Parameters:
interval- the time interval to compare to, null means a zero length interval now- Returns:
- true if the time intervals overlap
-
isEqual
Is this interval equal to the specified interval ignoring the chronology.This compares the underlying instants, ignoring the chronology.
- Parameters:
other- a readable interval to check against- Returns:
- true if the intervals are equal comparing the start and end millis
- Since:
- 2.3
-
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
Is this time interval before the specified instant.Intervals are inclusive of the start instant and exclusive of the end.
- Specified by:
isBeforein interfaceReadableInterval- Parameters:
instant- the instant to compare to, null means now- Returns:
- true if this time interval is before the instant
-
isBefore
Is this time interval entirely before the specified instant.Intervals are inclusive of the start instant and exclusive of the end.
- Specified by:
isBeforein interfaceReadableInterval- 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
Is this time interval after the specified instant.Intervals are inclusive of the start instant and exclusive of the end.
- Specified by:
isAfterin interfaceReadableInterval- Parameters:
instant- the instant to compare to, null means now- Returns:
- true if this time interval is after the instant
-
isAfter
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:
isAfterin interfaceReadableInterval- Parameters:
interval- the interval to compare to, null means now- Returns:
- true if this time interval is after the interval specified
-
toInterval
Get this interval as an immutableIntervalobject.- Specified by:
toIntervalin interfaceReadableInterval- Returns:
- the interval as an Interval object
-
toMutableInterval
Get this time interval as aMutableInterval.This will always return a new
MutableIntervalwith the same interval.- Specified by:
toMutableIntervalin interfaceReadableInterval- 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:
toDurationMillisin interfaceReadableInterval- Returns:
- the duration of the time interval in milliseconds
- Throws:
ArithmeticException- if the duration exceeds the capacity of a long
-
toDuration
Gets the duration of this time interval.The duration is equal to the end millis minus the start millis.
- Specified by:
toDurationin interfaceReadableInterval- Returns:
- the duration of the time interval
- Throws:
ArithmeticException- if the duration exceeds the capacity of a long
-
toPeriod
Converts the duration of the interval to aPeriodusing the All period type.This method should be used to extract the field values describing the difference between the start and end instants.
- Specified by:
toPeriodin interfaceReadableInterval- Returns:
- a time period derived from the interval
-
toPeriod
Converts the duration of the interval to aPeriodusing the specified period type.This method should be used to extract the field values describing the difference between the start and end instants.
- Specified by:
toPeriodin interfaceReadableInterval- Parameters:
type- the requested type of the duration, null means AllType- Returns:
- a time period derived from the interval
-
equals
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:
equalsin interfaceReadableInterval- Overrides:
equalsin classObject- Parameters:
readableInterval- a readable interval to check against- Returns:
- true if the intervals are equal comparing the start millis, end millis and chronology
-
hashCode
public int hashCode()Hashcode compatible with equals method.- Specified by:
hashCodein interfaceReadableInterval- Overrides:
hashCodein classObject- Returns:
- suitable hashcode
-
toString
Output a string in ISO8601 interval format.From version 2.1, the string includes the time zone offset.
- Specified by:
toStringin interfaceReadableInterval- Overrides:
toStringin classObject- Returns:
- re-parsable string (in the default zone)
-