Returns the minimal range that plain Range#contains(Comparable) contains all of the given values. The returned range is plain BoundType#CLOSED closed on both ends. @throws ClassCastException if the parameters are not mutually comparable @throws NoSuchElementException if {@c
(Iterable<C> values)
| 344 | |
| 345 | |
| 346 | public static <C extends Comparable<?>> Range<C> encloseAll(Iterable<C> values) { |
| 347 | checkNotNull(values); |
| 348 | if (values instanceof ContiguousSet) { |
| 349 | return ((ContiguousSet<C>) values).range(); |
| 350 | } |
| 351 | Iterator<C> valueIterator = values.iterator(); |
| 352 | C min = checkNotNull(valueIterator.next()); |
| 353 | C max = min; |
| 354 | while (valueIterator.hasNext()) { |
| 355 | C value = checkNotNull(valueIterator.next()); |
| 356 | min = Ordering.natural().min(min, value); |
| 357 | max = Ordering.natural().max(max, value); |
| 358 | } |
| 359 | return closed(min, max); |
| 360 | } |
| 361 | |
| 362 | final Cut<C> lowerBound; |
| 363 | final Cut<C> upperBound; |