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

Method getOnlyElement

guava/src/com/google/common/collect/Iterables.java:261–264  ·  view source on GitHub ↗

Returns the single element contained in {@code iterable}. <p><b>Java 8+ users:</b> the {@code Stream} equivalent to this method is {@code stream.collect(MoreCollectors.onlyElement())}. @throws NoSuchElementException if the iterable is empty @throws IllegalArgumentException if the iterable contains

(Iterable<T> iterable)

Source from the content-addressed store, hash-verified

259 * @throws IllegalArgumentException if the iterable contains multiple elements
260 */
261 @ParametricNullness
262 public static <T extends @Nullable Object> T getOnlyElement(Iterable<T> iterable) {
263 return Iterators.getOnlyElement(iterable.iterator());
264 }
265
266 /**
267 * Returns the single element contained in {@code iterable}, or {@code defaultValue} if the

Callers 15

testWriteThroughEntryMethod · 0.95
testForwardingObjectMethod · 0.95
testFutureBashMethod · 0.95
asImmutableMethod · 0.95
asImmutableMethod · 0.45
asImmutableMethod · 0.45
buildMethod · 0.45
buildOrThrowMethod · 0.45

Calls 2

getOnlyElementMethod · 0.95
iteratorMethod · 0.65