KStarbound/src/main/kotlin/ru/dbotthepony/kstarbound/Ext.kt

28 lines
837 B
Kotlin

package ru.dbotthepony.kstarbound
import com.google.common.collect.ImmutableMap
import com.google.gson.GsonBuilder
import com.google.gson.TypeAdapter
import java.util.Arrays
import java.util.stream.Stream
import kotlin.reflect.KProperty
inline fun <reified T> GsonBuilder.registerTypeAdapter(adapter: TypeAdapter<T>): GsonBuilder {
return registerTypeAdapter(T::class.java, adapter)
}
fun <T> Array<T>.stream(): Stream<T> = Arrays.stream(this)
operator fun <T> ThreadLocal<T>.getValue(thisRef: Any, property: KProperty<*>): T? {
return get()
}
operator fun <T> ThreadLocal<T>.setValue(thisRef: Any, property: KProperty<*>, value: T?) {
set(value)
}
operator fun <K, V> ImmutableMap.Builder<K, V>.set(key: K, value: V): ImmutableMap.Builder<K, V> = put(key, value)
fun String.sintern(): String = Starbound.strings.intern(this)