All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.allbs.hj212.core.ReaderMatch Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package cn.allbs.hj212.core;

import cn.allbs.hj212.lambda.RunnableWithThrowable;
import cn.allbs.hj212.lambda.SupplierWithThrowable;

import java.io.IOException;
import java.util.Optional;

/**
 * 功能: 字符读取匹配
 *
 * @author chenQi
 */
public interface ReaderMatch {


    /**
     * 字符读取流
     *
     * @return ParentStream
     */
    ParentStream done();

    /**
     * 匹配
     *
     * @return 匹配到
     * @throws IOException
     */
    Optional match() throws IOException;


    static SupplierWithThrowable, IOException> alwaysReturnPresent() {
        return () -> Optional.of(true);
    }

    static SupplierWithThrowable, IOException> alwaysReturnNotPresent() {
        return Optional::empty;
    }

    static SupplierWithThrowable, IOException> alwaysReturnPresentRunable(RunnableWithThrowable runnable) {
        return () -> {
            runnable.run();
            return Optional.of(true);
        };
    }

    static SupplierWithThrowable, IOException> alwaysReturnNotPresentRunable(RunnableWithThrowable runnable) {
        return () -> {
            runnable.run();
            return Optional.empty();
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy