org.jetbrains.spek.engine.memoized.MemoizedValueImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spek-junit-platform-engine Show documentation
Show all versions of spek-junit-platform-engine Show documentation
Spek TestEngine for the JUnit Platform
package org.jetbrains.spek.engine.memoized
import org.jetbrains.spek.api.memoized.CachingMode
import org.jetbrains.spek.api.memoized.MemoizedValue
import kotlin.reflect.KProperty
/**
* @author Ranie Jade Ramiso
*/
open class MemoizedValueImpl(val mode: CachingMode, val factory: () -> T): MemoizedValue {
private var instance: T? = null
fun get(): T {
if (instance == null) {
instance = factory()
}
return instance!!
}
override operator fun getValue(ref: Any?, property: KProperty<*>) = get()
fun reset() {
instance = null
}
}