T - the temporal type of time points in intervalsI - the type of intervals stored in the treepublic class IntervalTree<T,I extends ChronoInterval<T>> extends AbstractCollection<I>
Represents an augmented interval tree holding intervals for easy and quick search.
The semantics of augmented interval trees (AVL-trees) is described for example in Wikipedia. Empty intervals are never stored. An interval tree is also like a read-only collection of intervals.
| Modifier and Type | Class and Description |
|---|---|
static interface |
IntervalTree.Visitor<I>
Callback interface for tree traversal according to the visitor pattern design.
|
| Modifier and Type | Method and Description |
|---|---|
void |
accept(IntervalTree.Visitor<I> visitor)
Accepts given interval tree visitor.
|
boolean |
contains(ChronoInterval<T> interval)
Queries if given interval is stored in this tree.
|
List<I> |
findIntersections(ChronoInterval<T> interval)
Obtains a list of all stored intervals which intersect given search interval.
|
List<I> |
findIntersections(T timepoint)
Obtains a list of all stored intervals which intersect given point in time.
|
boolean |
isEmpty()
Checks if this tree contains no intervals.
|
Iterator<I> |
iterator()
Collects all stored intervals into a new list and then obtains an iterator for this list.
|
static <T,I extends ChronoInterval<T>> |
on(TimeLine<T> timeLine,
Collection<I> intervals)
Creates an interval tree on a timeline filled with given intervals.
|
static <I extends ChronoInterval<PlainTime>> |
onClockAxis(Collection<I> intervals)
Creates an interval tree on the clock axis filled with given clock intervals.
|
static <I extends ChronoInterval<PlainDate>> |
onDateAxis(Collection<I> intervals)
Creates an interval tree on the date axis filled with given date intervals.
|
static IntervalTree<Instant,SimpleInterval<Instant>> |
onInstantTimeLine(Collection<SimpleInterval<Instant>> intervals)
Creates an interval tree for the type
java.time.Instant filled with given simple intervals. |
static <I extends ChronoInterval<Moment>> |
onMomentAxis(Collection<I> intervals)
Creates an interval tree on the moment axis (UTC) filled with given moment intervals.
|
static <I extends ChronoInterval<PlainTimestamp>> |
onTimestampAxis(Collection<I> intervals)
Creates an interval tree on the timestamp axis filled with given timestamp intervals.
|
static IntervalTree<Date,SimpleInterval<Date>> |
onTraditionalTimeLine(Collection<SimpleInterval<Date>> intervals)
Creates an interval tree for the legacy type
java.util.Date filled with given simple intervals. |
int |
size()
Obtains the count of stored intervals.
|
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringequals, getClass, hashCode, notify, notifyAll, wait, wait, waitequals, hashCode, parallelStream, removeIf, spliterator, streampublic static <I extends ChronoInterval<PlainDate>> IntervalTree<PlainDate,I> onDateAxis(Collection<I> intervals)
Creates an interval tree on the date axis filled with given date intervals.
I - the type of intervals stored in the treeintervals - collection of date intervalsArithmeticException - if the count of intervals overflows an intpublic static <I extends ChronoInterval<PlainTime>> IntervalTree<PlainTime,I> onClockAxis(Collection<I> intervals)
Creates an interval tree on the clock axis filled with given clock intervals.
I - the type of intervals stored in the treeintervals - collection of clock intervalsArithmeticException - if the count of intervals overflows an intpublic static <I extends ChronoInterval<PlainTimestamp>> IntervalTree<PlainTimestamp,I> onTimestampAxis(Collection<I> intervals)
Creates an interval tree on the timestamp axis filled with given timestamp intervals.
I - the type of intervals stored in the treeintervals - collection of timestamp intervalsArithmeticException - if the count of intervals overflows an intpublic static <I extends ChronoInterval<Moment>> IntervalTree<Moment,I> onMomentAxis(Collection<I> intervals)
Creates an interval tree on the moment axis (UTC) filled with given moment intervals.
I - the type of intervals stored in the treeintervals - collection of moment intervalsArithmeticException - if the count of intervals overflows an intpublic static IntervalTree<Date,SimpleInterval<Date>> onTraditionalTimeLine(Collection<SimpleInterval<Date>> intervals)
Creates an interval tree for the legacy type java.util.Date filled with given simple intervals.
intervals - collection of simple intervalsArithmeticException - if the count of intervals overflows an intpublic static IntervalTree<Instant,SimpleInterval<Instant>> onInstantTimeLine(Collection<SimpleInterval<Instant>> intervals)
Creates an interval tree for the type java.time.Instant filled with given simple intervals.
intervals - collection of simple intervalsArithmeticException - if the count of intervals overflows an intpublic static <T,I extends ChronoInterval<T>> IntervalTree<T,I> on(TimeLine<T> timeLine, Collection<I> intervals)
Creates an interval tree on a timeline filled with given intervals.
T - the temporal type of time points in intervalsI - the type of intervals stored in the treetimeLine - the underlying timelineintervals - collection of intervalsArithmeticException - if the count of intervals overflows an intTimeAxis,
CalendarFamily.getTimeLine(String),
CalendarFamily.getTimeLine(net.time4j.engine.VariantSource),
CalendarYear.timeline(),
CalendarQuarter.timeline(),
CalendarMonth.timeline(),
CalendarWeek.timeline()public boolean isEmpty()
Checks if this tree contains no intervals.
isEmpty in interface Collection<I extends ChronoInterval<T>>isEmpty in class AbstractCollection<I extends ChronoInterval<T>>true if empty else falsepublic Iterator<I> iterator()
Collects all stored intervals into a new list and then obtains an iterator for this list.
This method is only useful if users really want to iterate over all stored
intervals. Otherwise a customized Visitor-implementation is more flexible.
iterator in interface Iterable<I extends ChronoInterval<T>>iterator in interface Collection<I extends ChronoInterval<T>>iterator in class AbstractCollection<I extends ChronoInterval<T>>Iterator which is read-onlypublic int size()
Obtains the count of stored intervals.
size in interface Collection<I extends ChronoInterval<T>>size in class AbstractCollection<I extends ChronoInterval<T>>public List<I> findIntersections(T timepoint)
Obtains a list of all stored intervals which intersect given point in time.
timepoint - the point in time to be checkedpublic List<I> findIntersections(ChronoInterval<T> interval)
Obtains a list of all stored intervals which intersect given search interval.
interval - the search intervalpublic boolean contains(ChronoInterval<T> interval)
Queries if given interval is stored in this tree.
interval - the interval to be checkedpublic void accept(IntervalTree.Visitor<I> visitor)
Accepts given interval tree visitor.
All nodes will be visited in ascending order, first sorted by start then by end.
Example:
DateInterval i1 = DateInterval.between(PlainDate.of(2014, 2, 28), PlainDate.of(2014, 5, 31));
DateInterval i2 = DateInterval.between(PlainDate.of(2014, 5, 31), PlainDate.of(2014, 6, 1));
DateInterval i3 = DateInterval.between(PlainDate.of(2014, 6, 15), PlainDate.of(2014, 6, 30));
IntervalTree<PlainDate, DateInterval> tree = IntervalTree.onDateAxis(Arrays.asList(i3, i1, i2));
tree.accept(
(interval) -> {
System.out.println(interval);
return false;
}
);
// output:
[2014-02-28/2014-05-31]
[2014-05-31/2014-06-01]
[2014-06-15/2014-06-30]
visitor - the interval tree visitorCopyright © 2014–2021. All rights reserved.