aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/moe/yuuta/workmode/async/StoppableGroup.kt
blob: ef651fe8bb8b68af326978edbfc5372104215386 (plain)
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
package moe.yuuta.workmode.async

class StoppableGroup : Stoppable {
    private val innerList: MutableList<Stoppable> = mutableListOf()

    fun add(stoppable: Stoppable): StoppableGroup {
        innerList.add(stoppable)
        return this
    }

    fun remove(stoppable: Stoppable): StoppableGroup {
        innerList.remove(stoppable)
        return this
    }

    override fun stop() {
        innerList.stream().forEach {
            it.stop()
        }
    }

    override fun isStopped(): Boolean {
        for (stoppable in innerList) {
            if (!stoppable.isStopped()) return false
        }
        return true
    }
}