This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class Listener<T>(element: T) { | |
var value: T = element | |
protected set(value) { | |
field = value | |
notifyObservers(field) | |
} | |
private val observers: MutableMap<UUID, Observer<T>> = ConcurrentHashMap() | |
private fun notifyObservers(newValue: T) { | |
observers.forEach { it.value.onChange(newValue) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ObservableSyncList<T>(list: MutableList<T> = ArrayList()) : SyncList<T>(list), ListListener { | |
override val observers: MutableMap<UUID, SilentObserver> = ConcurrentHashMap() | |
override fun add(element: T) = super.add(element).also { notifyObservers() } | |
override fun addAll(elements: Collection<T>) = super.addAll(elements).also { notifyObservers() } | |
override fun set(index: Int, element: T): T = super.set(index, element).also { notifyObservers() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun bench(run: () -> Unit) = (0..1_000_000).map { | |
measureTime(run).inMicroseconds | |
}.average() | |
bench { | |
// first code | |
}.toString() + "us" | |
bench { | |
// second code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <T> Closeable.use(block: () -> T): T { | |
var exception: Throwable? = null | |
try { | |
return block() | |
} catch (e: Throwable) { | |
exception = e | |
throw e | |
} finally { | |
when (exception) { | |
null -> close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.logging.log4j.Level; | |
import org.apache.logging.log4j.Marker; | |
import org.apache.logging.log4j.core.Filter; | |
import org.apache.logging.log4j.core.LogEvent; | |
import org.apache.logging.log4j.core.Logger; | |
import org.apache.logging.log4j.core.filter.AbstractFilter; | |
import org.apache.logging.log4j.message.Message; | |
import org.jetbrains.annotations.NotNull; | |
import org.jetbrains.annotations.Nullable; |