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

main.io.github.chengzis.chain.Chain.kt Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
package io.github.chengzis.chain

/**
 * 责任链
 * @param interceptors 拦截器列表
 * @param T 方法参数
 * @param R 方法返回值
 */
class Chain(private val interceptors: List>) {

    fun process(args: T): R {
        if (interceptors.isEmpty()) {
            throw RuntimeException("最后一个拦截器必须返回值,而不是调用chain.process(args)")
        }
        val chain = Chain(interceptors.subList(1, interceptors.size))
        return interceptors.first().process(chain, args)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy