--- old/src/java.base/share/classes/java/util/regex/Pattern.java 2018-04-09 01:56:44.064798201 -0700 +++ new/src/java.base/share/classes/java/util/regex/Pattern.java 2018-04-09 01:56:43.787772694 -0700 @@ -5819,6 +5819,26 @@ } /** + * Creates a predicate that tests if a given input string argument, + * an input sequence, matches this pattern. + * + * @apiNote + * This method creates a predicate that behaves as if it creates a matcher + * from the input sequence and then calls {@code matches}, for example a + * predicate of the form: + *
{@code
+     *   s -> matcher(s).matches();
+     * }
+ * + * @return The predicate which can be used for matching an input string + * against this pattern. + * @since 11 + * @see Matcher#matches + */ + public Predicate asMatchPredicate() { + return s -> matcher(s).matches(); + } + /** * Creates a stream from the given input sequence around matches of this * pattern. * --- old/test/jdk/java/util/regex/RegExTest.java 2018-04-09 01:56:44.787864776 -0700 +++ new/test/jdk/java/util/regex/RegExTest.java 2018-04-09 01:56:44.480836507 -0700 @@ -35,7 +35,7 @@ * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819 * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895 * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706 - * 8194667 8197462 + * 8194667 8197462 8184692 * * @library /test/lib * @build jdk.test.lib.RandomFactory @@ -164,6 +164,7 @@ groupCurlyNotFoundSuppTest(); groupCurlyBackoffTest(); patternAsPredicate(); + patternAsMatchPredicate(); invalidFlags(); embeddedFlags(); grapheme(); @@ -4686,6 +4687,26 @@ report("Pattern.asPredicate"); } + // This test is for 8184692 + private static void patternAsMatchPredicate() throws Exception { + Predicate p = Pattern.compile("[a-z]+").asMatchPredicate(); + + if (p.test("")) { + failCount++; + } + if (!p.test("word")) { + failCount++; + } + if (p.test("1234word")) { + failCount++; + } + if (p.test("1234")) { + failCount++; + } + report("Pattern.asMatchPredicate"); + } + + // This test is for 8035975 private static void invalidFlags() throws Exception { for (int flag = 1; flag != 0; flag <<= 1) {