diff --git a/spring-core/src/main/java/org/springframework/util/CompositeMap.java b/spring-core/src/main/java/org/springframework/util/CompositeMap.java index 3cf9cb55cf..6678806df4 100644 --- a/spring-core/src/main/java/org/springframework/util/CompositeMap.java +++ b/spring-core/src/main/java/org/springframework/util/CompositeMap.java @@ -26,7 +26,9 @@ import java.util.function.Consumer; import org.springframework.lang.Nullable; /** - * Composite map that combines two other maps. This type is created via + * Composite map that combines two other maps. + * + *

This type is created via * {@link CollectionUtils#compositeMap(Map, Map, BiFunction, Consumer)}. * * @author Arjen Poutsma diff --git a/spring-core/src/main/java/org/springframework/util/FilteredIterator.java b/spring-core/src/main/java/org/springframework/util/FilteredIterator.java index 96c9c18ffc..ab2c59a592 100644 --- a/spring-core/src/main/java/org/springframework/util/FilteredIterator.java +++ b/spring-core/src/main/java/org/springframework/util/FilteredIterator.java @@ -23,8 +23,9 @@ import java.util.function.Predicate; import org.springframework.lang.Nullable; /** - * Iterator that filters out values that do not match a predicate. - * This type is used by {@link CompositeMap}. + * {@link Iterator} that filters out values that do not match a predicate. + * + *

This type is used by {@link CompositeMap}. * * @author Arjen Poutsma * @since 6.2 @@ -39,7 +40,7 @@ final class FilteredIterator implements Iterator { @Nullable private E next; - private boolean nextSet; + private boolean hasNext; public FilteredIterator(Iterator delegate, Predicate filter) { @@ -52,18 +53,15 @@ final class FilteredIterator implements Iterator { @Override public boolean hasNext() { - if (this.nextSet) { - return true; - } - return setNext(); + return (this.hasNext || setNext()); } @Override public E next() { - if (!this.nextSet && !setNext()) { - throw new NoSuchElementException(); + if (!this.hasNext && !setNext()) { + throw new NoSuchElementException(); } - this.nextSet = false; + this.hasNext = false; Assert.state(this.next != null, "Next should not be null"); return this.next; } @@ -73,7 +71,7 @@ final class FilteredIterator implements Iterator { E next = this.delegate.next(); if (this.filter.test(next)) { this.next = next; - this.nextSet = true; + this.hasNext = true; return true; } }