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

kotlin.StandardJVM.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1
Show newest version
package kotlin

import java.util.ArrayList
import java.util.LinkedList
import java.util.HashSet
import java.util.LinkedHashSet
import java.util.TreeSet
import java.util.SortedSet
import java.util.Comparator
import java.io.PrintWriter
import java.io.PrintStream
import java.util.concurrent.Callable

/**
 * Add iterated elements to a [[LinkedHashSet]] to preserve insertion order
 */
public fun  Iterator.toLinkedSet() : LinkedHashSet = toCollection(LinkedHashSet())

/**
 * Add iterated elements to [[SortedSet]] with the given *comparator* to ensure iteration is in the order of the given comparator
 */
public fun  Iterator.toSortedSet(comparator: Comparator) : SortedSet = toCollection(TreeSet(comparator))


/**
 * Allows a stack trace to be printed from Kotlin's [[Throwable]]
 */
public fun Throwable.printStackTrace(writer: PrintWriter): Unit {
    val jlt = this as java.lang.Throwable
    jlt.printStackTrace(writer)
}

/**
 * Allows a stack trace to be printed from Kotlin's [[Throwable]]
 */
public fun Throwable.printStackTrace(stream: PrintStream): Unit {
    val jlt = this as java.lang.Throwable
    jlt.printStackTrace(stream)
}

/**
 * Returns the stack trace
 */

public fun Throwable.getStackTrace() : Array {
    val jlt = this as java.lang.Throwable
    return jlt.getStackTrace()!!
}

/**
 * A helper method for creating a [[Callable]] from a function
 */
deprecated("Use SAM constructor: Callable(...)")
public /*inline*/ fun  callable(action: ()-> T): Callable {
    return object: Callable {
        public override fun call() = action()
    }
}

/**
 * A helper method for creating a [[Runnable]] from a function
 */
deprecated("Use SAM constructor: Runnable(...)")
public /*inline*/ fun runnable(action: ()-> Unit): Runnable {
    return object: Runnable {
        public override fun run() {
            action()
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy