Returns an ImmutableSortedSet containing the same values in the given domain plain RangeSet#contains contained by this range set. Note: a.asSet(d).equals(b.asSet(d)) does not imply a.equals(b)! For example, a and b could be [2..4] and
(DiscreteDomain<C> domain)
| 403 | |
| 404 | |
| 405 | public ImmutableSortedSet<C> asSet(DiscreteDomain<C> domain) { |
| 406 | checkNotNull(domain); |
| 407 | if (isEmpty()) { |
| 408 | return ImmutableSortedSet.of(); |
| 409 | } |
| 410 | Range<C> span = span().canonical(domain); |
| 411 | if (!span.hasLowerBound()) { |
| 412 | // according to the spec of canonical, neither this ImmutableRangeSet nor |
| 413 | // the range have a lower bound |
| 414 | throw new IllegalArgumentException("Neither the DiscreteDomain nor this range set are bounded below"); |
| 415 | } else if (!span.hasUpperBound()) { |
| 416 | try { |
| 417 | domain.maxValue(); |
| 418 | } catch (NoSuchElementException e) { |
| 419 | throw new IllegalArgumentException("Neither the DiscreteDomain nor this range set are bounded above"); |
| 420 | } |
| 421 | } |
| 422 | return new AsSet(domain); |
| 423 | } |
| 424 | |
| 425 | private final class AsSet extends ImmutableSortedSet<C> { |
| 426 | private final DiscreteDomain<C> domain; |
no test coverage detected