|
|||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||||
See:
Description
| Classes Summary | |
|---|---|
| ComparableRange | |
| ImmutableArrayListBuilder | |
| Pair | |
| Triple | |
| Property Summary | |
|---|---|
val |
|
| Function Summary | ||
|---|---|---|
fun |
String(stringBuffer: StringBuffer): String
|
|
fun |
String(stringBuilder: StringBuilder): String
|
|
fun |
String(bytes: ByteArray): String
|
|
fun |
String(bytes: ByteArray, charset: Charset): String
|
|
fun |
String(bytes: ByteArray, i: Int, i1: Int): String
|
|
fun |
String(bytes: ByteArray, offset: Int, length: Int, charset: Charset): String
|
|
fun |
String(bytes: ByteArray, offset: Int, length: Int, charsetName: String): String
|
|
fun |
String(bytes: ByteArray, charsetName: String): String
|
|
fun |
String(chars: CharArray): String
|
|
|
annotationType(): Class<T>
|
|
|
array(vararg t: T): Array<T>
|
|
|
arrayList(vararg values: T): ArrayList<T>
|
|
|
arrayListOf(vararg values: T): ArrayList<T>
Returns a new ArrayList with a variable number of initial elements |
|
fun |
assert(value: Boolean, [message: Any]): Unit
Throws an AssertionError with an optional message if the value is false and runtime assertions have been enabled on the JVM using the -ea JVM option. |
|
fun |
assert(value: Boolean, lazyMessage: () -> String): Unit
Throws an AssertionError with the specified lazyMessage if the value is false and runtime assertions have been enabled on the JVM using the -ea JVM option. |
|
fun |
booleanArray(vararg content: Boolean): BooleanArray
|
|
fun |
byteArray(vararg content: Byte): ByteArray
|
|
|
callable(action: () -> T): Callable<T>
A helper method for creating a Callable from a function |
|
fun |
charArray(vararg content: Char): CharArray
|
|
fun |
check(value: Boolean, [message: Any]): Unit
Throws an IllegalStateException with an optional message if the value is false. |
|
fun |
check(value: Boolean, lazyMessage: () -> String): Unit
Throws an IllegalStateException with the lazyMessage if the value is false. |
|
|
checkNotNull(value: T?, [message: String]): T
Throws an IllegalStateException with the given message if the value is null otherwise the not null value is returned. |
|
fun |
checkStepIsPositive(isPositive: Boolean, step: Number): Unit
|
|
|
comparator(vararg functions: (T) -> Any): Comparator<T>
Creates a comparator using the sequence of functions used to calculate a value to compare on |
|
|
comparator(fn: (T, T) -> Int): Comparator<T>
Creates a comparator using the sequence of functions used to calculate a value to compare on |
|
|
compareBy(a: T?, b: T?, vararg functions: (T) -> Any): Int
Helper method for implementing Comparable methods using a list of functions to calculate the values to compare |
|
|
compareValues(a: T?, b: T?): Int
Compares the two values which may be Comparable otherwise they are compared via #equals() and if they are not the same then the #hashCode() method is used as the difference |
|
|
countTo(n: Int): (T) -> Boolean
|
|
fun |
doubleArray(vararg content: Double): DoubleArray
|
|
fun |
floatArray(vararg content: Float): FloatArray
|
|
|
hashMap(vararg values: Pair<K, V>): HashMap<K, V>
|
|
|
hashMapOf(vararg values: Pair<K, V>): HashMap<K, V>
Returns a new HashMap populated with the given tuple values where the first value in each tuple is the key and the second value is the value |
|
|
hashSet(vararg values: T): HashSet<T>
|
|
|
hashSetOf(vararg values: T): HashSet<T>
Returns a new HashSet with a variable number of initial elements |
|
fun |
intArray(vararg content: Int): IntArray
|
|
|
iterate(nextFunction: () -> T?): Iterator<T>
Returns an iterator which invokes the function to calculate the next value on each iteration until the function returns null |
|
|
javaClass(): Class<T>
|
|
|
linkedList(vararg values: T): LinkedList<T>
|
|
|
linkedListOf(vararg values: T): LinkedList<T>
Returns a new LinkedList with a variable number of initial elements |
|
|
linkedMap(vararg values: Pair<K, V>): LinkedHashMap<K, V>
|
|
|
linkedMapOf(vararg values: Pair<K, V>): LinkedHashMap<K, V>
Returns a new LinkedHashMap populated with the given tuple values where the first value in each tuple is the key and the second value is the value. This map preserves insertion order so iterating through the map’s entries will be in the same order |
|
|
listBuilder(): ImmutableArrayListBuilder<T>
|
|
|
listOf(vararg values: T): List<T>
Returns a new read-only list of given elements |
|
fun |
longArray(vararg content: Long): LongArray
|
|
|
mapOf(vararg values: Pair<K, V>): Map<K, V>
Returns a new read-only map of given pairs, where the first value is the key, and the second is value |
|
|
rangeTo(that: T): ComparableRange<T>
|
|
fun |
require(value: Boolean, [message: Any]): Unit
Throws an IllegalArgumentException with an optional message if the value is false. |
|
fun |
require(value: Boolean, lazyMessage: () -> String): Unit
Throws an IllegalArgumentException with the lazyMessage if the value is false. |
|
|
requireNotNull(value: T?, [message: Any]): T
Throws an IllegalArgumentException with the given message if the value is null otherwise the not null value is returned. |
|
|
run(f: () -> T): T
Run function f |
|
fun |
runnable(action: () -> Unit): Runnable
A helper method for creating a Runnable from a function |
|
|
setOf(vararg values: T): Set<T>
Returns a new read-only set of given elements |
|
fun |
shortArray(vararg content: Short): ShortArray
|
|
|
sortedMap(vararg values: Pair<K, V>): SortedMap<K, V>
|
|
|
sortedMapOf(vararg values: Pair<K, V>): SortedMap<K, V>
Returns a new SortedMap populated with the given tuple values where the first value in each tuple is the key and the second value is the value |
|
|
sortedSet(comparator: Comparator<T>, vararg values: T): TreeSet<T>
|
|
|
sortedSet(vararg values: T): TreeSet<T>
|
|
|
sortedSetOf(comparator: Comparator<T>, vararg values: T): TreeSet<T>
Returns a new SortedSet with the given comparator and the initial elements |
|
|
sortedSetOf(vararg values: T): TreeSet<T>
Returns a new SortedSet with the initial elements |
|
|
to(that: B): Pair<A, B>
Creates a tuple of type Pair from this and that which can be useful for creating Map literals with less noise, for example |
|
There are a number of extension functions on Collection, Iterator, Map and arrays to allow easy composition collections using familiar combinators like
Functions on Collection, Map and arrays are all eager, in that methods like map() will create a complete result List when the method completes.
Functions on Iterator are lazy so that they try to return new iterators that lazily evaluate things. For example map() returns a new Iterator that lazily maps the values in the original iterator.
When writing code it is recommended you add checks early in a function to ensure parameters are valid. There are a number of helper methods for this:
| Function Detail |
|---|
fun <T> arrayListOf(vararg values: T): ArrayList<T>
Returns a new ArrayList with a variable number of initial elements
fun assert(value: Boolean, [message: Any]): Unit
Throws an AssertionError with an optional message if the value is false
and runtime assertions have been enabled on the JVM using the -ea JVM option.
fun assert(value: Boolean, lazyMessage: () -> String): Unit
Throws an AssertionError with the specified lazyMessage if the value is false
and runtime assertions have been enabled on the JVM using the -ea JVM option.
fun <T> callable(action: () -> T): Callable<T>
A helper method for creating a Callable from a function
fun check(value: Boolean, [message: Any]): Unit
Throws an IllegalStateException with an optional message if the value is false.
val error = failsWith(javaClass<IllegalStateException>()) {
check(false, "Hello")
}
assertEquals("Hello", error.getMessage())
fun check(value: Boolean, lazyMessage: () -> String): Unit
Throws an IllegalStateException with the lazyMessage if the value is false.
val error = failsWith(javaClass<IllegalStateException>()) {
check(false) {"Hello"}
}
assertEquals("Hello", error.getMessage())
fun <T> checkNotNull(value: T?, [message: String]): T
Throws an IllegalStateException with the given message if the value is null otherwise
the not null value is returned.
val s1: String? = "S1"
val r1: String = checkNotNull(s1)
assertEquals("S1", r1)
fun <T> comparator(vararg functions: (T) -> Any): Comparator<T>
Creates a comparator using the sequence of functions used to calculate a value to compare on
fun <T> comparator(fn: (T, T) -> Int): Comparator<T>
Creates a comparator using the sequence of functions used to calculate a value to compare on
fun <T> compareBy(a: T?, b: T?, vararg functions: (T) -> Any): Int
Helper method for implementing Comparable methods using a list of functions
to calculate the values to compare
fun <T> compareValues(a: T?, b: T?): Int
Compares the two values which may be Comparable otherwise
they are compared via #equals() and if they are not the same then
the #hashCode() method is used as the difference
fun <K, V> hashMapOf(vararg values: Pair<K, V>): HashMap<K, V>
Returns a new HashMap populated with the given tuple values where the first value in each tuple
is the key and the second value is the value
val map = hashMap(Pair("a", 1), Pair("b", 2))
assertEquals(2, map.size)
assertEquals(1, map.get("a"))
assertEquals(2, map.get("b"))
fun <T> hashSetOf(vararg values: T): HashSet<T>
Returns a new HashSet with a variable number of initial elements
fun <T> iterate(nextFunction: () -> T?): Iterator<T>
Returns an iterator which invokes the function to calculate the next value on each iteration until the function returns null
// fibonacci terms
var index = 0; var a = 0; var b = 1
return iterate<Int> { when (index++) { 0 -> a; 1 -> b; else -> { val result = a + b; a = b; b = result; result } } }
fun <T> linkedListOf(vararg values: T): LinkedList<T>
Returns a new LinkedList with a variable number of initial elements
fun <K, V> linkedMapOf(vararg values: Pair<K, V>): LinkedHashMap<K, V>
Returns a new LinkedHashMap populated with the given tuple values where the first value in each tuple
is the key and the second value is the value. This map preserves insertion order so iterating through
the map’s entries will be in the same order
val map = linkedMap(Pair("c", 3), Pair("b", 2), Pair("a", 1))
assertEquals(1, map.get("a"))
assertEquals(2, map.get("b"))
assertEquals(3, map.get("c"))
assertEquals(arrayList("c", "b", "a"), map.keySet().toList())
fun <K, V> mapOf(vararg values: Pair<K, V>): Map<K, V>
Returns a new read-only map of given pairs, where the first value is the key, and the second is value
fun require(value: Boolean, [message: Any]): Unit
Throws an IllegalArgumentException with an optional message if the value is false.
val error = failsWith(javaClass<IllegalArgumentException>()) {
require(false, "Hello")
}
assertEquals("Hello", error.getMessage())
fun require(value: Boolean, lazyMessage: () -> String): Unit
Throws an IllegalArgumentException with the lazyMessage if the value is false.
val error = failsWith(javaClass<IllegalArgumentException>()) {
require(false) {"Hello"}
}
assertEquals("Hello", error.getMessage())
fun <T> requireNotNull(value: T?, [message: Any]): T
Throws an IllegalArgumentException with the given message if the value is null otherwise
the not null value is returned.
val s1: String? = "S1"
val r1: String = requireNotNull(s1)
assertEquals("S1", r1)
fun runnable(action: () -> Unit): Runnable
A helper method for creating a Runnable from a function
fun <K, V> sortedMapOf(vararg values: Pair<K, V>): SortedMap<K, V>
Returns a new SortedMap populated with the given tuple values where the first value in each tuple
is the key and the second value is the value
val map = sortedMap(Pair("c", 3), Pair("b", 2), Pair("a", 1))
assertEquals(1, map.get("a"))
assertEquals(2, map.get("b"))
assertEquals(3, map.get("c"))
assertEquals(arrayList("a", "b", "c"), map.keySet()!!.toList())
fun <T> sortedSetOf(comparator: Comparator<T>, vararg values: T): TreeSet<T>
Returns a new SortedSet with the given comparator and the initial elements
fun <T> sortedSetOf(vararg values: T): TreeSet<T>
Returns a new SortedSet with the initial elements
fun <A, B> A.to(that: B): Pair<A, B>
Creates a tuple of type Pair from this and that which can be useful for creating Map literals
with less noise, for example
val map = hashMap("a" to 1, "b" to 2)
assertEquals(2, map.size)
assertEquals(1, map.get("a"))
assertEquals(2, map.get("b"))
|
||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||