Polish contribution

See gh-33902
This commit is contained in:
Sam Brannen
2024-11-17 11:45:37 +01:00
parent e0e96c487f
commit 6544698078
2 changed files with 12 additions and 12 deletions

View File

@@ -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.
*
* <p>This type is created via
* {@link CollectionUtils#compositeMap(Map, Map, BiFunction, Consumer)}.
*
* @author Arjen Poutsma

View File

@@ -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.
*
* <p>This type is used by {@link CompositeMap}.
*
* @author Arjen Poutsma
* @since 6.2
@@ -39,7 +40,7 @@ final class FilteredIterator<E> implements Iterator<E> {
@Nullable
private E next;
private boolean nextSet;
private boolean hasNext;
public FilteredIterator(Iterator<E> delegate, Predicate<E> filter) {
@@ -52,18 +53,15 @@ final class FilteredIterator<E> implements Iterator<E> {
@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<E> implements Iterator<E> {
E next = this.delegate.next();
if (this.filter.test(next)) {
this.next = next;
this.nextSet = true;
this.hasNext = true;
return true;
}
}