Regex Point Lambdafication Patch
Paul Sandoz
paul.sandoz at oracle.com
Mon Mar 11 13:38:53 PDT 2013
Hi Ben,
This is unrelated to your off-by-one error... but the Spliterator characteristics is one less that it could be :-) it can be:
Spliterator.NONNULL | Spliterator.ORDERED
Paul.
On Mar 11, 2013, at 6:49 PM, Ben Evans <benjamin.john.evans at gmail.com> wrote:
> I've tried this:
>
> private static class MatcherIterator implements Iterator<CharSequence> {
> private final Matcher curMatcher;
> private final CharSequence input;
> private int current = 0;
>
> MatcherIterator(CharSequence in, Matcher m) {
> input = in;
> curMatcher = m;
> }
>
> public CharSequence next() {
> CharSequence nextChunk = input.subSequence(current, curMatcher.start());
> current = curMatcher.end();
> return nextChunk;
> }
>
> public boolean hasNext() {
> return curMatcher.find();
> }
> }
>
> public Stream<CharSequence> splitAsStream(final CharSequence input) {
> return Streams.stream(Spliterators.spliteratorUnknownSize(new
> MatcherIterator(input, matcher(input)), Spliterator.ORDERED));
> }
>
> But it seems to lead to an off-by-one error in my tests - and I'm not
> sure why (maybe just inexperience with the Spliterators methods).
>
> Any ideas?
>
> Thanks,
>
> Ben
More information about the lambda-dev
mailing list