Class IntervalSetsOverlaysIterator<T>

java.lang.Object
com.amalgamasimulation.core.scheduling.IntervalSetsOverlaysIterator<T>
Type Parameters:
T - the type of values associated with the interval sets
All Implemented Interfaces:
Iterator<IntervalSetsOverlaysIterator.IntervalSetsOverlay<T>>

public class IntervalSetsOverlaysIterator<T> extends Object implements Iterator<IntervalSetsOverlaysIterator.IntervalSetsOverlay<T>>
An iterator that partitions a specified interval into sub-intervals based on boundary points from multiple interval sets and returns for each sub-interval the set of values whose intervals overlap with it within a specified containing interval set.

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
  • Constructor Details

    • IntervalSetsOverlaysIterator

      public 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.
      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. If true, iterates through overlaps in forward direction (increasing order); if false, iterates in reverse direction (decreasing order).
    • IntervalSetsOverlaysIterator

      public IntervalSetsOverlaysIterator(Map<T,IntervalSet> intervalSets)
      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

      public IntervalSetsOverlaysIterator(Map<T,IntervalSet> intervalSets, boolean forwardDirection)
  • 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 IntervalSetsOverlaysIterator and converts it to a Stream for 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.IntervalSetsOverlay objects 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.IntervalSetsOverlay objects representing the partitioned intervals and their overlapping values within the specified containing set
      See Also:
    • overlaysStream

      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.IntervalSetsOverlay objects 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.IntervalSetsOverlay objects where the values are the interval sets themselves that overlap within the specified containing set
      See Also:
    • insertBoundaryPoints

      public void insertBoundaryPoints(Interval interval)
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
    • next

      Specified by:
      next in interface Iterator<T>