-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add isNext(char) and isNext(Predicate<Character>) methods to ImmutableStringReader and StringReader #98
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 theImmutableStringReader
interface andStringReader
class.