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

kotlin.script.experimental.jvm.util.SnippetsHistory.kt Maven / Gradle / Ivy

There is a newer version: 2.0.20-Beta2
Show newest version
/*
 * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package kotlin.script.experimental.jvm.util

import java.io.Serializable
import java.util.*


typealias CompiledHistoryItem = Pair
typealias CompiledHistoryStorage = ArrayList>
typealias CompiledHistoryList = List>

/*
   WARNING: Not thread safe, the caller is assumed to lock access.
 */
open class SnippetsHistory(startingHistory: CompiledHistoryList = emptyList()) : Serializable {
    protected val history: CompiledHistoryStorage = ArrayList(startingHistory)

    fun add(line: CompiledT, value: ResultT) {
        history.add(line to value)
    }

    fun lastItem(): CompiledHistoryItem? = history.lastOrNull()
    fun lastValue(): ResultT? = lastItem()?.second

    val items: List> = history

    fun isEmpty(): Boolean = history.isEmpty()
    fun isNotEmpty(): Boolean = history.isNotEmpty()

    companion object {
        private const val serialVersionUID: Long = 8328353001L
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy