Last active
December 21, 2016 09:53
-
-
Save VenkataRaju/9313294fab4ddc7592447732c8a0e54d to your computer and use it in GitHub Desktop.
Pattern matchAsStream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test | |
{ | |
private static Stream<String> matchAsStream(CharSequence input, String pattern) | |
{ | |
return StreamSupport.stream(Spliterators.spliterator(new com.google.common.collect.AbstractIterator<String>() | |
{ | |
Matcher matcher = Pattern.compile(pattern).matcher(input); | |
@Override | |
protected String computeNext() | |
{ | |
return matcher.find() ? matcher.group() : endOfData(); | |
} | |
}, 4, Spliterator.ORDERED | Spliterator.NONNULL), false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment