feiyu02
2024-06-27 e8f935a01d75c89ac591a80b9318eac2480e2dcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.flightfeather.uav.biz
 
import com.flightfeather.uav.socket.eunm.FactorType
 
/**
 * 所选主要分析因子,以及关联因子
 * 在做数据异常分析以及数据统计时,用于决定是否需要进行处理该因子。
 * @date 2024/6/27
 * @author feiyu02
 */
class FactorFilter private constructor(){
 
    data class SelectedFactor(
        val main:FactorType,
        var subs:List<FactorType> = emptyList()
    )
 
    inner class Builder{
        fun withMain(factorType: FactorType): Builder {
            selectedList.add(SelectedFactor(factorType))
            return this
        }
 
        fun withSubs(subs: List<FactorType>): Builder {
            if (selectedList.isNotEmpty()) {
                selectedList.last().subs = subs
            }
            return this
        }
 
        fun create(): FactorFilter {
            return this@FactorFilter
        }
    }
 
    companion object{
        fun builder() = FactorFilter().Builder()
        fun default() = builder().create()
    }
 
    // 所选因子集合
    val selectedList = mutableListOf<SelectedFactor>()
 
    fun mainList(): List<FactorType> {
        return selectedList.map { it.main }
    }
}