38 lines
767 B
Kotlin
38 lines
767 B
Kotlin
package nl.voidcorp.alarmclock
|
|
|
|
import com.google.gson.GsonBuilder
|
|
import java.io.File
|
|
import java.text.SimpleDateFormat
|
|
import java.util.*
|
|
|
|
/**
|
|
* @author J0QUE
|
|
* @version 1.0
|
|
*
|
|
*/
|
|
val gson = GsonBuilder().setPrettyPrinting().create()
|
|
|
|
fun Any.toJson(): String = gson.toJson(this)
|
|
|
|
fun String.toFile(): File = File(this)
|
|
|
|
val String.uri: String
|
|
get() = this.toFile().toURI().toString()
|
|
|
|
val sdf = SimpleDateFormat("HH:mm:ss")
|
|
|
|
|
|
fun getTime(): Time = Time(sdf.format(Date()))
|
|
|
|
val random = Random()
|
|
|
|
fun <K, V> MutableMap<K, V>.getRandom(): MutableMap.MutableEntry<K, V> {
|
|
val i = random.nextInt(this.size)
|
|
return this.entries.elementAt(i)
|
|
}
|
|
|
|
fun <E> MutableList<E>.getRandom(): E {
|
|
val i = random.nextInt(this.size)
|
|
return this.elementAt(i)
|
|
}
|