@Test public void testOverlap() { IntervalSet a,b; a = new IntervalSet("1-4"); b = new IntervalSet("5-6"); assertFalse(a.overlaps(b)); assertFalse(b.overlaps(a)); a = new IntervalSet("1-4"); b = new IntervalSet("4"); assertTrue(a.overlaps(b)); assertTrue(b.overlaps(a)); a = new IntervalSet("1-4"); b = new IntervalSet("2-3"); assertTrue(a.overlaps(b)); assertTrue(b.overlaps(a)); a = new IntervalSet("1-4"); b = new IntervalSet(""); assertFalse(a.overlaps(b)); assertFalse(b.overlaps(a)); }
public boolean overlaps(IntervalSet other) { if( !this.isEmpty() && !other.isEmpty() ) { Iterator<Interval> a = this.iterator(); Iterator<Interval> b = other.iterator(); Interval nextA = a.next(); Interval nextB = b.next(); if(nextA.overlaps(nextB)) { return true; } while(a.hasNext() || b.hasNext()) { if( nextA.getEnd() <= nextB.getEnd() ) { if( a.hasNext() ) { nextA = a.next(); } else { return false; } } else { if( b.hasNext() ) { nextB = b.next(); } else { return false; } } if(nextA.overlaps(nextB)) { return true; } } } return false; }
IntervalSet extends TreeSet<Interval> implements Comparable<IntervalSet> { public boolean overlaps(IntervalSet other) { if( !this.isEmpty() && !other.isEmpty() ) { Iterator<Interval> a = this.iterator(); Iterator<Interval> b = other.iterator(); Interval nextA = a.next(); Interval nextB = b.next(); if(nextA.overlaps(nextB)) { return true; } while(a.hasNext() || b.hasNext()) { if( nextA.getEnd() <= nextB.getEnd() ) { if( a.hasNext() ) { nextA = a.next(); } else { return false; } } else { if( b.hasNext() ) { nextB = b.next(); } else { return false; } } if(nextA.overlaps(nextB)) { return true; } } } return false; } }
IntervalSet extends TreeSet<Interval> implements Comparable<IntervalSet> { public boolean overlaps(IntervalSet other) { if( !this.isEmpty() && !other.isEmpty() ) { Iterator<Interval> a = this.iterator(); Iterator<Interval> b = other.iterator(); Interval nextA = a.next(); Interval nextB = b.next(); if(nextA.overlaps(nextB)) { return true; } while(a.hasNext() || b.hasNext()) { if( nextA.getEnd() <= nextB.getEnd() ) { if( a.hasNext() ) { nextA = a.next(); } else { return false; } } else { if( b.hasNext() ) { nextB = b.next(); } else { return false; } } if(nextA.overlaps(nextB)) { return true; } } } return false; } IntervalSet();  IntervalSet(Collection<? extends Interval> c);  IntervalSet(Comparator<? super Interval> comparator);  IntervalSet(SortedSet<Integer> intSet);  IntervalSet(String selStr);  IntervalSet(Interval... infiniteInterval); }
IntervalSet extends TreeSet<Interval> implements Comparable<IntervalSet> { public boolean overlaps(IntervalSet other) { if( !this.isEmpty() && !other.isEmpty() ) { Iterator<Interval> a = this.iterator(); Iterator<Interval> b = other.iterator(); Interval nextA = a.next(); Interval nextB = b.next(); if(nextA.overlaps(nextB)) { return true; } while(a.hasNext() || b.hasNext()) { if( nextA.getEnd() <= nextB.getEnd() ) { if( a.hasNext() ) { nextA = a.next(); } else { return false; } } else { if( b.hasNext() ) { nextB = b.next(); } else { return false; } } if(nextA.overlaps(nextB)) { return true; } } } return false; } IntervalSet();  IntervalSet(Collection<? extends Interval> c);  IntervalSet(Comparator<? super Interval> comparator);  IntervalSet(SortedSet<Integer> intSet);  IntervalSet(String selStr);  IntervalSet(Interval... infiniteInterval); void addInterval(int start, int end); TreeSet<Integer> getIntegerSet(); IntervalSet getMergedIntervalSet(); boolean overlaps(IntervalSet other); boolean contains(Integer point); @Override int compareTo(IntervalSet other); @Override String toString(); static boolean isValidSelectionString(String selStr); String toSelectionString(); }
IntervalSet extends TreeSet<Interval> implements Comparable<IntervalSet> { public boolean overlaps(IntervalSet other) { if( !this.isEmpty() && !other.isEmpty() ) { Iterator<Interval> a = this.iterator(); Iterator<Interval> b = other.iterator(); Interval nextA = a.next(); Interval nextB = b.next(); if(nextA.overlaps(nextB)) { return true; } while(a.hasNext() || b.hasNext()) { if( nextA.getEnd() <= nextB.getEnd() ) { if( a.hasNext() ) { nextA = a.next(); } else { return false; } } else { if( b.hasNext() ) { nextB = b.next(); } else { return false; } } if(nextA.overlaps(nextB)) { return true; } } } return false; } IntervalSet();  IntervalSet(Collection<? extends Interval> c);  IntervalSet(Comparator<? super Interval> comparator);  IntervalSet(SortedSet<Integer> intSet);  IntervalSet(String selStr);  IntervalSet(Interval... infiniteInterval); void addInterval(int start, int end); TreeSet<Integer> getIntegerSet(); IntervalSet getMergedIntervalSet(); boolean overlaps(IntervalSet other); boolean contains(Integer point); @Override int compareTo(IntervalSet other); @Override String toString(); static boolean isValidSelectionString(String selStr); String toSelectionString();  }