Class IntervalSetsOverlaysIterator<T>
- Type Parameters:
T- the type of values associated with the interval sets
- All Implemented Interfaces:
Iterator<IntervalSetsOverlaysIterator.IntervalSetsOverlay<T>>
This class is useful for analyzing temporal or spatial overlaps between multiple interval-based data sets. It efficiently computes all distinct regions where different combinations of intervals intersect.
Zero-length Intervals (points) are filtered out during construction and do not contribute to the overlap analysis. Only intervals with non-zero length are included into the result.
Example usage:
Map<String, IntervalSet> intervalSets = Map.of(
"A", IntervalSet.of(0, 10),
"B", IntervalSet.of(5, 15)
);
IntervalSetsOverlaysIterator<String> iterator = new IntervalSetsOverlaysIterator<>(intervalSets);
while (iterator.hasNext()) {
IntervalSetsOverlay<String> overlay = iterator.next();
System.out.println("Interval: " + overlay.interval() + ", Values: " + overlay.values());
}
Example output:
Interval: Interval[min=-∞, max=0.0], Values: [] Interval: Interval[min=0.0, max=5.0], Values: [A] Interval: Interval[min=5.0, max=10.0], Values: [A, B] Interval: Interval[min=10.0, max=15.0], Values: [B] Interval: Interval[min=15.0, max=∞], Values: []
- Author:
- Alexander Morozov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents an overlay result containing an interval and the set of values whose intervals overlap with it. -
Constructor Summary
ConstructorsConstructorDescriptionIntervalSetsOverlaysIterator(Map<T, IntervalSet> intervalSets) Constructs a new iterator that analyzes overlaps within the specified interval sets over the entire universe (negative to positive infinity).IntervalSetsOverlaysIterator(Map<T, IntervalSet> intervalSets, boolean forwardDirection) IntervalSetsOverlaysIterator(Map<T, IntervalSet> intervalSets, IntervalSet withinIntervalSet) Constructs a new iterator that analyzes overlaps within the specified interval sets constrained to the given containing interval set.IntervalSetsOverlaysIterator(Map<T, IntervalSet> intervalSets, IntervalSet withinIntervalSet, boolean forwardDirection) Constructs a new iterator that analyzes overlaps within the specified interval sets constrained to the given containing interval set. -
Method Summary
Modifier and TypeMethodDescriptionbooleanhasNext()voidinsertBoundaryPoints(Interval interval) next()overlaysStream(List<IntervalSet> intervalSets) Converts a list of interval sets into a stream of overlay results where each interval set is associated with itself as the value, over the entire universe.overlaysStream(List<IntervalSet> intervalSets, IntervalSet withinIntervalSet) Converts a list of interval sets into a stream of overlay results constrained to a specific containing interval set, where each interval set is associated with itself as the value.static <T> Stream<IntervalSetsOverlaysIterator.IntervalSetsOverlay<T>> overlaysStream(Map<T, IntervalSet> intervalSets) Converts a map of values to their associated interval sets into a stream of overlay results over the entire universe (negative to positive infinity).static <T> Stream<IntervalSetsOverlaysIterator.IntervalSetsOverlay<T>> overlaysStream(Map<T, IntervalSet> intervalSets, IntervalSet withinIntervalSet) Converts a map of values to their associated interval sets into a stream of overlay results constrained to a specific containing interval set.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
IntervalSetsOverlaysIterator
Constructs a new iterator that analyzes overlaps within the specified interval sets constrained to the given containing interval set.- Parameters:
intervalSets- a map of values to their associated interval sets. Only non-zero length intervals are considered for overlap analysis.withinIntervalSet- the containing interval set that constrains the analysis. Only sub-intervals that have non-zero intersection with this set will be returned.
-
IntervalSetsOverlaysIterator
public IntervalSetsOverlaysIterator(Map<T, IntervalSet> intervalSets, IntervalSet withinIntervalSet, boolean forwardDirection) Constructs a new iterator that analyzes overlaps within the specified interval sets constrained to the given containing interval set.- Parameters:
intervalSets- a map of values to their associated interval sets. Only non-zero length intervals are considered for overlap analysis.withinIntervalSet- the containing interval set that constrains the analysis. Only sub-intervals that have non-zero intersection with this set will be returned.forwardDirection- the direction of iteration. Iftrue, iterates through overlaps in forward direction (increasing order); iffalse, iterates in reverse direction (decreasing order).
-
IntervalSetsOverlaysIterator
Constructs a new iterator that analyzes overlaps within the specified interval sets over the entire universe (negative to positive infinity).- Parameters:
intervalSets- a map of values to their associated interval sets. Only non-zero length intervals are considered for overlap analysis.
-
IntervalSetsOverlaysIterator
-
-
Method Details
-
overlaysStream
public static <T> Stream<IntervalSetsOverlaysIterator.IntervalSetsOverlay<T>> overlaysStream(Map<T, IntervalSet> intervalSets) Converts a map of values to their associated interval sets into a stream of overlay results over the entire universe (negative to positive infinity).This is a convenience method that creates an
IntervalSetsOverlaysIteratorand converts it to aStreamfor functional-style processing.- Type Parameters:
T- the type of values associated with the interval sets- Parameters:
intervalSets- a map of values to their associated interval sets. Only non-zero length intervals are considered for overlap analysis.- Returns:
- a stream of
IntervalSetsOverlaysIterator.IntervalSetsOverlayobjects representing the partitioned intervals and their overlapping values across the entire universe - See Also:
-
overlaysStream
public static <T> Stream<IntervalSetsOverlaysIterator.IntervalSetsOverlay<T>> overlaysStream(Map<T, IntervalSet> intervalSets, IntervalSet withinIntervalSet) Converts a map of values to their associated interval sets into a stream of overlay results constrained to a specific containing interval set.This method allows analyzing overlaps only within a specified region of interest, filtering out intervals that don't intersect with the containing set.
- Type Parameters:
T- the type of values associated with the interval sets- Parameters:
intervalSets- a map of values to their associated interval sets. Only non-zero length intervals are considered for overlap analysis.withinIntervalSet- the containing interval set that constrains the analysis. Only sub-intervals that have non-zero intersection with this set will be included in the stream.- Returns:
- a stream of
IntervalSetsOverlaysIterator.IntervalSetsOverlayobjects representing the partitioned intervals and their overlapping values within the specified containing set - See Also:
-
overlaysStream
public static Stream<IntervalSetsOverlaysIterator.IntervalSetsOverlay<IntervalSet>> overlaysStream(List<IntervalSet> intervalSets) Converts a list of interval sets into a stream of overlay results where each interval set is associated with itself as the value, over the entire universe.This is a convenience method for cases where you want to analyze the overlaps between interval sets themselves rather than external values. Each interval set serves as both the data and the associated value.
- Parameters:
intervalSets- a list of interval sets to analyze for overlaps. Only non-zero length intervals are considered.- Returns:
- a stream of
IntervalSetsOverlaysIterator.IntervalSetsOverlayobjects where the values are the interval sets themselves that overlap in each partitioned interval - See Also:
-
overlaysStream
public static Stream<IntervalSetsOverlaysIterator.IntervalSetsOverlay<IntervalSet>> overlaysStream(List<IntervalSet> intervalSets, IntervalSet withinIntervalSet) Converts a list of interval sets into a stream of overlay results constrained to a specific containing interval set, where each interval set is associated with itself as the value.This method combines the functionality of analyzing interval set overlaps with constraining the analysis to a specific region of interest.
- Parameters:
intervalSets- a list of interval sets to analyze for overlaps. Only non-zero length intervals are considered.withinIntervalSet- the containing interval set that constrains the analysis. Only sub-intervals that have non-zero intersection with this set will be included in the stream.- Returns:
- a stream of
IntervalSetsOverlaysIterator.IntervalSetsOverlayobjects where the values are the interval sets themselves that overlap within the specified containing set - See Also:
-
insertBoundaryPoints
-
hasNext
public boolean hasNext() -
next
-