// Copyright 2016 takahashikzn
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jp.root42.indolently;

import java.util.function.Predicate;
import java.util.regex.Pattern;


/**
 * Enhanced {@link Pattern} object
 *
 * @author takahashikzn.
 */
public interface SPtrn
    extends Predicate<CharSequence> {

    /**
     * Get {@link Pattern} instance which this object contains.
     *
     * @return {@link Pattern} instance which this object contains
     */
    Pattern ptrn();

    /**
     * An shortcut of {@code ptrn.pattern().pattern()}.
     *
     * @return regex string
     * @see Pattern#pattern()
     */
    default String pattern() {
        return this.ptrn().pattern();
    }

    @Override
    default boolean test(final CharSequence cs) {
        return this.matcher(cs).matches();
    }

    /**
     * Create a {@link SMatcher} instance.
     *
     * @param cs the string to match
     * @return created {@link SMatcher} instance
     */
    default SMatcher matcher(final CharSequence cs) {
        return new SMatcherImpl(this.ptrn().matcher(cs), cs);
    }

    /**
     * Tokenize string by the regex pattern which this object expresses.
     * This method is equivalent to {@code ptrn.split(cs, 0)}.
     *
     * @param cs the string to tokenize
     * @return token list
     */
    default SList<String> split(final CharSequence cs) {
        return this.split(cs, 0);
    }

    /**
     * Tokenize string by the regex pattern which this object expresses.
     *
     * @param cs the string to tokenize
     * @param limit The result threshold
     * @return token list
     * @see Pattern#split(CharSequence, int)
     */
    default SList<String> split(final CharSequence cs, final int limit) {
        return Indolently.list(this.ptrn().split(cs, limit));
    }
}

@@ -609,16 +609,90 @@
 ently;%0A%0A
+import java.util.function.BiFunction;%0Aimport java.util.function.Function;%0A
 import j
@@ -2376,11 +2376,1415 @@
 );%0A    %7D
+%0A%0A    /**%0A     * delegate for %7B@link Matcher#replaceAll(String)%7D%0A     *%0A     * @param cs the string to replace%0A     * @param replacement replacement string%0A     * @return replaced string%0A     */%0A    default String replaceAll(final CharSequence cs, final String replacement) %7B%0A        return this.matcher(cs).replaceAll(replacement);%0A    %7D%0A%0A    /**%0A     * delegate for %7B@link Matcher#replaceFirst(String)%7D%0A     *%0A     * @param cs the string to replace%0A     * @param replacement replacement string%0A     * @return replaced string%0A     */%0A    default String replaceFirst(final CharSequence cs, final String replacement) %7B%0A        return this.matcher(cs).replaceFirst(replacement);%0A    %7D%0A%0A    /**%0A     * delegate for %7B@link SMatcher#replace(Function)%7D%0A     *%0A     * @param cs the string to replace%0A     * @param f replace operator%0A     * @return replaced string%0A     * @see #replaceAll(String)%0A     */%0A    default String replace(final CharSequence cs, final Function%3CString, String%3E f) %7B%0A        return this.matcher(cs).replace(f);%0A    %7D%0A%0A    /**%0A     * delegate for %7B@link SMatcher#replace(BiFunction)%7D%0A     *%0A     * @param cs the string to replace%0A     * @param f replace operator%0A     * @return replaced string%0A     * @see #replaceAll(String)%0A     */%0A    default String replace(final CharSequence cs, final BiFunction%3C? super SMatcher, String, String%3E f) %7B%0A        return this.matcher(cs).replace(f);%0A    %7D
 %0A%7D%0A

add shortcut methods