Added include function in Conditions in UtilsFactory

This commit is contained in:
2022-09-10 21:34:59 +08:00
parent 58d981d5f2
commit ebe71eb21a

View File

@@ -139,15 +139,26 @@ internal inline fun <T> T.conditions(initiate: Conditions<T>.() -> Unit) = Condi
*/
internal class Conditions<T>(internal var value: T) {
/** 全部判断条件数组 */
private val conditions = ArrayList<Boolean>()
/** 全部判断条件数组 (与) */
private val popularConditions = ArrayList<Boolean>()
/** 全部判断条件数组 (与成立 - 非忽略) */
private val includeConditions = ArrayList<Boolean>()
/**
* 添加与 (and) 条件
* @param value 条件值
*/
internal fun and(value: Boolean) {
conditions.add(value)
popularConditions.add(value)
}
/**
* 添加与 (and) 后成立且不与 (and) 后忽略条件
* @param value 条件值
*/
internal fun include(value: Boolean) {
includeConditions.add(value)
}
/**
@@ -165,7 +176,10 @@ internal class Conditions<T>(internal var value: T) {
* 获取条件判断结果
* @return [Boolean]
*/
private val result by lazy { conditions.takeIf { it.isNotEmpty() }?.any { it.not() }?.not() == true }
private val result by lazy {
includeConditions.takeIf { it.isNotEmpty() }?.any { it.not() }?.not() == true ||
popularConditions.takeIf { it.isNotEmpty() }?.any { it.not() }?.not() == true
}
/**
* 当条件成立