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)
| 325 | * @since 14.0 |
| 326 | */ |
| 327 | public static <C extends Comparable<?>> Range<C> encloseAll(Iterable<C> values) { |
| 328 | checkNotNull(values); |
| 329 | if (values instanceof ContiguousSet) { |
| 330 | return ((ContiguousSet<C>) values).range(); |
| 331 | } |
| 332 | Iterator<C> valueIterator = values.iterator(); |
| 333 | C min = checkNotNull(valueIterator.next()); |
| 334 | C max = min; |
| 335 | while (valueIterator.hasNext()) { |
| 336 | C value = checkNotNull(valueIterator.next()); |
| 337 | min = Ordering.natural().min(min, value); |
| 338 | max = Ordering.natural().max(max, value); |
| 339 | } |
| 340 | return closed(min, max); |
| 341 | } |
| 342 | |
| 343 | final Cut<C> lowerBound; |
| 344 | final Cut<C> upperBound; |