MCPcopy
hub / github.com/google/guava / encloseAll

Method encloseAll

guava/src/com/google/common/collect/Range.java:304–322  ·  view source on GitHub ↗

Returns the minimal range that {@linkplain Range#contains(Comparable) contains} all of the given values. The returned range is {@linkplain BoundType#CLOSED closed} on both ends. @throws ClassCastException if the values are not mutually comparable @throws NoSuchElementException if {@code values} is

(Iterable<C> values)

Source from the content-addressed store, hash-verified

302 * @since 14.0
303 */
304 public static <C extends Comparable<?>> Range<C> encloseAll(Iterable<C> values) {
305 checkNotNull(values);
306 if (values instanceof SortedSet) {
307 SortedSet<C> set = (SortedSet<C>) values;
308 Comparator<?> comparator = set.comparator();
309 if (Ordering.<C>natural().equals(comparator) || comparator == null) {
310 return closed(set.first(), set.last());
311 }
312 }
313 Iterator<C> valueIterator = values.iterator();
314 C min = checkNotNull(valueIterator.next());
315 C max = min;
316 while (valueIterator.hasNext()) {
317 C value = checkNotNull(valueIterator.next());
318 min = Ordering.<C>natural().min(min, value);
319 max = Ordering.<C>natural().max(max, value);
320 }
321 return closed(min, max);
322 }
323
324 final Cut<C> lowerBound;
325 final Cut<C> upperBound;

Callers 4

testEncloseAllMethod · 0.95
testEncloseAll_emptyMethod · 0.95
checkedCreateMethod · 0.95

Calls 12

naturalMethod · 0.95
closedMethod · 0.95
comparatorMethod · 0.65
equalsMethod · 0.65
iteratorMethod · 0.65
nextMethod · 0.65
checkNotNullMethod · 0.45
firstMethod · 0.45
lastMethod · 0.45
hasNextMethod · 0.45
minMethod · 0.45
maxMethod · 0.45

Tested by 4

testEncloseAllMethod · 0.76
testEncloseAll_emptyMethod · 0.76
checkedCreateMethod · 0.76