aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt
blob: e64c55213d92a64a748109340252e4fb5f8aa854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package at.hannibal2.skyhanni.utils

import kotlin.time.Duration

class TimeLimitedSet<T>(expireAfterWrite: Duration) {

    private val cache = TimeLimitedCache<T, Unit>(expireAfterWrite)

    fun add(element: T) = cache.put(element, Unit)

    fun contains(element: T): Boolean = cache.containsKey(element)

    fun clear() = cache.clear()

    fun toSet(): Set<T> = cache.keys().toSet()
}