Returns a ContiguousSet containing the same values in the given domain plain Range#contains contained by the range. @throws IllegalArgumentException if neither range nor the domain has a lower bound, or if neither has an upper bound @since 13.0
(Range<C> range, DiscreteDomain<C> domain)
| 51 | */ |
| 52 | |
| 53 | public static <C extends Comparable> ContiguousSet<C> create(Range<C> range, DiscreteDomain<C> domain) { |
| 54 | checkNotNull(range); |
| 55 | checkNotNull(domain); |
| 56 | Range<C> effectiveRange = range; |
| 57 | try { |
| 58 | if (!range.hasLowerBound()) { |
| 59 | effectiveRange = effectiveRange.intersection(Range.atLeast(domain.minValue())); |
| 60 | } |
| 61 | if (!range.hasUpperBound()) { |
| 62 | effectiveRange = effectiveRange.intersection(Range.atMost(domain.maxValue())); |
| 63 | } |
| 64 | } catch (NoSuchElementException e) { |
| 65 | throw new IllegalArgumentException(e); |
| 66 | } |
| 67 | |
| 68 | // Per class spec, we are allowed to throw CCE if necessary |
| 69 | |
| 70 | boolean empty = effectiveRange.isEmpty() || Range.compareOrThrow(range.lowerBound.leastValueAbove(domain), range.upperBound.greatestValueBelow(domain)) > 0; |
| 71 | return empty |
| 72 | ? new EmptyContiguousSet<C>(domain) |
| 73 | : new RegularContiguousSet<C>(effectiveRange, domain); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | final DiscreteDomain<C> domain; |
no test coverage detected