Skip to content

Commit

Permalink
fix for empty word
Browse files Browse the repository at this point in the history
  • Loading branch information
walaniam committed Jan 3, 2022
1 parent 6e4f37d commit 85dafde
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main/java/walaniam/scrabble/dictionary/set/WordsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,30 @@ public void read(Consumer<String> consumer) throws IOException {
if (!Character.isWhitespace(c)) {
wordBuffer.append(c);
} else {
consumer.accept(READ_BUFFER.apply(wordBuffer));
wordsLoaded++;
if (consume(consumer, wordBuffer)) {
wordsLoaded++;
}
}
}
}

consumer.accept(READ_BUFFER.apply(wordBuffer));
wordsLoaded++;
if (consume(consumer, wordBuffer)) {
wordsLoaded++;
}
}

log.debug("{} words loaded in {} ms", wordsLoaded, System.currentTimeMillis() - start);
}

private boolean consume(Consumer<String> consumer, StringBuilder buffer) {
String word = READ_BUFFER.apply(buffer);
if (word != null && word.length() > 0) {
consumer.accept(word);
return true;
}
return false;
}

private Reader readWithEncoding(InputStream input) throws IOException {

BufferedInputStream bis = new BufferedInputStream(input);
Expand Down

0 comments on commit 85dafde

Please sign in to comment.