< prev index next >

src/java.base/share/classes/java/util/regex/Pattern.java

Print this page




5802     }
5803 
5804     /**
5805      *  This must be the very first initializer.
5806      */
5807     static final Node accept = new Node();
5808 
5809     static final Node lastAccept = new LastNode();
5810 
5811     /**
5812      * Creates a predicate which can be used to match a string.
5813      *
5814      * @return  The predicate which can be used for matching on a string
5815      * @since   1.8
5816      */
5817     public Predicate<String> asPredicate() {
5818         return s -> matcher(s).find();
5819     }
5820 
5821     /**




















5822      * Creates a stream from the given input sequence around matches of this
5823      * pattern.
5824      *
5825      * <p> The stream returned by this method contains each substring of the
5826      * input sequence that is terminated by another subsequence that matches
5827      * this pattern or is terminated by the end of the input sequence.  The
5828      * substrings in the stream are in the order in which they occur in the
5829      * input. Trailing empty strings will be discarded and not encountered in
5830      * the stream.
5831      *
5832      * <p> If this pattern does not match any subsequence of the input then
5833      * the resulting stream has just one element, namely the input sequence in
5834      * string form.
5835      *
5836      * <p> When there is a positive-width match at the beginning of the input
5837      * sequence then an empty leading substring is included at the beginning
5838      * of the stream. A zero-width match at the beginning however never produces
5839      * such empty leading substring.
5840      *
5841      * <p> If the input sequence is mutable, it must remain constant during the




5802     }
5803 
5804     /**
5805      *  This must be the very first initializer.
5806      */
5807     static final Node accept = new Node();
5808 
5809     static final Node lastAccept = new LastNode();
5810 
5811     /**
5812      * Creates a predicate which can be used to match a string.
5813      *
5814      * @return  The predicate which can be used for matching on a string
5815      * @since   1.8
5816      */
5817     public Predicate<String> asPredicate() {
5818         return s -> matcher(s).find();
5819     }
5820 
5821     /**
5822      * Creates a predicate that tests if a given input string argument, 
5823      * an input sequence, matches this pattern.
5824      *
5825      * @apiNote
5826      * This method creates a predicate that behaves as if it creates a matcher
5827      * from the input sequence and then calls {@code matches}, for example a
5828      * predicate of the form:
5829      * <pre>{@code
5830      *   s -> matcher(s).matches();
5831      * }</pre>
5832      *
5833      * @return  The predicate which can be used for matching an input string
5834      * against this pattern.
5835      * @since   11
5836      * @see Matcher#matches
5837      */
5838     public Predicate<String> asMatchPredicate() {
5839         return s -> matcher(s).matches();
5840     }
5841     /**
5842      * Creates a stream from the given input sequence around matches of this
5843      * pattern.
5844      *
5845      * <p> The stream returned by this method contains each substring of the
5846      * input sequence that is terminated by another subsequence that matches
5847      * this pattern or is terminated by the end of the input sequence.  The
5848      * substrings in the stream are in the order in which they occur in the
5849      * input. Trailing empty strings will be discarded and not encountered in
5850      * the stream.
5851      *
5852      * <p> If this pattern does not match any subsequence of the input then
5853      * the resulting stream has just one element, namely the input sequence in
5854      * string form.
5855      *
5856      * <p> When there is a positive-width match at the beginning of the input
5857      * sequence then an empty leading substring is included at the beginning
5858      * of the stream. A zero-width match at the beginning however never produces
5859      * such empty leading substring.
5860      *
5861      * <p> If the input sequence is mutable, it must remain constant during the


< prev index next >