private ClusterException(Collection<? extends Throwable> exceptions) { super( exceptions.size() + " exceptions were thrown. The first exception is listed as a cause.", exceptions.iterator().next()); ArrayList<Throwable> temp = new ArrayList<>(); temp.addAll(exceptions); this.exceptions = Collections.unmodifiableCollection(temp); }
public void clean() { // the lock protects removal from a concurrent put which could otherwise mutate the // queue after it has been removed from the map synchronized (unsent) { Iterator<ConcurrentLinkedQueue<ClientRequest>> iterator = unsent.values().iterator(); while (iterator.hasNext()) { ConcurrentLinkedQueue<ClientRequest> requests = iterator.next(); if (requests.isEmpty()) iterator.remove(); } } }
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) @CollectionSize.Require(absent = ZERO) public void testIterator_removeAffectsBackingCollection() { int originalSize = collection.size(); Iterator<E> iterator = collection.iterator(); Object element = iterator.next(); // If it's an Entry, it may become invalid once it's removed from the Map. Copy it. if (element instanceof Entry) { Entry<?, ?> entry = (Entry<?, ?>) element; element = mapEntry(entry.getKey(), entry.getValue()); } assertTrue(collection.contains(element)); // sanity check iterator.remove(); assertFalse(collection.contains(element)); assertEquals(originalSize - 1, collection.size()); }
private void assertCollectionSize(Collection<?> collection, int size) { assertEquals(size, collection.size()); if (size > 0) { assertFalse(collection.isEmpty()); } else { assertTrue(collection.isEmpty()); } assertEquals(size, Iterables.size(collection)); assertEquals(size, Iterators.size(collection.iterator())); } }
/** * Removes all elements in the given Collection that aren't accepted by the given Filter. */ public static <E> void retainAll(Collection<E> elems, Predicate<? super E> filter) { for (Iterator<E> iter = elems.iterator(); iter.hasNext();) { E elem = iter.next(); if ( ! filter.test(elem)) { iter.remove(); } } }
/** * Collect any {@link AsyncConfigurer} beans through autowiring. */ @Autowired(required = false) void setConfigurers(Collection<AsyncConfigurer> configurers) { if (CollectionUtils.isEmpty(configurers)) { return; } if (configurers.size() > 1) { throw new IllegalStateException("Only one AsyncConfigurer may exist"); } AsyncConfigurer configurer = configurers.iterator().next(); this.executor = configurer::getAsyncExecutor; this.exceptionHandler = configurer::getAsyncUncaughtExceptionHandler; }
@Override public String toString() { StringBuilder builder = new StringBuilder("["); for (Iterator<?> iterator = getContent().iterator(); iterator.hasNext();) { Object expression = iterator.next(); builder.append(expression.toString()); if (iterator.hasNext()) { builder.append(getToStringInfix()); } } builder.append("]"); return builder.toString(); }
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) @CollectionSize.Require(absent = ZERO) public void testIteratorRemove_unsupported() { Iterator<E> iterator = collection.iterator(); iterator.next(); try { iterator.remove(); fail("iterator.remove() should throw UnsupportedOperationException"); } catch (UnsupportedOperationException expected) { } expectUnchanged(); assertTrue(collection.contains(e0())); }
private String style(Collection<?> value) { StringBuilder result = new StringBuilder(value.size() * 8 + 16); result.append(getCollectionTypeString(value)).append('['); for (Iterator<?> i = value.iterator(); i.hasNext();) { result.append(style(i.next())); if (i.hasNext()) { result.append(',').append(' '); } } if (value.isEmpty()) { result.append(EMPTY); } result.append("]"); return result.toString(); }
@Autowired(required = false) void setConfigurers(Collection<TransactionManagementConfigurer> configurers) { if (CollectionUtils.isEmpty(configurers)) { return; } if (configurers.size() > 1) { throw new IllegalStateException("Only one TransactionManagementConfigurer may exist"); } TransactionManagementConfigurer configurer = configurers.iterator().next(); this.txManager = configurer.annotationDrivenTransactionManager(); }