Interval extends PartiallyOrdered<Interval<C>> implements Comparable<Interval<C>> { @Override public Interval<C> intersect(final Interval<C> that) { if(this == MAGIC || that == NULL) { return that; } if(this == NULL) { return NULL; } if(that == MAGIC) { return new Interval(this.dimension, this.range); } if(this.dimension == that.dimension) { if(this.isConnected(that)) { return new Interval(this.dimension, this.range.intersection(that.range)); } return new Interval(this.dimension); } return NULL; } private  Interval(); private  Interval(int dimension); private  Interval(final Range<C> range);  Interval(int dimension, final Range<C> range); @Override Interval<C> intersect(final Interval<C> that); @Override Interval<C> union(final Interval<C> that); Interval<C> coalesce(final Interval<C> that); @Override double measure(); boolean isConnected(final Interval<C> that); boolean hasAll(); boolean hasNone(); boolean isDimensionless(); int getDimension(); @Beta Difference<C> minus(final Interval<C> that); @Beta Difference<C> complement(); Interval<C> ahead(); Interval<C> behind(); Interval<C> gap(final Interval<C> that); boolean before(final Interval<C> that); boolean after(final Interval<C> that); boolean between(final Interval<C> that, final Interval<C> other); boolean overlaps(final Interval<C> that); boolean then(final Interval<C> that); boolean starts(final Interval<C> that); boolean ends(final Interval<C> that); @Override boolean equals(final Object that); @Override String toString(); @Override int hashCode(); Range<C> toRange(); @Override int compareTo(Interval<C> that); final static Interval NULL; final static Interval MAGIC; }
@Test public void testIntersect() { assertEquals(a.intersect(c), a); assertEquals(c.intersect(a), a); assertEquals(a.intersect(a), a); }