Add isNext(char) and isNext(Predicate<Character>) methods to ImmutableStringReader and StringReader#98
Add isNext(char) and isNext(Predicate<Character>) methods to ImmutableStringReader and StringReader#98ErrorCraft wants to merge 3 commits into
Conversation
|
I feel like |
|
Ah yeah, maybe something like |
|
Changed the method name to |
| @Override | ||
| public boolean isNext(char c) { | ||
| return canRead() && peek() == c; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isNext(Predicate<Character> predicate) { | ||
| return canRead() && predicate.test(peek()); | ||
| } |
There was a problem hiding this comment.
Would it make sense to implement these as default methods of the interface instead?
(Though assuming no or only a few users implement their own ImmutableStringReader it likely makes no difference)
|
|
||
| boolean isNext(char c); | ||
|
|
||
| boolean isNext(Predicate<Character> predicate); |
There was a problem hiding this comment.
What about using IntPredicate here? This would avoid boxing and unboxing. But maybe it does not matter much. And it might cause confusion, making users believe this handles code points (including > Character.MAX_VALUE), so this would require renaming the parameter to for example charPredicate.
|
Closing and reopening to rerun checks. |
I see myself and other people use
reader.canRead() && reader.peek() == c(or!reader.canRead() || reader.peek() != c) all the time. This is very tedious to do, so this adds theisAt(char)method to theImmutableStringReaderinterface andStringReaderclass.