@Override public Iterator<Interval> intervalsIterator(SimplifiedIntervalList intervals) { return intervals.iterator(); }
/** * Constructor to build a predicate that applies an arbitrary predicate to not-before intervals from the * iterator. * * @param supplyList The SimplifiedList of intervals to test the predicate against * @param testPredicate The predicate to use when testing an interval against the supply * @param defaultValue The value for the test if no comparison interval can be found in the list. */ public SkippingIntervalPredicate( SimplifiedIntervalList supplyList, BiPredicate<Interval, Interval> testPredicate, boolean defaultValue ) { this.supply = supplyList.iterator(); this.testPredicate = testPredicate; this.defaultValue = defaultValue; activeInterval = null; if (supply.hasNext()) { activeInterval = supply.next(); } }
/** * Return the intersection of all subintervals in two interval lists. * * @param that A simplified list of intervals * * @return A new simplified interval list whose intervals are all subintervals of this and that. */ public SimplifiedIntervalList intersect(SimplifiedIntervalList that) { Iterator<Interval> theseIntervals = this.iterator(); Iterator<Interval> thoseIntervals = that.iterator(); Interval thisCurrent = getNextIfAvailable.apply(theseIntervals); Interval thatCurrent = getNextIfAvailable.apply(thoseIntervals); List<Interval> collected = new ArrayList<>(); while (thisCurrent != null && thatCurrent != null) { if (thisCurrent.overlaps(thatCurrent)) { collected.add(thisCurrent.overlap(thatCurrent)); } if (thisCurrent.isBefore(thatCurrent.getEnd())) { thisCurrent = getNextIfAvailable.apply(theseIntervals); } else { thatCurrent = getNextIfAvailable.apply(thoseIntervals); } } return new SimplifiedIntervalList(collected); }