8164781: Pattern.asPredicate specification is incomplete
Summary: Updated specification to reflect usage of find()
Reviewed-by: psandoz
--- a/src/java.base/share/classes/java/util/regex/Pattern.java Mon Apr 09 19:23:01 2018 +0200
+++ b/src/java.base/share/classes/java/util/regex/Pattern.java Mon Apr 09 10:39:29 2018 -0700
@@ -5809,10 +5809,21 @@
static final Node lastAccept = new LastNode();
/**
- * Creates a predicate which can be used to match a string.
+ * Creates a predicate that tests if this pattern is found in a given input
+ * string.
*
- * @return The predicate which can be used for matching on a string
+ * @apiNote
+ * This method creates a predicate that behaves as if it creates a matcher
+ * from the input sequence and then calls {@code find}, for example a
+ * predicate of the form:
+ * <pre>{@code
+ * s -> matcher(s).find();
+ * }</pre>
+ *
+ * @return The predicate which can be used for finding a match on a
+ * subsequence of a string
* @since 1.8
+ * @see Matcher#find
*/
public Predicate<String> asPredicate() {
return s -> matcher(s).find();
--- a/test/jdk/java/util/regex/RegExTest.java Mon Apr 09 19:23:01 2018 +0200
+++ b/test/jdk/java/util/regex/RegExTest.java Mon Apr 09 10:39:29 2018 -0700
@@ -4683,6 +4683,9 @@
if (p.test("1234")) {
failCount++;
}
+ if (!p.test("word1234")) {
+ failCount++;
+ }
report("Pattern.asPredicate");
}