All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.spek.engine.memoized.MemoizedValueImpl.kt Maven / Gradle / Ivy

There is a newer version: 1.1.5
Show newest version
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
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy