Package avail.utility

Types

Link copied to clipboard
class Graph<Vertex>

A Graph is an unordered collection of vertices, along with the successor-predecessor relationships between them. From the Graph's viewpoint, the vertices are merely mementos that support equals and hashCode. Edges are not explicitly represented, but instead are a consequence of how the outEdges and inEdges are populated.

Link copied to clipboard
object IO

IO is a utility class for input/output operations.

Link copied to clipboard
class Multigraph<V, E : Multigraph.Edge<V>>(original: Multigraph<V, E>)

This is an implementation of a directed multigraph. A graph consists of a collection of vertices connected by (directed) edges. A vertex v1 may be connected to another vertex v2 by more than one edge, which makes this a multigraph implementation. However, note that v1 and v2 can not be multiply connected by the same edge (i.e., two edges connecting v1 and v2 must not be equal to each other).

Link copied to clipboard
class Mutable<T>(var value: T)

Support explicit mutable wrapping of variables. This is used specifically for allowing non-final variables to be used by inner classes. The uses were generated automatically by the Smalltalk → Java translator after flow analysis.

Link copied to clipboard
class NullOutputStream : OutputStream

A NullOutputStream discards everything written to it.

Link copied to clipboard
class ObjectTracer(val start: Any, val target: Any)

A utility for determining the shortest path through fields from a starting object to a target object. The search is performed breadth-first to ensure the shortest path is found.

Link copied to clipboard
class ParagraphFormatter @JvmOverloads constructor(    val windowWidth: Int = 80,     val leftMargin: Int = 0,     val rightMargin: Int = 0,     val firstIndent: Int = 0,     val restIndent: Int = 0)

A ParagraphFormatter object holds a particular paragraph style in the form of window width, margin, and indentation settings. It is then used to apply those whitespace and word-wrap settings to a String.

Link copied to clipboard
class ParagraphFormatterStream(formatter: ParagraphFormatter, appendable: Appendable) : Appendable

ParagraphFormatterStream wraps an Appendable with a ParagraphFormatter, so that Strings can automatically be formatted by the ParagraphFormatter before being appended to the output stream.

Link copied to clipboard
class PrefixSharingList<E> : AbstractList<E>

This is an implementation of an immutable List for which append, the non-destructive append operation, takes constant time. There is also a withoutLast operation for producing a list with its rightmost element removed. Iterating over the entire list takes linear time, and does not use recursion.

Link copied to clipboard
class PrefixTree<K, V>(mapFactory: () -> MutableMap<K, PrefixTree<K, V>> = { mutableMapOf() })

A prefix tree, with amortized O(1) access time, amortized O(1) insertion time O(1), amortized O(1) removal time, and O(n) prune time. Thread-safe iff the internal transition tables, supplied by the factory, are thread-safe.

Link copied to clipboard
open class PublicCloneable<X : PublicCloneable<X>> : Cloneable

Subclasses get a public clone method without a silly catch of an impossible exception.

Link copied to clipboard
class SimpleThreadFactory(prefix: String) : ThreadFactory

A ThreadFactory that creates Threads named with a prefix, a dash, and a practically unique counter.

Link copied to clipboard
object Strings

Strings provides various string utilities.

Link copied to clipboard
data class Tuple1<T1>(val t1: T1)

Tuple of length 1.

Link copied to clipboard
data class Tuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(    val t1: T1,     val t2: T2,     val t3: T3,     val t4: T4,     val t5: T5,     val t6: T6,     val t7: T7,     val t8: T8,     val t9: T9,     val t10: T10)

Tuple of length 10.

Link copied to clipboard
typealias Tuple2<T1, T2> = Pair<T1, T2>

Tuple of length 2.

Link copied to clipboard
typealias Tuple3<T1, T2, T3> = Triple<T1, T2, T3>

Tuple of length 3.

Link copied to clipboard
data class Tuple4<T1, T2, T3, T4>(    val t1: T1,     val t2: T2,     val t3: T3,     val t4: T4)

Tuple of length 4.

Link copied to clipboard
data class Tuple5<T1, T2, T3, T4, T5>(    val t1: T1,     val t2: T2,     val t3: T3,     val t4: T4,     val t5: T5)

Tuple of length 5.

Link copied to clipboard
data class Tuple6<T1, T2, T3, T4, T5, T6>(    val t1: T1,     val t2: T2,     val t3: T3,     val t4: T4,     val t5: T5,     val t6: T6)

Tuple of length 6.

Link copied to clipboard
data class Tuple7<T1, T2, T3, T4, T5, T6, T7>(    val t1: T1,     val t2: T2,     val t3: T3,     val t4: T4,     val t5: T5,     val t6: T6,     val t7: T7)

Tuple of length 7.

Link copied to clipboard
data class Tuple8<T1, T2, T3, T4, T5, T6, T7, T8>(    val t1: T1,     val t2: T2,     val t3: T3,     val t4: T4,     val t5: T5,     val t6: T6,     val t7: T7,     val t8: T8)

Tuple of length 8.

Link copied to clipboard
data class Tuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(    val t1: T1,     val t2: T2,     val t3: T3,     val t4: T4,     val t5: T5,     val t6: T6,     val t7: T7,     val t8: T8,     val t9: T9)

Tuple of length 9.

Link copied to clipboard
class UTF8ResourceBundleControl : ResourceBundle.Control

UTF8ResourceBundleControl permits the reading of UTF-8-encoded Java properties files.

Link copied to clipboard
class WorkStealingQueue<E : Comparable<E>>(parallelism: Int) : AbstractQueue<E> , BlockingQueue<E>

A WorkStealingQueue tracks parallelism separate subqueues of tasks. Each Interpreter feeds and consumes a distinct subqueue dedicated to that interpreter thread, ideally without contention from other threads. When a subqueue is exhausted, the requesting thread will examine the other threads' queues and steal one for itself. Only at that point will contention occur.

Functions

Link copied to clipboard
inline fun <I, O : I?> I.cast(): O

When you know better, this bypasses static type-safety, while leaving dynamic type-safety intact, other than generics and nulls.

Link copied to clipboard
fun currentTrace(): String

Produce a String representation of the current stack trace. It throws a Throwable and catches it, which will show up in the trace.

Link copied to clipboard
inline fun <A : Iterable<B>, B, C> A.deepForEach(extractor: B.() -> Iterable<C>, body: (C) -> Unit)

Given an Iterable receiver, run the normal forEach operation to produce a series of values, apply the extractor extension function to each of those values to produce an Iterable for each of them, and run forEach on those Iterables, in order, using the body function.

inline fun <A : Iterable<B>, B, C, D> A.deepForEach(    extractor1: B.() -> Iterable<C>,     extractor2: C.() -> Iterable<D>,     body: (D) -> Unit)

Given an Iterable receiver, run the normal forEach operation to produce a series of values, apply the extractor1 extension function to each of those values to produce an Iterable for each of them, run the extractor2 extension function to produce an Iterable to run forEach on, with the body function.

Link copied to clipboard
inline fun Int.ifZero(minorBody: () -> Int): Int

Having already compared two things to get an Int that represents less-than, equal, or greater-than, answer that if it's not equal (i.e., not 0). Otherwise use the inlined zero-argument block to do further comparisons.

inline fun <C : Comparable<C>> Int.ifZero(minor1: () -> C, minor2: () -> C): Int

Having already compared two things to get an Int that represents less-than, equal, or greater-than, answer that if it's not equal (i.e., not 0). Otherwise evaluate the two lambdas and use (Comparable.compareTo) to produce an Int to use instead.

Link copied to clipboard
inline fun <T> T?.isNullOr(body: T.() -> Boolean): Boolean

If the receiver is null, answer true. Otherwise run the body with the non-null receiver and answer the resulting Boolean.

Link copied to clipboard
fun Any.javaNotify()
Link copied to clipboard
fun Any.javaNotifyAll()
Link copied to clipboard
fun Any.javaWait()
fun Any.javaWait(timeout: Long)
fun Any.javaWait(timeout: Long, nanos: Int)
Link copied to clipboard
inline fun loopUntil(lambda: () -> Boolean)

Execute the given lambda repeatedly until it returns true.

Link copied to clipboard
inline fun loopWhile(lambda: () -> Boolean)

Execute the given lambda repeatedly until it returns false.

Link copied to clipboard
inline fun <T, R> Iterable<T>.mapToSet(destination: MutableSet<R> = mutableSetOf(), transform: (T) -> R): MutableSet<R>

Transform the receiver via the supplied function and collect the results into an optionally provided set. Answer the result set.

Link copied to clipboard
inline fun <T> T?.notNullAnd(body: T.() -> Boolean): Boolean

If the receiver is null, answer false. Otherwise run the body with the non-null receiver and answer the resulting Boolean.

Link copied to clipboard
fun <E> Collection<E>.parallelDoThen(action: (E, () -> Unit) -> Unit, then: () -> Unit)

