Merge pull request #10469 from dreis2211:iterator-to-remove-if

* pr/10469:
  Replace some loops with removeIf()
pull/10469/merge
Stephane Nicoll 7 years ago
commit cf30392564

@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.http;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.junit.Test;
@ -114,13 +113,8 @@ public class HttpMessageConvertersTests {
@Override
protected List<HttpMessageConverter<?>> postProcessConverters(
List<HttpMessageConverter<?>> converters) {
for (Iterator<HttpMessageConverter<?>> iterator = converters
.iterator(); iterator.hasNext();) {
if (iterator
.next() instanceof MappingJackson2XmlHttpMessageConverter) {
iterator.remove();
}
}
converters.removeIf(
converter -> converter instanceof MappingJackson2XmlHttpMessageConverter);
return converters;
}
};
@ -144,13 +138,8 @@ public class HttpMessageConvertersTests {
@Override
protected List<HttpMessageConverter<?>> postProcessPartConverters(
List<HttpMessageConverter<?>> converters) {
for (Iterator<HttpMessageConverter<?>> iterator = converters
.iterator(); iterator.hasNext();) {
if (iterator
.next() instanceof MappingJackson2XmlHttpMessageConverter) {
iterator.remove();
}
}
converters.removeIf(
converter -> converter instanceof MappingJackson2XmlHttpMessageConverter);
return converters;
}
};

@ -20,7 +20,6 @@ import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
@ -280,11 +279,7 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda
beans.add(beanName);
}
}
for (Iterator<String> iterator = beans.iterator(); iterator.hasNext();) {
if (isScopedTarget(iterator.next())) {
iterator.remove();
}
}
beans.removeIf(this::isScopedTarget);
return beans.toArray(new String[beans.size()]);
}

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -149,12 +148,8 @@ public class TestRestTemplate {
interceptors = Collections.emptyList();
}
interceptors = new ArrayList<>(interceptors);
Iterator<ClientHttpRequestInterceptor> iterator = interceptors.iterator();
while (iterator.hasNext()) {
if (iterator.next() instanceof BasicAuthorizationInterceptor) {
iterator.remove();
}
}
interceptors.removeIf(
interceptor -> interceptor instanceof BasicAuthorizationInterceptor);
interceptors.add(new BasicAuthorizationInterceptor(username, password));
restTemplate.setInterceptors(interceptors);
}

@ -22,7 +22,6 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
@ -149,12 +148,7 @@ public class ConfigurationMetadata {
if (candidates == null || candidates.isEmpty()) {
return null;
}
ListIterator<ItemMetadata> it = candidates.listIterator();
while (it.hasNext()) {
if (!it.next().hasSameType(metadata)) {
it.remove();
}
}
candidates.removeIf(itemMetadata -> !itemMetadata.hasSameType(metadata));
if (candidates.size() == 1) {
return candidates.get(0);
}

@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
@ -530,12 +529,7 @@ public class ConfigFileApplicationListener
}
private void removeUnprocessedDefaultProfiles() {
for (Iterator<Profile> iterator = this.profiles.iterator(); iterator
.hasNext();) {
if (iterator.next().isDefaultProfile()) {
iterator.remove();
}
}
this.profiles.removeIf(Profile::isDefaultProfile);
}
private void addProfiles(Set<Profile> profiles) {

Loading…
Cancel
Save