RFR 8071479: Stream and lamdification improvements to j.u.regex.Matcher

Paul Sandoz paul.sandoz at oracle.com
Thu Feb 5 10:59:12 UTC 2015


Hi.

Please review these stream/lambda enhancements on Matcher:

  http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8071479--Matcher-stream-results/webrev/

Two new methods are added to Matcher:

1) replaceAll(Function<MatchResult, String> ) that is more flexible than the existing replaceAll that accepts a single value.

2) Stream<MatchResult> results() that returns a stream of MatchResult for all matches.

The former does introduce a minor source incompatibility for a null argument, but then so did the new append methods accepting StringBuilder that were recently added (see JDK-8039124).
 
For the latter i opted to place the method on Matcher rather than Pattern as i think that is a better fit with current usages of Matcher and operating on a MatchResult. That marginally increases the complexity since co-modification checking is required.

I update the test PatternStreamTest to derive the expected result.


I suppose i could add another method replaceFirst(Function<MatchResult, String> ) if anyone feels strongly about that. Consistency-wise it seems the right thing to do.

Paul.



More information about the core-libs-dev mailing list