Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix WordCounterSpliterator.tryAdvance
fixes:
1. when initial string is empty, prevents throwing StringIndexOutOfBoundsException
2. the last valid iteration return true. old code returns false for the last character which breaks tryAdvance() specs
  • Loading branch information
uprem authored Sep 10, 2016
commit 931f17e3435207ea97336bd230ac92f160a6073e
8 changes: 6 additions & 2 deletions src/main/java/lambdasinaction/chap7/WordCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ private WordCounterSpliterator(String string) {

@Override
public boolean tryAdvance(Consumer<? super Character> action) {
action.accept(string.charAt(currentChar++));
return currentChar < string.length();
if(currentChar < string.length()) {
action.accept(string.charAt(currentChar++));
return true;
} else {
return false;
}
}

@Override
Expand Down