Skip to content

Commit

Permalink
Polish contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Nov 17, 2024
1 parent e0e96c4 commit 6544698
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
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
Expand All @@ -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) {
Expand All @@ -52,18 +53,15 @@ public FilteredIterator(Iterator<E> delegate, Predicate<E> filter) {

@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;
}
Expand All @@ -73,7 +71,7 @@ private boolean setNext() {
E next = this.delegate.next();
if (this.filter.test(next)) {
this.next = next;
this.nextSet = true;
this.hasNext = true;
return true;
}
}
Expand Down

0 comments on commit 6544698

Please sign in to comment.