For each element in the collection, execute the action, passing a zero-argument function to run exactly once afterward (in this Thread or another). When the last element's zero-argument function has been invoked, or immediately if the collection is empty, invoke then.

Link copied to clipboard
inline fun <S, T> Collection<S>.parallelMapThen(crossinline action: (S, (T) -> Unit) -> Unit, crossinline then: (List<T>) -> Unit)

For each element in the collection, execute the action, passing a zero-argument function to run exactly once afterward (in this Thread or another). When the last element's zero-argument function has been invoked, or immediately if the collection is empty, invoke then.

Link copied to clipboard
fun <E, R> List<E>.partitionedMap(    partitions: Int,     body: (List<E>, (List<R>) -> Unit) -> Unit,     after: (List<R>) -> Unit)

Partition the receiver into partitions approximately equal sublists. Some may be empty if count is larger than the receiver's size. Invoke the supplied body for each sublist. The body must eventually, perhaps in another Thread, invoke a function passed to it, to indicate completion, and to provide a list containing the element-wise transformation of the original sublist. These transformed sublists are then concatenated to form a new list, which is passed to the after function, perhaps in another Thread.

Link copied to clipboard
fun <E, K> List<E>.partitionRunsBy(groupingKey: (E) -> K): List<List<E>>

Given a list and a key-extraction function, produce a list of non-empty lists of elements that have the same key. Note that it only looks for runs of a key, and treats reoccurrences of some key after a gap to be a new key.

Link copied to clipboard
fun <E> MutableList<E>.removeLast(): E

Kotlin has one of these in experimental, which forces the Universe to say it's also experimental. So boo.

Link copied to clipboard
inline fun <T> ReentrantReadWriteLock.safeWrite(lambda: () -> T): T

Execute the given lambda while holding the supplied ReentrantReadWriteLock's write lock. This is the correct alternative to the brokenwrite supplied by the Kotlin library, which non-atomically attempts to upgrade a read lock into a write lock by first dropping all extant holds of the read lock (!).

Link copied to clipboard
fun <T1> t(t1: T1): Tuple1<T1>

Construct a tuple of length 1.

fun <T1, T2> t(t1: T1, t2: T2): Pair<T1, T2>

Construct a tuple of length 2.

fun <T1, T2, T3> t(    t1: T1,     t2: T2,     t3: T3): Triple<T1, T2, T3>

Construct a tuple of length 3.

fun <T1, T2, T3, T4> t(    t1: T1,     t2: T2,     t3: T3,     t4: T4): Tuple4<T1, T2, T3, T4>

Construct a tuple of length 4.

fun <T1, T2, T3, T4, T5> t(    t1: T1,     t2: T2,     t3: T3,     t4: T4,     t5: T5): Tuple5<T1, T2, T3, T4, T5>

Construct a tuple of length 5.

fun <T1, T2, T3, T4, T5, T6> t(    t1: T1,     t2: T2,     t3: T3,     t4: T4,     t5: T5,     t6: T6): Tuple6<T1, T2, T3, T4, T5, T6>

Construct a tuple of length 6.

fun <T1, T2, T3, T4, T5, T6, T7> t(    t1: T1,     t2: T2,     t3: T3,     t4: T4,     t5: T5,     t6: T6,     t7: T7): Tuple7<T1, T2, T3, T4, T5, T6, T7>

Construct a tuple of length 7.

fun <T1, T2, T3, T4, T5, T6, T7, T8> t(    t1: T1,     t2: T2,     t3: T3,     t4: T4,     t5: T5,     t6: T6,     t7: T7,     t8: T8): Tuple8<T1, T2, T3, T4, T5, T6, T7, T8>

Construct a tuple of length 8.

fun <T1, T2, T3, T4, T5, T6, T7, T8, T9> t(    t1: T1,     t2: T2,     t3: T3,     t4: T4,     t5: T5,     t6: T6,     t7: T7,     t8: T8,     t9: T9): Tuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9>

Construct a tuple of length 9.

fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> t(    t1: T1,     t2: T2,     t3: T3,     t4: T4,     t5: T5,     t6: T6,     t7: T7,     t8: T8,     t9: T9,     t10: T10): Tuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>

Construct a tuple of length 10.

Link copied to clipboard
inline fun <K : Enum<K>, V : Any> Array<K>.toEnumMap(generator: (K) -> V): EnumMap<K, V>

Project the receiver onto an {@link EnumMap}, applying the function to each enum value of the array.

Link copied to clipboard
fun trace(t: Throwable): String

Produce a String representation of the stack trace captured in the given Throwable.