RangeGeometries { public static <N extends Number & Comparable<? super N>> Rectangle range(final Range<N> range) { checkNotNull(range); if (range.isEmpty()) { throw new IllegalArgumentException("range must not be empty"); } if (!range.hasLowerBound() || !range.hasUpperBound()) { throw new IllegalArgumentException("range must have lower and upper bounds"); } Number lowerEndpoint = range.lowerEndpoint(); BoundType lowerBoundType = range.lowerBoundType(); Number upperEndpoint = range.upperEndpoint(); BoundType upperBoundType = range.upperBoundType(); double x1 = lowerBoundType == BoundType.OPEN ? lowerEndpoint.doubleValue() + 1.0d : lowerEndpoint.doubleValue(); double y1 = 0.0d; double x2 = upperBoundType == BoundType.OPEN ? upperEndpoint.doubleValue() - 1.0d : upperEndpoint.doubleValue(); double y2 = 1.0d; return Geometries.rectangle(x1, y1, x2, y2); } private  RangeGeometries(); static Point singleton(final N value); static Rectangle closed(final N lower, final N upper); static Rectangle closedOpen(final N lower, final N upper); static Rectangle openClosed(final N lower, final N upper); static Rectangle open(final N lower, final N upper); static Rectangle range(final Range<N> range);  }
@Test(expected=NullPointerException.class) public void testRangeNullRange() { range(null); }
@Test(expected=IllegalArgumentException.class) public void testRangeNoLowerBound() { range(Range.lessThan(42L)); }
@Test(expected=IllegalArgumentException.class) public void testRangeNoUpperBound() { range(Range.greaterThan(42L)); }
@Test public void testRange() { assertEquals(Geometries.rectangle(42.0d, 0.0d, 42.0d, 1.0d), range(Range.singleton(42L))); assertEquals(Geometries.rectangle(24.0d, 0.0d, 42.0d, 1.0d), range(Range.closed(24L, 42L))); assertEquals(Geometries.rectangle(24.0d, 0.0d, 41.0d, 1.0d), range(Range.closedOpen(24L, 42L))); assertEquals(Geometries.rectangle(25.0d, 0.0d, 42.0d, 1.0d), range(Range.openClosed(24L, 42L))); assertEquals(Geometries.rectangle(25.0d, 0.0d, 41.0d, 1.0d), range(Range.open(24L, 42L))); }