RangeBoundary implements Comparable<RangeBoundary<C>> { @Override public int compareTo(RangeBoundary<C> other) { if (this.infinity && other.infinity) { return this.infinitySign - other.infinitySign; } if (this.infinity) { return this.isPlusInfinity() ? 1 : -1; } if (other.infinity) { return other.isPlusInfinity() ? -1 : 1; } return this.value.compareTo(other.value); } private  RangeBoundary(C value, boolean infinity, int infinitySign);  RangeBoundary(C value); @Override int compareTo(RangeBoundary<C> other); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void shouldCompareTwoPlusInfinitiesAsEqual() { RangeBoundary<Integer> boundaryA = new RangeBoundary<Integer>(null); RangeBoundary<Integer> boundaryB = new RangeBoundary<Integer>(null); assertThat(boundaryA.compareTo(boundaryB)).isEqualTo(0); }
@Test public void shouldCompareTwoConcreteValuesUsingTheirComparator() { RangeBoundary<Integer> boundaryA = new RangeBoundary<Integer>(10); RangeBoundary<Integer> boundaryB = new RangeBoundary<Integer>(5); assertThat(boundaryA.compareTo(boundaryB)).isGreaterThan(0); }