More standard library documentation.

This commit is contained in:
Dmitry Jemerov
2015-03-05 19:07:02 +01:00
parent cb27797845
commit 32072d0a4f
44 changed files with 1702 additions and 136 deletions
+8 -8
View File
@@ -19,7 +19,7 @@
package kotlin package kotlin
/** /**
* An array of bytes. When targeting the JVM, instances of this class are represented as byte[]. * An array of bytes. When targeting the JVM, instances of this class are represented as `byte[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero. * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/ */
public class ByteArray(size: Int) : Cloneable { public class ByteArray(size: Int) : Cloneable {
@@ -38,7 +38,7 @@ public class ByteArray(size: Int) : Cloneable {
} }
/** /**
* An array of chars. When targeting the JVM, instances of this class are represented as char[]. * An array of chars. When targeting the JVM, instances of this class are represented as `char[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero. * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/ */
public class CharArray(size: Int) : Cloneable { public class CharArray(size: Int) : Cloneable {
@@ -57,7 +57,7 @@ public class CharArray(size: Int) : Cloneable {
} }
/** /**
* An array of shorts. When targeting the JVM, instances of this class are represented as short[]. * An array of shorts. When targeting the JVM, instances of this class are represented as `short[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero. * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/ */
public class ShortArray(size: Int) : Cloneable { public class ShortArray(size: Int) : Cloneable {
@@ -76,7 +76,7 @@ public class ShortArray(size: Int) : Cloneable {
} }
/** /**
* An array of ints. When targeting the JVM, instances of this class are represented as int[]. * An array of ints. When targeting the JVM, instances of this class are represented as `int[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero. * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/ */
public class IntArray(size: Int) : Cloneable { public class IntArray(size: Int) : Cloneable {
@@ -95,7 +95,7 @@ public class IntArray(size: Int) : Cloneable {
} }
/** /**
* An array of longs. When targeting the JVM, instances of this class are represented as long[]. * An array of longs. When targeting the JVM, instances of this class are represented as `long[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero. * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/ */
public class LongArray(size: Int) : Cloneable { public class LongArray(size: Int) : Cloneable {
@@ -114,7 +114,7 @@ public class LongArray(size: Int) : Cloneable {
} }
/** /**
* An array of floats. When targeting the JVM, instances of this class are represented as float[]. * An array of floats. When targeting the JVM, instances of this class are represented as `float[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero. * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/ */
public class FloatArray(size: Int) : Cloneable { public class FloatArray(size: Int) : Cloneable {
@@ -133,7 +133,7 @@ public class FloatArray(size: Int) : Cloneable {
} }
/** /**
* An array of doubles. When targeting the JVM, instances of this class are represented as double[]. * An array of doubles. When targeting the JVM, instances of this class are represented as `double[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero. * @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/ */
public class DoubleArray(size: Int) : Cloneable { public class DoubleArray(size: Int) : Cloneable {
@@ -152,7 +152,7 @@ public class DoubleArray(size: Int) : Cloneable {
} }
/** /**
* An array of booleans. When targeting the JVM, instances of this class are represented as boolean[]. * An array of booleans. When targeting the JVM, instances of this class are represented as `boolean[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to false. * @constructor Creates a new array of the specified [size], with all elements initialized to false.
*/ */
public class BooleanArray(size: Int) : Cloneable { public class BooleanArray(size: Int) : Cloneable {
+12
View File
@@ -21,12 +21,24 @@ package kotlin
* represented as values of the primitive type `boolean`. * represented as values of the primitive type `boolean`.
*/ */
public class Boolean private () : Comparable<Boolean> { public class Boolean private () : Comparable<Boolean> {
/**
* Returns the inverse of this boolean.
*/
public fun not(): Boolean public fun not(): Boolean
/**
* Performs a logical `and` operation between this Boolean and the [other] one.
*/
public fun and(other: Boolean): Boolean public fun and(other: Boolean): Boolean
/**
* Performs a logical `or` operation between this Boolean and the [other] one.
*/
public fun or(other: Boolean): Boolean public fun or(other: Boolean): Boolean
/**
* Performs a logical `xor` operation between this Boolean and the [other] one.
*/
public fun xor(other: Boolean): Boolean public fun xor(other: Boolean): Boolean
public override fun compareTo(other: Boolean): Int public override fun compareTo(other: Boolean): Int
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -26,13 +26,13 @@ public annotation class data
/** /**
* Marks the annotated class, function or property as deprecated. * Marks the annotated class, function or property as deprecated.
* @param value the message explaining the deprecation and recommending an alternative API to use. * @property value the message explaining the deprecation and recommending an alternative API to use.
*/ */
public annotation class deprecated(val value: String) public annotation class deprecated(val value: String)
/** /**
* Suppresses the given compilation warnings in the annotated element. * Suppresses the given compilation warnings in the annotated element.
* @param names names of the compiler diagnostics to suppress. * @property names names of the compiler diagnostics to suppress.
*/ */
public annotation class suppress(vararg val names: String) public annotation class suppress(vararg val names: String)
@@ -18,72 +18,118 @@
package kotlin package kotlin
/** An extension function that takes 0 arguments. */
public trait ExtensionFunction0<in T, out R> { public trait ExtensionFunction0<in T, out R> {
/** Invokes the function. */
public fun T.invoke(): R public fun T.invoke(): R
} }
/** An extension function that takes 1 argument. */
public trait ExtensionFunction1<in T, in P1, out R> { public trait ExtensionFunction1<in T, in P1, out R> {
/** Invokes the function with the specified argument. */
public fun T.invoke(p1: P1): R public fun T.invoke(p1: P1): R
} }
/** An extension function that takes 2 arguments. */
public trait ExtensionFunction2<in T, in P1, in P2, out R> { public trait ExtensionFunction2<in T, in P1, in P2, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2): R public fun T.invoke(p1: P1, p2: P2): R
} }
/** An extension function that takes 3 arguments. */
public trait ExtensionFunction3<in T, in P1, in P2, in P3, out R> { public trait ExtensionFunction3<in T, in P1, in P2, in P3, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3): R public fun T.invoke(p1: P1, p2: P2, p3: P3): R
} }
/** An extension function that takes 4 arguments. */
public trait ExtensionFunction4<in T, in P1, in P2, in P3, in P4, out R> { public trait ExtensionFunction4<in T, in P1, in P2, in P3, in P4, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4): R
} }
/** An extension function that takes 5 arguments. */
public trait ExtensionFunction5<in T, in P1, in P2, in P3, in P4, in P5, out R> { public trait ExtensionFunction5<in T, in P1, in P2, in P3, in P4, in P5, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R
} }
/** An extension function that takes 6 arguments. */
public trait ExtensionFunction6<in T, in P1, in P2, in P3, in P4, in P5, in P6, out R> { public trait ExtensionFunction6<in T, in P1, in P2, in P3, in P4, in P5, in P6, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R
} }
/** An extension function that takes 7 arguments. */
public trait ExtensionFunction7<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, out R> { public trait ExtensionFunction7<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R
} }
/** An extension function that takes 8 arguments. */
public trait ExtensionFunction8<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, out R> { public trait ExtensionFunction8<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R
} }
/** An extension function that takes 9 arguments. */
public trait ExtensionFunction9<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, out R> { public trait ExtensionFunction9<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R
} }
/** An extension function that takes 10 arguments. */
public trait ExtensionFunction10<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, out R> { public trait ExtensionFunction10<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R
} }
/** An extension function that takes 11 arguments. */
public trait ExtensionFunction11<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, out R> { public trait ExtensionFunction11<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R
} }
/** An extension function that takes 12 arguments. */
public trait ExtensionFunction12<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, out R> { public trait ExtensionFunction12<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R
} }
/** An extension function that takes 13 arguments. */
public trait ExtensionFunction13<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, out R> { public trait ExtensionFunction13<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R
} }
/** An extension function that takes 14 arguments. */
public trait ExtensionFunction14<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, out R> { public trait ExtensionFunction14<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R
} }
/** An extension function that takes 15 arguments. */
public trait ExtensionFunction15<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, out R> { public trait ExtensionFunction15<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R
} }
/** An extension function that takes 16 arguments. */
public trait ExtensionFunction16<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, out R> { public trait ExtensionFunction16<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R
} }
/** An extension function that takes 17 arguments. */
public trait ExtensionFunction17<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, out R> { public trait ExtensionFunction17<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R
} }
/** An extension function that takes 18 arguments. */
public trait ExtensionFunction18<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, out R> { public trait ExtensionFunction18<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R
} }
/** An extension function that takes 19 arguments. */
public trait ExtensionFunction19<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, out R> { public trait ExtensionFunction19<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R
} }
/** An extension function that takes 20 arguments. */
public trait ExtensionFunction20<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, out R> { public trait ExtensionFunction20<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R
} }
/** An extension function that takes 21 arguments. */
public trait ExtensionFunction21<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, out R> { public trait ExtensionFunction21<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R
} }
/** An extension function that takes 22 arguments. */
public trait ExtensionFunction22<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, in P22, out R> { public trait ExtensionFunction22<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, in P22, out R> {
/** Invokes the function with the specified arguments. */
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R
} }
@@ -16,8 +16,22 @@
package kotlin package kotlin
/**
* Holder for special values of floating point types.
*/
public trait FloatingPointConstants<T> { public trait FloatingPointConstants<T> {
/**
* A constant holding the positive infinity value.
*/
public val POSITIVE_INFINITY: T public val POSITIVE_INFINITY: T
/**
* A constant holding the negative infinity value.
*/
public val NEGATIVE_INFINITY: T public val NEGATIVE_INFINITY: T
/**
* A constant holding the "not a number" value.
*/
public val NaN: T public val NaN: T
} }
+46
View File
@@ -18,72 +18,118 @@
package kotlin package kotlin
/** A function that takes 0 arguments. */
public trait Function0<out R> { public trait Function0<out R> {
/** Invokes the function. */
public fun invoke(): R public fun invoke(): R
} }
/** A function that takes 1 argument. */
public trait Function1<in P1, out R> { public trait Function1<in P1, out R> {
/** Invokes the function with the specified argument. */
public fun invoke(p1: P1): R public fun invoke(p1: P1): R
} }
/** A function that takes 2 arguments. */
public trait Function2<in P1, in P2, out R> { public trait Function2<in P1, in P2, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2): R public fun invoke(p1: P1, p2: P2): R
} }
/** A function that takes 3 arguments. */
public trait Function3<in P1, in P2, in P3, out R> { public trait Function3<in P1, in P2, in P3, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3): R public fun invoke(p1: P1, p2: P2, p3: P3): R
} }
/** A function that takes 4 arguments. */
public trait Function4<in P1, in P2, in P3, in P4, out R> { public trait Function4<in P1, in P2, in P3, in P4, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4): R
} }
/** A function that takes 5 arguments. */
public trait Function5<in P1, in P2, in P3, in P4, in P5, out R> { public trait Function5<in P1, in P2, in P3, in P4, in P5, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R
} }
/** A function that takes 6 arguments. */
public trait Function6<in P1, in P2, in P3, in P4, in P5, in P6, out R> { public trait Function6<in P1, in P2, in P3, in P4, in P5, in P6, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R
} }
/** A function that takes 7 arguments. */
public trait Function7<in P1, in P2, in P3, in P4, in P5, in P6, in P7, out R> { public trait Function7<in P1, in P2, in P3, in P4, in P5, in P6, in P7, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R
} }
/** A function that takes 8 arguments. */
public trait Function8<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, out R> { public trait Function8<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R
} }
/** A function that takes 9 arguments. */
public trait Function9<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, out R> { public trait Function9<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R
} }
/** A function that takes 10 arguments. */
public trait Function10<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, out R> { public trait Function10<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R
} }
/** A function that takes 11 arguments. */
public trait Function11<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, out R> { public trait Function11<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R
} }
/** A function that takes 12 arguments. */
public trait Function12<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, out R> { public trait Function12<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R
} }
/** A function that takes 13 arguments. */
public trait Function13<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, out R> { public trait Function13<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R
} }
/** A function that takes 14 arguments. */
public trait Function14<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, out R> { public trait Function14<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R
} }
/** A function that takes 15 arguments. */
public trait Function15<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, out R> { public trait Function15<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R
} }
/** A function that takes 16 arguments. */
public trait Function16<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, out R> { public trait Function16<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R
} }
/** A function that takes 17 arguments. */
public trait Function17<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, out R> { public trait Function17<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R
} }
/** A function that takes 18 arguments. */
public trait Function18<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, out R> { public trait Function18<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R
} }
/** A function that takes 19 arguments. */
public trait Function19<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, out R> { public trait Function19<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R
} }
/** A function that takes 20 arguments. */
public trait Function20<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, out R> { public trait Function20<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R
} }
/** A function that takes 21 arguments. */
public trait Function21<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, out R> { public trait Function21<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R
} }
/** A function that takes 22 arguments. */
public trait Function22<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, in P22, out R> { public trait Function22<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, in P22, out R> {
/** Invokes the function with the specified arguments. */
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R
} }
+5
View File
@@ -27,6 +27,9 @@ public annotation class noinline
* calling functions. Inline functions can use reified type parameters, and lambdas passed to inline * calling functions. Inline functions can use reified type parameters, and lambdas passed to inline
* functions can contain non-local returns. * functions can contain non-local returns.
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/inline-functions.html) for more information. * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/inline-functions.html) for more information.
*
* @property strategy the [InlineStrategy] to use for inlining this function.
*
* @see noinline * @see noinline
* @see inlineOptions * @see inlineOptions
*/ */
@@ -55,6 +58,8 @@ public enum class InlineStrategy {
* receiving function are allowed to use non-local control flow statements. Lambdas which are called from * receiving function are allowed to use non-local control flow statements. Lambdas which are called from
* a different execution context (for example, from an object contained in the receiving function) * a different execution context (for example, from an object contained in the receiving function)
* are restricted to local control flow statements. * are restricted to local control flow statements.
*
* @property value the inlining options selected for the annotated function parameter.
*/ */
public annotation class inlineOptions(vararg val value: InlineOption) public annotation class inlineOptions(vararg val value: InlineOption)
+8 -8
View File
@@ -18,7 +18,7 @@
package kotlin package kotlin
/** An iterator over a sequence of values of type Byte. */ /** An iterator over a sequence of values of type `Byte`. */
public abstract class ByteIterator : Iterator<Byte> { public abstract class ByteIterator : Iterator<Byte> {
override final fun next() = nextByte() override final fun next() = nextByte()
@@ -26,7 +26,7 @@ public abstract class ByteIterator : Iterator<Byte> {
public abstract fun nextByte(): Byte public abstract fun nextByte(): Byte
} }
/** An iterator over a sequence of values of type Char. */ /** An iterator over a sequence of values of type `Char`. */
public abstract class CharIterator : Iterator<Char> { public abstract class CharIterator : Iterator<Char> {
override final fun next() = nextChar() override final fun next() = nextChar()
@@ -34,7 +34,7 @@ public abstract class CharIterator : Iterator<Char> {
public abstract fun nextChar(): Char public abstract fun nextChar(): Char
} }
/** An iterator over a sequence of values of type Short. */ /** An iterator over a sequence of values of type `Short`. */
public abstract class ShortIterator : Iterator<Short> { public abstract class ShortIterator : Iterator<Short> {
override final fun next() = nextShort() override final fun next() = nextShort()
@@ -42,7 +42,7 @@ public abstract class ShortIterator : Iterator<Short> {
public abstract fun nextShort(): Short public abstract fun nextShort(): Short
} }
/** An iterator over a sequence of values of type Int. */ /** An iterator over a sequence of values of type `Int`. */
public abstract class IntIterator : Iterator<Int> { public abstract class IntIterator : Iterator<Int> {
override final fun next() = nextInt() override final fun next() = nextInt()
@@ -50,7 +50,7 @@ public abstract class IntIterator : Iterator<Int> {
public abstract fun nextInt(): Int public abstract fun nextInt(): Int
} }
/** An iterator over a sequence of values of type Long. */ /** An iterator over a sequence of values of type `Long`. */
public abstract class LongIterator : Iterator<Long> { public abstract class LongIterator : Iterator<Long> {
override final fun next() = nextLong() override final fun next() = nextLong()
@@ -58,7 +58,7 @@ public abstract class LongIterator : Iterator<Long> {
public abstract fun nextLong(): Long public abstract fun nextLong(): Long
} }
/** An iterator over a sequence of values of type Float. */ /** An iterator over a sequence of values of type `Float`. */
public abstract class FloatIterator : Iterator<Float> { public abstract class FloatIterator : Iterator<Float> {
override final fun next() = nextFloat() override final fun next() = nextFloat()
@@ -66,7 +66,7 @@ public abstract class FloatIterator : Iterator<Float> {
public abstract fun nextFloat(): Float public abstract fun nextFloat(): Float
} }
/** An iterator over a sequence of values of type Double. */ /** An iterator over a sequence of values of type `Double`. */
public abstract class DoubleIterator : Iterator<Double> { public abstract class DoubleIterator : Iterator<Double> {
override final fun next() = nextDouble() override final fun next() = nextDouble()
@@ -74,7 +74,7 @@ public abstract class DoubleIterator : Iterator<Double> {
public abstract fun nextDouble(): Double public abstract fun nextDouble(): Double
} }
/** An iterator over a sequence of values of type Boolean. */ /** An iterator over a sequence of values of type `Boolean`. */
public abstract class BooleanIterator : Iterator<Boolean> { public abstract class BooleanIterator : Iterator<Boolean> {
override final fun next() = nextBoolean() override final fun next() = nextBoolean()
@@ -20,7 +20,10 @@ package kotlin
import kotlin.internal.getProgressionFinalElement import kotlin.internal.getProgressionFinalElement
/** An iterator over a progression of values of type Byte. */ /**
* An iterator over a progression of values of type `Byte`.
* @property increment the number by which the value is incremented on each step.
*/
class ByteProgressionIterator(start: Byte, end: Byte, val increment: Int) : ByteIterator() { class ByteProgressionIterator(start: Byte, end: Byte, val increment: Int) : ByteIterator() {
private var next = start.toInt() private var next = start.toInt()
private val finalElement: Byte = getProgressionFinalElement(start.toInt(), end.toInt(), increment).toByte() private val finalElement: Byte = getProgressionFinalElement(start.toInt(), end.toInt(), increment).toByte()
@@ -40,7 +43,10 @@ class ByteProgressionIterator(start: Byte, end: Byte, val increment: Int) : Byte
} }
} }
/** An iterator over a progression of values of type Char. */ /**
* An iterator over a progression of values of type `Char`.
* @property increment the number by which the value is incremented on each step.
*/
class CharProgressionIterator(start: Char, end: Char, val increment: Int) : CharIterator() { class CharProgressionIterator(start: Char, end: Char, val increment: Int) : CharIterator() {
private var next = start.toInt() private var next = start.toInt()
private val finalElement: Char = getProgressionFinalElement(start.toInt(), end.toInt(), increment).toChar() private val finalElement: Char = getProgressionFinalElement(start.toInt(), end.toInt(), increment).toChar()
@@ -60,7 +66,10 @@ class CharProgressionIterator(start: Char, end: Char, val increment: Int) : Char
} }
} }
/** An iterator over a progression of values of type Short. */ /**
* An iterator over a progression of values of type `Short`.
* @property increment the number by which the value is incremented on each step.
*/
class ShortProgressionIterator(start: Short, end: Short, val increment: Int) : ShortIterator() { class ShortProgressionIterator(start: Short, end: Short, val increment: Int) : ShortIterator() {
private var next = start.toInt() private var next = start.toInt()
private val finalElement: Short = getProgressionFinalElement(start.toInt(), end.toInt(), increment).toShort() private val finalElement: Short = getProgressionFinalElement(start.toInt(), end.toInt(), increment).toShort()
@@ -80,7 +89,10 @@ class ShortProgressionIterator(start: Short, end: Short, val increment: Int) : S
} }
} }
/** An iterator over a progression of values of type Int. */ /**
* An iterator over a progression of values of type `Int`.
* @property increment the number by which the value is incremented on each step.
*/
class IntProgressionIterator(start: Int, end: Int, val increment: Int) : IntIterator() { class IntProgressionIterator(start: Int, end: Int, val increment: Int) : IntIterator() {
private var next = start private var next = start
private val finalElement: Int = getProgressionFinalElement(start, end, increment) private val finalElement: Int = getProgressionFinalElement(start, end, increment)
@@ -100,7 +112,10 @@ class IntProgressionIterator(start: Int, end: Int, val increment: Int) : IntIter
} }
} }
/** An iterator over a progression of values of type Long. */ /**
* An iterator over a progression of values of type `Long`.
* @property increment the number by which the value is incremented on each step.
*/
class LongProgressionIterator(start: Long, end: Long, val increment: Long) : LongIterator() { class LongProgressionIterator(start: Long, end: Long, val increment: Long) : LongIterator() {
private var next = start private var next = start
private val finalElement: Long = getProgressionFinalElement(start, end, increment) private val finalElement: Long = getProgressionFinalElement(start, end, increment)
@@ -120,7 +135,10 @@ class LongProgressionIterator(start: Long, end: Long, val increment: Long) : Lon
} }
} }
/** An iterator over a progression of values of type Float. */ /**
* An iterator over a progression of values of type `Float`.
* @property increment the number by which the value is incremented on each step.
*/
class FloatProgressionIterator(start: Float, val end: Float, val increment: Float) : FloatIterator() { class FloatProgressionIterator(start: Float, val end: Float, val increment: Float) : FloatIterator() {
private var next = start private var next = start
@@ -133,7 +151,10 @@ class FloatProgressionIterator(start: Float, val end: Float, val increment: Floa
} }
} }
/** An iterator over a progression of values of type Double. */ /**
* An iterator over a progression of values of type `Double`.
* @property increment the number by which the value is incremented on each step.
*/
class DoubleProgressionIterator(start: Double, val end: Double, val increment: Double) : DoubleIterator() { class DoubleProgressionIterator(start: Double, val end: Double, val increment: Double) : DoubleIterator() {
private var next = start private var next = start
+7 -7
View File
@@ -19,7 +19,7 @@
package kotlin package kotlin
/** /**
* A progression of values of type Byte. * A progression of values of type `Byte`.
*/ */
public class ByteProgression( public class ByteProgression(
override val start: Byte, override val start: Byte,
@@ -46,7 +46,7 @@ public class ByteProgression(
} }
/** /**
* A progression of values of type Char. * A progression of values of type `Char`.
*/ */
public class CharProgression( public class CharProgression(
override val start: Char, override val start: Char,
@@ -73,7 +73,7 @@ public class CharProgression(
} }
/** /**
* A progression of values of type Short. * A progression of values of type `Short`.
*/ */
public class ShortProgression( public class ShortProgression(
override val start: Short, override val start: Short,
@@ -100,7 +100,7 @@ public class ShortProgression(
} }
/** /**
* A progression of values of type Int. * A progression of values of type `Int`.
*/ */
public class IntProgression( public class IntProgression(
override val start: Int, override val start: Int,
@@ -127,7 +127,7 @@ public class IntProgression(
} }
/** /**
* A progression of values of type Long. * A progression of values of type `Long`.
*/ */
public class LongProgression( public class LongProgression(
override val start: Long, override val start: Long,
@@ -154,7 +154,7 @@ public class LongProgression(
} }
/** /**
* A progression of values of type Float. * A progression of values of type `Float`.
*/ */
public class FloatProgression( public class FloatProgression(
override val start: Float, override val start: Float,
@@ -182,7 +182,7 @@ public class FloatProgression(
} }
/** /**
* A progression of values of type Double. * A progression of values of type `Double`.
*/ */
public class DoubleProgression( public class DoubleProgression(
override val start: Double, override val start: Double,
@@ -26,4 +26,7 @@ public trait PropertyMetadata {
public val name: String public val name: String
} }
/**
* @suppress
*/
public class PropertyMetadataImpl(override val name: String): PropertyMetadata public class PropertyMetadataImpl(override val name: String): PropertyMetadata
+7 -7
View File
@@ -19,7 +19,7 @@
package kotlin package kotlin
/** /**
* A range of values of type Byte. * A range of values of type `Byte`.
*/ */
public class ByteRange(override val start: Byte, override val end: Byte) : Range<Byte>, Progression<Byte> { public class ByteRange(override val start: Byte, override val end: Byte) : Range<Byte>, Progression<Byte> {
override val increment: Int override val increment: Int
@@ -45,7 +45,7 @@ public class ByteRange(override val start: Byte, override val end: Byte) : Range
} }
/** /**
* A range of values of type Char. * A range of values of type `Char`.
*/ */
public class CharRange(override val start: Char, override val end: Char) : Range<Char>, Progression<Char> { public class CharRange(override val start: Char, override val end: Char) : Range<Char>, Progression<Char> {
override val increment: Int override val increment: Int
@@ -71,7 +71,7 @@ public class CharRange(override val start: Char, override val end: Char) : Range
} }
/** /**
* A range of values of type Short. * A range of values of type `Short`.
*/ */
public class ShortRange(override val start: Short, override val end: Short) : Range<Short>, Progression<Short> { public class ShortRange(override val start: Short, override val end: Short) : Range<Short>, Progression<Short> {
override val increment: Int override val increment: Int
@@ -97,7 +97,7 @@ public class ShortRange(override val start: Short, override val end: Short) : Ra
} }
/** /**
* A range of values of type Int. * A range of values of type `Int`.
*/ */
public class IntRange(override val start: Int, override val end: Int) : Range<Int>, Progression<Int> { public class IntRange(override val start: Int, override val end: Int) : Range<Int>, Progression<Int> {
override val increment: Int override val increment: Int
@@ -123,7 +123,7 @@ public class IntRange(override val start: Int, override val end: Int) : Range<In
} }
/** /**
* A range of values of type Long. * A range of values of type `Long`.
*/ */
public class LongRange(override val start: Long, override val end: Long) : Range<Long>, Progression<Long> { public class LongRange(override val start: Long, override val end: Long) : Range<Long>, Progression<Long> {
override val increment: Long override val increment: Long
@@ -149,7 +149,7 @@ public class LongRange(override val start: Long, override val end: Long) : Range
} }
/** /**
* A range of values of type Float. * A range of values of type `Float`.
*/ */
public class FloatRange(override val start: Float, override val end: Float) : Range<Float>, Progression<Float> { public class FloatRange(override val start: Float, override val end: Float) : Range<Float>, Progression<Float> {
override val increment: Float override val increment: Float
@@ -175,7 +175,7 @@ public class FloatRange(override val start: Float, override val end: Float) : Ra
} }
/** /**
* A range of values of type Double. * A range of values of type `Double`.
*/ */
public class DoubleRange(override val start: Double, override val end: Double) : Range<Double>, Progression<Double> { public class DoubleRange(override val start: Double, override val end: Double) : Range<Double>, Progression<Double> {
override val increment: Double override val increment: Double
+3
View File
@@ -16,6 +16,9 @@
package kotlin package kotlin
/**
* The type with only one value: the Unit object. This type corresponds to the `void` type in Java.
*/
public object Unit { public object Unit {
override fun toString() = "kotlin.Unit" override fun toString() = "kotlin.Unit"
} }
@@ -29,7 +29,7 @@ class GenerateArrays(out: PrintWriter) : BuiltInsSourceGenerator(out) {
val s = kind.capitalized val s = kind.capitalized
val defaultValue = when(kind) { PrimitiveType.BOOLEAN -> "false"; else -> "zero" } val defaultValue = when(kind) { PrimitiveType.BOOLEAN -> "false"; else -> "zero" }
out.println("/**") out.println("/**")
out.println(" * An array of ${typeLower}s. When targeting the JVM, instances of this class are represented as ${typeLower}[].") out.println(" * An array of ${typeLower}s. When targeting the JVM, instances of this class are represented as `${typeLower}[]`.")
out.println(" * @constructor Creates a new array of the specified [size], with all elements initialized to ${defaultValue}.") out.println(" * @constructor Creates a new array of the specified [size], with all elements initialized to ${defaultValue}.")
out.println(" */") out.println(" */")
out.println("public class ${s}Array(size: Int) : Cloneable {") out.println("public class ${s}Array(size: Int) : Cloneable {")
@@ -24,14 +24,15 @@ val MAX_PARAM_COUNT = 22
enum class FunctionKind( enum class FunctionKind(
private val classNamePrefix: String, private val classNamePrefix: String,
val docPrefix: String?,
val hasReceiverParameter: Boolean, val hasReceiverParameter: Boolean,
private val superClassNamePrefix: String? private val superClassNamePrefix: String?
) { ) {
FUNCTION : FunctionKind("Function", false, null) FUNCTION : FunctionKind("Function", "A function", false, null)
EXTENSION_FUNCTION : FunctionKind("ExtensionFunction", true, null) EXTENSION_FUNCTION : FunctionKind("ExtensionFunction", "An extension function", true, null)
K_FUNCTION : FunctionKind("KFunction", false, "Function") K_FUNCTION : FunctionKind("KFunction", null, false, "Function")
K_MEMBER_FUNCTION : FunctionKind("KMemberFunction", true, "ExtensionFunction") K_MEMBER_FUNCTION : FunctionKind("KMemberFunction", null, true, "ExtensionFunction")
K_EXTENSION_FUNCTION : FunctionKind("KExtensionFunction", true, "ExtensionFunction") K_EXTENSION_FUNCTION : FunctionKind("KExtensionFunction", null, true, "ExtensionFunction")
fun getFileName() = (if (isReflection()) "reflect/" else "") + classNamePrefix + "s.kt" fun getFileName() = (if (isReflection()) "reflect/" else "") + classNamePrefix + "s.kt"
fun getClassName(i: Int) = classNamePrefix + i fun getClassName(i: Int) = classNamePrefix + i
@@ -62,6 +63,7 @@ class GenerateFunctions(out: PrintWriter, val kind: FunctionKind) : BuiltInsSour
override fun generateBody() { override fun generateBody() {
for (i in 0..MAX_PARAM_COUNT) { for (i in 0..MAX_PARAM_COUNT) {
generateDocumentation(kind.docPrefix, i)
out.print("public trait " + kind.getClassName(i)) out.print("public trait " + kind.getClassName(i))
generateTypeParameters(i, true) generateTypeParameters(i, true)
generateSuperClass(i) generateSuperClass(i)
@@ -69,6 +71,12 @@ class GenerateFunctions(out: PrintWriter, val kind: FunctionKind) : BuiltInsSour
} }
} }
fun generateDocumentation(docPrefix: String?, i: Int) {
if (docPrefix == null) return
val suffix = if (i == 1) "" else "s"
out.println("/** $docPrefix that takes $i argument${suffix}. */")
}
fun generateSuperClass(i: Int) { fun generateSuperClass(i: Int) {
val superClass = kind.getSuperClassName(i) val superClass = kind.getSuperClassName(i)
if (superClass != null) { if (superClass != null) {
@@ -89,6 +97,12 @@ class GenerateFunctions(out: PrintWriter, val kind: FunctionKind) : BuiltInsSour
} }
fun generateInvokeSignature(i: Int) { fun generateInvokeSignature(i: Int) {
if (i == 0) {
out.println(" /** Invokes the function. */")
} else {
val suffix = if (i == 1) "" else "s"
out.println(" /** Invokes the function with the specified argument${suffix}. */")
}
out.print(" public fun ${if (kind.hasReceiverParameter) "T." else ""}invoke(") out.print(" public fun ${if (kind.hasReceiverParameter) "T." else ""}invoke(")
for (j in 1..i) { for (j in 1..i) {
out.print("p$j: P$j") out.print("p$j: P$j")
@@ -24,7 +24,7 @@ class GenerateIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
override fun generateBody() { override fun generateBody() {
for (kind in PrimitiveType.values()) { for (kind in PrimitiveType.values()) {
val s = kind.capitalized val s = kind.capitalized
out.println("/** An iterator over a sequence of values of type $s. */") out.println("/** An iterator over a sequence of values of type `$s`. */")
out.println("public abstract class ${s}Iterator : Iterator<$s> {" ) out.println("public abstract class ${s}Iterator : Iterator<$s> {" )
out.println(" override final fun next() = next$s()") out.println(" override final fun next() = next$s()")
out.println() out.println()
@@ -21,10 +21,26 @@ import org.jetbrains.kotlin.generators.builtins.generateBuiltIns.BuiltInsSourceG
import java.io.PrintWriter import java.io.PrintWriter
class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
private val binaryOperators: List<String> = listOf("plus", "minus", "times", "div", "mod") private val binaryOperators: Map<String, String> = mapOf(
private val unaryOperators: List<String> = listOf("inc", "dec", "plus", "minus") "plus" to "Adds the other value to this value.",
private val shiftOperators: List<String> = listOf("shl", "shr", "ushr") "minus" to "Subtracts the other value from this value.",
private val bitwiseOperators: List<String> = listOf("and", "or", "xor") "times" to "Multiplies this value by the other value.",
"div" to "Divides this value by the other value.",
"mod" to "Calculates the remainder of dividing this value by the other value."
)
private val unaryOperators: Map<String, String> = mapOf(
"inc" to "Increments this value.",
"dec" to "Decrements this value.",
"plus" to "Returns this value.",
"minus" to "Returns the negative of this value.")
private val shiftOperators: Map<String, String> = mapOf(
"shl" to "Shifts this value left by [bits].",
"shr" to "Shifts this value right by [bits], filling the leftmost bits with copies of the sign bit.",
"ushr" to "Shifts this value right by [bits], filling the leftmost bits with zeros.")
private val bitwiseOperators: Map<String, String> = mapOf(
"and" to "Performs a bitwise AND operation between the two values.",
"or" to "Performs a bitwise OR operation between the two values.",
"xor" to "Performs a bitwise XOR operation between the two values.")
private val typeDescriptions: Map<PrimitiveType, String> = hashMapOf( private val typeDescriptions: Map<PrimitiveType, String> = hashMapOf(
PrimitiveType.DOUBLE to "double-precision 64-bit IEEE 754 floating point number", PrimitiveType.DOUBLE to "double-precision 64-bit IEEE 754 floating point number",
PrimitiveType.FLOAT to "single-precision 32-bit IEEE 754 floating point number", PrimitiveType.FLOAT to "single-precision 32-bit IEEE 754 floating point number",
@@ -61,7 +77,7 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
generateBitwiseOperators(className) generateBitwiseOperators(className)
} }
generateConversions() generateConversions(kind)
out.println("}\n") out.println("}\n")
} }
@@ -76,6 +92,17 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
private fun generateCompareTo(thisKind: PrimitiveType) { private fun generateCompareTo(thisKind: PrimitiveType) {
for (otherKind in PrimitiveType.exceptBoolean) { for (otherKind in PrimitiveType.exceptBoolean) {
out.println("/**")
if (thisKind == PrimitiveType.CHAR && otherKind != PrimitiveType.CHAR) {
out.println(" * Compares the character code of this character with the specified value for order.")
} else if (thisKind != PrimitiveType.CHAR && otherKind == PrimitiveType.CHAR) {
out.println(" * Compares this value with the character code of the specified character for order.")
} else {
out.println(" * Compares this value with the specified value for order.")
}
out.println(" * Returns zero if this value is equal to the specified other value, a negative number if its less than other, ")
out.println(" * or a positive number if its greater than other.")
out.println(" */")
out.print(" public ") out.print(" public ")
if (otherKind == thisKind) out.print("override ") if (otherKind == thisKind) out.print("override ")
out.println("fun compareTo(other: ${otherKind.capitalized}): Int") out.println("fun compareTo(other: ${otherKind.capitalized}): Int")
@@ -84,17 +111,18 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
} }
private fun generateBinaryOperators(thisKind: PrimitiveType) { private fun generateBinaryOperators(thisKind: PrimitiveType) {
for (name in binaryOperators) { for ((name, doc) in binaryOperators) {
generateOperator(name, thisKind) generateOperator(name, doc, thisKind)
} }
} }
private fun generateOperator(name: String, thisKind: PrimitiveType) { private fun generateOperator(name: String, doc: String, thisKind: PrimitiveType) {
for (otherKind in PrimitiveType.exceptBoolean) { for (otherKind in PrimitiveType.exceptBoolean) {
if (thisKind == PrimitiveType.CHAR && otherKind == PrimitiveType.CHAR && name != "minus") { if (thisKind == PrimitiveType.CHAR && otherKind == PrimitiveType.CHAR && name != "minus") {
continue continue
} }
val returnType = getOperatorReturnType(thisKind, otherKind) val returnType = getOperatorReturnType(thisKind, otherKind)
out.println(" /** $doc */")
out.println(" public fun $name(other: ${otherKind.capitalized}): $returnType") out.println(" public fun $name(other: ${otherKind.capitalized}): $returnType")
} }
out.println() out.println()
@@ -102,10 +130,12 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
private fun generateRangeTo(thisKind: PrimitiveType) { private fun generateRangeTo(thisKind: PrimitiveType) {
if (thisKind == PrimitiveType.CHAR) { if (thisKind == PrimitiveType.CHAR) {
out.println(" /** Creates a range from this value to the specified [other] value. */")
out.println(" public fun rangeTo(other: Char): CharRange") out.println(" public fun rangeTo(other: Char): CharRange")
} else { } else {
for (otherKind in PrimitiveType.exceptBoolean) { for (otherKind in PrimitiveType.exceptBoolean) {
val returnType = if (otherKind.ordinal() > thisKind.ordinal()) otherKind else thisKind val returnType = if (otherKind.ordinal() > thisKind.ordinal()) otherKind else thisKind
out.println(" /** Creates a range from this value to the specified [other] value. */")
out.println(" public fun rangeTo(other: ${otherKind.capitalized}): ${returnType.capitalized}Range") out.println(" public fun rangeTo(other: ${otherKind.capitalized}): ${returnType.capitalized}Range")
} }
} }
@@ -114,28 +144,35 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
} }
private fun generateUnaryOperators(kind: PrimitiveType) { private fun generateUnaryOperators(kind: PrimitiveType) {
for (name in unaryOperators) { for ((name, doc) in unaryOperators) {
val returnType = if (kind in listOf(PrimitiveType.SHORT, PrimitiveType.BYTE, PrimitiveType.CHAR) && val returnType = if (kind in listOf(PrimitiveType.SHORT, PrimitiveType.BYTE, PrimitiveType.CHAR) &&
name in listOf("plus", "minus")) "Int" else kind.capitalized name in listOf("plus", "minus")) "Int" else kind.capitalized
out.println(" /** $doc */")
out.println(" public fun $name(): $returnType") out.println(" public fun $name(): $returnType")
} }
out.println() out.println()
} }
private fun generateBitwiseOperators(className: String) { private fun generateBitwiseOperators(className: String) {
for (name in shiftOperators) { for ((name, doc) in shiftOperators) {
out.println(" /** $doc */")
out.println(" public fun $name(bits: Int): $className") out.println(" public fun $name(bits: Int): $className")
} }
for (name in bitwiseOperators) { for ((name, doc) in bitwiseOperators) {
out.println(" /** $doc */")
out.println(" public fun $name(other: $className): $className") out.println(" public fun $name(other: $className): $className")
} }
out.println(" /** Inverts the bits in this value/ */")
out.println(" public fun inv(): $className") out.println(" public fun inv(): $className")
out.println() out.println()
} }
private fun generateConversions() { private fun generateConversions(kind: PrimitiveType) {
for (otherKind in PrimitiveType.exceptBoolean) { for (otherKind in PrimitiveType.exceptBoolean) {
val name = otherKind.capitalized val name = otherKind.capitalized
if (kind == PrimitiveType.CHAR) { // Char is not a Number and does not inherit Number's javadocs
out.println(" /** Returns the value of this character as a `$name`. */")
}
out.println(" public override fun to$name(): $name") out.println(" public override fun to$name(): $name")
} }
} }
@@ -31,7 +31,10 @@ fun integerProgressionIterator(kind: ProgressionKind): String {
else -> "" to "" else -> "" to ""
} }
return """/** An iterator over a progression of values of type $t. */ return """/**
* An iterator over a progression of values of type `$t`.
* @property increment the number by which the value is incremented on each step.
*/
class ${t}ProgressionIterator(start: $t, end: $t, val increment: $incrementType) : ${t}Iterator() { class ${t}ProgressionIterator(start: $t, end: $t, val increment: $incrementType) : ${t}Iterator() {
private var next = start$toInt private var next = start$toInt
private val finalElement: $t = getProgressionFinalElement(start$toInt, end$toInt, increment)$toType private val finalElement: $t = getProgressionFinalElement(start$toInt, end$toInt, increment)$toType
@@ -55,7 +58,10 @@ class ${t}ProgressionIterator(start: $t, end: $t, val increment: $incrementType)
fun floatingPointProgressionIterator(kind: ProgressionKind): String { fun floatingPointProgressionIterator(kind: ProgressionKind): String {
val t = kind.capitalized val t = kind.capitalized
return """/** An iterator over a progression of values of type $t. */ return """/**
* An iterator over a progression of values of type `$t`.
* @property increment the number by which the value is incremented on each step.
*/
class ${t}ProgressionIterator(start: $t, val end: $t, val increment: $t) : ${t}Iterator() { class ${t}ProgressionIterator(start: $t, val end: $t, val increment: $t) : ${t}Iterator() {
private var next = start private var next = start
@@ -66,7 +66,7 @@ class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) {
out.println( out.println(
"""/** """/**
* A progression of values of type $t. * A progression of values of type `$t`.
*/ */
public class $progression( public class $progression(
override val start: $t, override val start: $t,
@@ -64,7 +64,7 @@ class GenerateRanges(out: PrintWriter) : BuiltInsSourceGenerator(out) {
out.println( out.println(
"""/** """/**
* A range of values of type $t. * A range of values of type `$t`.
*/ */
public class $range(override val start: $t, override val end: $t) : Range<$t>, Progression<$t> { public class $range(override val start: $t, override val end: $t) : Range<$t>, Progression<$t> {
override val increment: $incrementType override val increment: $incrementType
+245
View File
@@ -6,198 +6,443 @@ package kotlin
// //
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Byte.downTo(to: Byte): ByteProgression { public fun Byte.downTo(to: Byte): ByteProgression {
return ByteProgression(this, to, -1) return ByteProgression(this, to, -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Byte.downTo(to: Char): CharProgression { public fun Byte.downTo(to: Char): CharProgression {
return CharProgression(this.toChar(), to, -1) return CharProgression(this.toChar(), to, -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Byte.downTo(to: Short): ShortProgression { public fun Byte.downTo(to: Short): ShortProgression {
return ShortProgression(this.toShort(), to, -1) return ShortProgression(this.toShort(), to, -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Byte.downTo(to: Int): IntProgression { public fun Byte.downTo(to: Int): IntProgression {
return IntProgression(this.toInt(), to, -1) return IntProgression(this.toInt(), to, -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Byte.downTo(to: Long): LongProgression { public fun Byte.downTo(to: Long): LongProgression {
return LongProgression(this.toLong(), to, -1.toLong()) return LongProgression(this.toLong(), to, -1.toLong())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Byte.downTo(to: Float): FloatProgression { public fun Byte.downTo(to: Float): FloatProgression {
return FloatProgression(this.toFloat(), to, -1.toFloat()) return FloatProgression(this.toFloat(), to, -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Byte.downTo(to: Double): DoubleProgression { public fun Byte.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Char.downTo(to: Byte): CharProgression { public fun Char.downTo(to: Byte): CharProgression {
return CharProgression(this, to.toChar(), -1) return CharProgression(this, to.toChar(), -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Char.downTo(to: Char): CharProgression { public fun Char.downTo(to: Char): CharProgression {
return CharProgression(this, to, -1) return CharProgression(this, to, -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Char.downTo(to: Short): ShortProgression { public fun Char.downTo(to: Short): ShortProgression {
return ShortProgression(this.toShort(), to, -1) return ShortProgression(this.toShort(), to, -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Char.downTo(to: Int): IntProgression { public fun Char.downTo(to: Int): IntProgression {
return IntProgression(this.toInt(), to, -1) return IntProgression(this.toInt(), to, -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Char.downTo(to: Long): LongProgression { public fun Char.downTo(to: Long): LongProgression {
return LongProgression(this.toLong(), to, -1.toLong()) return LongProgression(this.toLong(), to, -1.toLong())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Char.downTo(to: Float): FloatProgression { public fun Char.downTo(to: Float): FloatProgression {
return FloatProgression(this.toFloat(), to, -1.toFloat()) return FloatProgression(this.toFloat(), to, -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Char.downTo(to: Double): DoubleProgression { public fun Char.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Short.downTo(to: Byte): ShortProgression { public fun Short.downTo(to: Byte): ShortProgression {
return ShortProgression(this, to.toShort(), -1) return ShortProgression(this, to.toShort(), -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Short.downTo(to: Char): ShortProgression { public fun Short.downTo(to: Char): ShortProgression {
return ShortProgression(this, to.toShort(), -1) return ShortProgression(this, to.toShort(), -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Short.downTo(to: Short): ShortProgression { public fun Short.downTo(to: Short): ShortProgression {
return ShortProgression(this, to, -1) return ShortProgression(this, to, -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Short.downTo(to: Int): IntProgression { public fun Short.downTo(to: Int): IntProgression {
return IntProgression(this.toInt(), to, -1) return IntProgression(this.toInt(), to, -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Short.downTo(to: Long): LongProgression { public fun Short.downTo(to: Long): LongProgression {
return LongProgression(this.toLong(), to, -1.toLong()) return LongProgression(this.toLong(), to, -1.toLong())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Short.downTo(to: Float): FloatProgression { public fun Short.downTo(to: Float): FloatProgression {
return FloatProgression(this.toFloat(), to, -1.toFloat()) return FloatProgression(this.toFloat(), to, -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Short.downTo(to: Double): DoubleProgression { public fun Short.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Int.downTo(to: Byte): IntProgression { public fun Int.downTo(to: Byte): IntProgression {
return IntProgression(this, to.toInt(), -1) return IntProgression(this, to.toInt(), -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Int.downTo(to: Char): IntProgression { public fun Int.downTo(to: Char): IntProgression {
return IntProgression(this, to.toInt(), -1) return IntProgression(this, to.toInt(), -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Int.downTo(to: Short): IntProgression { public fun Int.downTo(to: Short): IntProgression {
return IntProgression(this, to.toInt(), -1) return IntProgression(this, to.toInt(), -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Int.downTo(to: Int): IntProgression { public fun Int.downTo(to: Int): IntProgression {
return IntProgression(this, to, -1) return IntProgression(this, to, -1)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Int.downTo(to: Long): LongProgression { public fun Int.downTo(to: Long): LongProgression {
return LongProgression(this.toLong(), to, -1.toLong()) return LongProgression(this.toLong(), to, -1.toLong())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Int.downTo(to: Float): FloatProgression { public fun Int.downTo(to: Float): FloatProgression {
return FloatProgression(this.toFloat(), to, -1.toFloat()) return FloatProgression(this.toFloat(), to, -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Int.downTo(to: Double): DoubleProgression { public fun Int.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Long.downTo(to: Byte): LongProgression { public fun Long.downTo(to: Byte): LongProgression {
return LongProgression(this, to.toLong(), -1.toLong()) return LongProgression(this, to.toLong(), -1.toLong())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Long.downTo(to: Char): LongProgression { public fun Long.downTo(to: Char): LongProgression {
return LongProgression(this, to.toLong(), -1.toLong()) return LongProgression(this, to.toLong(), -1.toLong())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Long.downTo(to: Short): LongProgression { public fun Long.downTo(to: Short): LongProgression {
return LongProgression(this, to.toLong(), -1.toLong()) return LongProgression(this, to.toLong(), -1.toLong())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Long.downTo(to: Int): LongProgression { public fun Long.downTo(to: Int): LongProgression {
return LongProgression(this, to.toLong(), -1.toLong()) return LongProgression(this, to.toLong(), -1.toLong())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Long.downTo(to: Long): LongProgression { public fun Long.downTo(to: Long): LongProgression {
return LongProgression(this, to, -1.toLong()) return LongProgression(this, to, -1.toLong())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Long.downTo(to: Float): FloatProgression { public fun Long.downTo(to: Float): FloatProgression {
return FloatProgression(this.toFloat(), to, -1.toFloat()) return FloatProgression(this.toFloat(), to, -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Long.downTo(to: Double): DoubleProgression { public fun Long.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Float.downTo(to: Byte): FloatProgression { public fun Float.downTo(to: Byte): FloatProgression {
return FloatProgression(this, to.toFloat(), -1.toFloat()) return FloatProgression(this, to.toFloat(), -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Float.downTo(to: Char): FloatProgression { public fun Float.downTo(to: Char): FloatProgression {
return FloatProgression(this, to.toFloat(), -1.toFloat()) return FloatProgression(this, to.toFloat(), -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Float.downTo(to: Short): FloatProgression { public fun Float.downTo(to: Short): FloatProgression {
return FloatProgression(this, to.toFloat(), -1.toFloat()) return FloatProgression(this, to.toFloat(), -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Float.downTo(to: Int): FloatProgression { public fun Float.downTo(to: Int): FloatProgression {
return FloatProgression(this, to.toFloat(), -1.toFloat()) return FloatProgression(this, to.toFloat(), -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Float.downTo(to: Long): FloatProgression { public fun Float.downTo(to: Long): FloatProgression {
return FloatProgression(this, to.toFloat(), -1.toFloat()) return FloatProgression(this, to.toFloat(), -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Float.downTo(to: Float): FloatProgression { public fun Float.downTo(to: Float): FloatProgression {
return FloatProgression(this, to, -1.toFloat()) return FloatProgression(this, to, -1.toFloat())
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Float.downTo(to: Double): DoubleProgression { public fun Float.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Double.downTo(to: Byte): DoubleProgression { public fun Double.downTo(to: Byte): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Double.downTo(to: Char): DoubleProgression { public fun Double.downTo(to: Char): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Double.downTo(to: Short): DoubleProgression { public fun Double.downTo(to: Short): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Double.downTo(to: Int): DoubleProgression { public fun Double.downTo(to: Int): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Double.downTo(to: Long): DoubleProgression { public fun Double.downTo(to: Long): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Double.downTo(to: Float): DoubleProgression { public fun Double.downTo(to: Float): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun Double.downTo(to: Double): DoubleProgression { public fun Double.downTo(to: Double): DoubleProgression {
return DoubleProgression(this, to, -1.0) return DoubleProgression(this, to, -1.0)
} }
+23 -23
View File
@@ -700,7 +700,7 @@ public fun String.first(): Char {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun <T> Array<out T>.first(predicate: (T) -> Boolean): T { public inline fun <T> Array<out T>.first(predicate: (T) -> Boolean): T {
@@ -709,7 +709,7 @@ public inline fun <T> Array<out T>.first(predicate: (T) -> Boolean): T {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun BooleanArray.first(predicate: (Boolean) -> Boolean): Boolean { public inline fun BooleanArray.first(predicate: (Boolean) -> Boolean): Boolean {
@@ -718,7 +718,7 @@ public inline fun BooleanArray.first(predicate: (Boolean) -> Boolean): Boolean {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun ByteArray.first(predicate: (Byte) -> Boolean): Byte { public inline fun ByteArray.first(predicate: (Byte) -> Boolean): Byte {
@@ -727,7 +727,7 @@ public inline fun ByteArray.first(predicate: (Byte) -> Boolean): Byte {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun CharArray.first(predicate: (Char) -> Boolean): Char { public inline fun CharArray.first(predicate: (Char) -> Boolean): Char {
@@ -736,7 +736,7 @@ public inline fun CharArray.first(predicate: (Char) -> Boolean): Char {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun DoubleArray.first(predicate: (Double) -> Boolean): Double { public inline fun DoubleArray.first(predicate: (Double) -> Boolean): Double {
@@ -745,7 +745,7 @@ public inline fun DoubleArray.first(predicate: (Double) -> Boolean): Double {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun FloatArray.first(predicate: (Float) -> Boolean): Float { public inline fun FloatArray.first(predicate: (Float) -> Boolean): Float {
@@ -754,7 +754,7 @@ public inline fun FloatArray.first(predicate: (Float) -> Boolean): Float {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun IntArray.first(predicate: (Int) -> Boolean): Int { public inline fun IntArray.first(predicate: (Int) -> Boolean): Int {
@@ -763,7 +763,7 @@ public inline fun IntArray.first(predicate: (Int) -> Boolean): Int {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun LongArray.first(predicate: (Long) -> Boolean): Long { public inline fun LongArray.first(predicate: (Long) -> Boolean): Long {
@@ -772,7 +772,7 @@ public inline fun LongArray.first(predicate: (Long) -> Boolean): Long {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun ShortArray.first(predicate: (Short) -> Boolean): Short { public inline fun ShortArray.first(predicate: (Short) -> Boolean): Short {
@@ -781,7 +781,7 @@ public inline fun ShortArray.first(predicate: (Short) -> Boolean): Short {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun <T> Iterable<T>.first(predicate: (T) -> Boolean): T { public inline fun <T> Iterable<T>.first(predicate: (T) -> Boolean): T {
@@ -790,7 +790,7 @@ public inline fun <T> Iterable<T>.first(predicate: (T) -> Boolean): T {
} }
/** /**
* "Returns the first element matching the given [predicate]. * Returns the first element matching the given [predicate].
* @throws NoSuchElementException if no such element is found. * @throws NoSuchElementException if no such element is found.
*/ */
public inline fun <T> Stream<T>.first(predicate: (T) -> Boolean): T { public inline fun <T> Stream<T>.first(predicate: (T) -> Boolean): T {
@@ -925,7 +925,7 @@ public fun String.firstOrNull(): Char? {
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun <T> Array<out T>.firstOrNull(predicate: (T) -> Boolean): T? { public inline fun <T> Array<out T>.firstOrNull(predicate: (T) -> Boolean): T? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -933,7 +933,7 @@ public inline fun <T> Array<out T>.firstOrNull(predicate: (T) -> Boolean): T? {
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun BooleanArray.firstOrNull(predicate: (Boolean) -> Boolean): Boolean? { public inline fun BooleanArray.firstOrNull(predicate: (Boolean) -> Boolean): Boolean? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -941,7 +941,7 @@ public inline fun BooleanArray.firstOrNull(predicate: (Boolean) -> Boolean): Boo
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun ByteArray.firstOrNull(predicate: (Byte) -> Boolean): Byte? { public inline fun ByteArray.firstOrNull(predicate: (Byte) -> Boolean): Byte? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -949,7 +949,7 @@ public inline fun ByteArray.firstOrNull(predicate: (Byte) -> Boolean): Byte? {
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun CharArray.firstOrNull(predicate: (Char) -> Boolean): Char? { public inline fun CharArray.firstOrNull(predicate: (Char) -> Boolean): Char? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -957,7 +957,7 @@ public inline fun CharArray.firstOrNull(predicate: (Char) -> Boolean): Char? {
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun DoubleArray.firstOrNull(predicate: (Double) -> Boolean): Double? { public inline fun DoubleArray.firstOrNull(predicate: (Double) -> Boolean): Double? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -965,7 +965,7 @@ public inline fun DoubleArray.firstOrNull(predicate: (Double) -> Boolean): Doubl
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun FloatArray.firstOrNull(predicate: (Float) -> Boolean): Float? { public inline fun FloatArray.firstOrNull(predicate: (Float) -> Boolean): Float? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -973,7 +973,7 @@ public inline fun FloatArray.firstOrNull(predicate: (Float) -> Boolean): Float?
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun IntArray.firstOrNull(predicate: (Int) -> Boolean): Int? { public inline fun IntArray.firstOrNull(predicate: (Int) -> Boolean): Int? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -981,7 +981,7 @@ public inline fun IntArray.firstOrNull(predicate: (Int) -> Boolean): Int? {
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun LongArray.firstOrNull(predicate: (Long) -> Boolean): Long? { public inline fun LongArray.firstOrNull(predicate: (Long) -> Boolean): Long? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -989,7 +989,7 @@ public inline fun LongArray.firstOrNull(predicate: (Long) -> Boolean): Long? {
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun ShortArray.firstOrNull(predicate: (Short) -> Boolean): Short? { public inline fun ShortArray.firstOrNull(predicate: (Short) -> Boolean): Short? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -997,7 +997,7 @@ public inline fun ShortArray.firstOrNull(predicate: (Short) -> Boolean): Short?
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun <T> Iterable<T>.firstOrNull(predicate: (T) -> Boolean): T? { public inline fun <T> Iterable<T>.firstOrNull(predicate: (T) -> Boolean): T? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -1005,7 +1005,7 @@ public inline fun <T> Iterable<T>.firstOrNull(predicate: (T) -> Boolean): T? {
} }
/** /**
* Returns first element matching the given [predicate], or `null` if element was not found * Returns the first element matching the given [predicate], or `null` if element was not found
*/ */
public inline fun <T> Stream<T>.firstOrNull(predicate: (T) -> Boolean): T? { public inline fun <T> Stream<T>.firstOrNull(predicate: (T) -> Boolean): T? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -1013,7 +1013,7 @@ public inline fun <T> Stream<T>.firstOrNull(predicate: (T) -> Boolean): T? {
} }
/** /**
* Returns first character matching the given [predicate], or `null` if character was not found * Returns the first character matching the given [predicate], or `null` if character was not found
*/ */
public inline fun String.firstOrNull(predicate: (Char) -> Boolean): Char? { public inline fun String.firstOrNull(predicate: (Char) -> Boolean): Char? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -1,5 +1,9 @@
package kotlin package kotlin
/**
* Returns an array with the specified [size], where each element is calculated by calling the specified
* [init] function. The `init` function returns an array element given its index.
*/
public inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> { public inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
val result = arrayOfNulls<T>(size) val result = arrayOfNulls<T>(size)
@@ -75,8 +75,12 @@ public fun ByteArray.toString(charset: String): String = String(this, charset)
*/ */
public fun ByteArray.toString(charset: Charset): String = String(this, charset) public fun ByteArray.toString(charset: Charset): String = String(this, charset)
/**
* Returns an array containing the elements of this collection.
*/
[Intrinsic("kotlin.collections.copyToArray")] public fun <reified T> Collection<T>.copyToArray(): Array<T> = [Intrinsic("kotlin.collections.copyToArray")] public fun <reified T> Collection<T>.copyToArray(): Array<T> =
throw UnsupportedOperationException() throw UnsupportedOperationException()
/** Returns the array if it's not null, or an empty array otherwise. */ /** Returns the array if it's not null, or an empty array otherwise. */
public inline fun <reified T> Array<out T>?.orEmpty(): Array<out T> = this ?: array<T>() public inline fun <reified T> Array<out T>?.orEmpty(): Array<out T> = this ?: array<T>()
@@ -17,7 +17,10 @@ public fun <T> Enumeration<T>.iterator(): Iterator<T> = object : Iterator<T> {
public fun <T> Iterator<T>.iterator(): Iterator<T> = this public fun <T> Iterator<T>.iterator(): Iterator<T> = this
/** /**
* Data class representing a value with an index * Data class representing a value from a collection or sequence, along with its index in that collection or sequence.
*
* @property value the underlying value.
* @property index the index of the value in the collection or sequence.
*/ */
public data class IndexedValue<out T>(public val index: Int, public val value: T) public data class IndexedValue<out T>(public val index: Int, public val value: T)
@@ -64,11 +64,14 @@ public fun hashSetOf<T>(vararg values: T): HashSet<T> = values.toCollection(Hash
public fun linkedSetOf<T>(vararg values: T): LinkedHashSet<T> = values.toCollection(LinkedHashSet(values.size())) public fun linkedSetOf<T>(vararg values: T): LinkedHashSet<T> = values.toCollection(LinkedHashSet(values.size()))
/** /**
* Returns an IntRange of the valid indices for this collection. * Returns an [IntRange] of the valid indices for this collection.
*/ */
public val Collection<*>.indices: IntRange public val Collection<*>.indices: IntRange
get() = 0..size() - 1 get() = 0..size() - 1
/**
* Returns an [IntRange] that starts with zero and ends at the value of this number but does not include it.
*/
public val Int.indices: IntRange public val Int.indices: IntRange
get() = 0..this - 1 get() = 0..this - 1
@@ -92,5 +95,12 @@ public fun <T> List<T>?.orEmpty(): List<T> = this ?: emptyList()
/** Returns this Set if it's not null and the empty set otherwise. */ /** Returns this Set if it's not null and the empty set otherwise. */
public fun <T> Set<T>?.orEmpty(): Set<T> = this ?: emptySet() public fun <T> Set<T>?.orEmpty(): Set<T> = this ?: emptySet()
/**
* Returns the size of this iterable if it is known, or `null` otherwise.
*/
public fun <T> Iterable<T>.collectionSizeOrNull(): Int? = if (this is Collection<*>) size() else null public fun <T> Iterable<T>.collectionSizeOrNull(): Int? = if (this is Collection<*>) size() else null
/**
* Returns the size of this iterable if it is known, or the specified [default] value otherwise.
*/
public fun <T> Iterable<T>.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) size() else default public fun <T> Iterable<T>.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) size() else default
@@ -2,12 +2,27 @@ package kotlin
import java.util.* import java.util.*
/**
* A sequence that returns values through its iterator. The values are evaluated lazily, and the sequence
* is potentially infinite.
*
* @param T the type of elements in the sequence.
*/
public trait Stream<out T> { public trait Stream<out T> {
/**
* Returns an iterator that returns the values from the sequence.
*/
public fun iterator(): Iterator<T> public fun iterator(): Iterator<T>
} }
/**
* Creates a stream that returns the specified values.
*/
public fun <T> streamOf(vararg elements: T): Stream<T> = elements.stream() public fun <T> streamOf(vararg elements: T): Stream<T> = elements.stream()
/**
* Creates a stream that returns all values in the specified [progression].
*/
public fun <T> streamOf(progression: Progression<T>): Stream<T> = object : Stream<T> { public fun <T> streamOf(progression: Progression<T>): Stream<T> = object : Stream<T> {
override fun iterator(): Iterator<T> = progression.iterator() override fun iterator(): Iterator<T> = progression.iterator()
} }
@@ -60,6 +75,10 @@ public class FilteringStream<T>(private val stream: Stream<T>,
} }
} }
/**
* A stream which returns the results of applying the given [transformer] function to the values
* in the underlying [stream].
*/
public class TransformingStream<T, R>(private val stream: Stream<T>, private val transformer: (T) -> R) : Stream<R> { public class TransformingStream<T, R>(private val stream: Stream<T>, private val transformer: (T) -> R) : Stream<R> {
override fun iterator(): Iterator<R> = object : Iterator<R> { override fun iterator(): Iterator<R> = object : Iterator<R> {
val iterator = stream.iterator() val iterator = stream.iterator()
@@ -72,6 +91,11 @@ public class TransformingStream<T, R>(private val stream: Stream<T>, private val
} }
} }
/**
* A stream which returns the results of applying the given [transformer] function to the values
* in the underlying [stream], where the transformer function takes the index of the value in the underlying
* stream along with the value itself.
*/
public class TransformingIndexedStream<T, R>(private val stream: Stream<T>, private val transformer: (Int, T) -> R) : Stream<R> { public class TransformingIndexedStream<T, R>(private val stream: Stream<T>, private val transformer: (Int, T) -> R) : Stream<R> {
override fun iterator(): Iterator<R> = object : Iterator<R> { override fun iterator(): Iterator<R> = object : Iterator<R> {
val iterator = stream.iterator() val iterator = stream.iterator()
@@ -103,6 +127,11 @@ public class IndexingStream<T>(private val stream: Stream<T>) : Stream<IndexedVa
} }
} }
/**
* A stream which takes the values from two parallel underlying streams, passes them to the given
* [transform] function and returns the values returned by that function. The stream stops returning
* values as soon as one of the underlying streams stops returning values.
*/
public class MergingStream<T1, T2, V>(private val stream1: Stream<T1>, public class MergingStream<T1, T2, V>(private val stream1: Stream<T1>,
private val stream2: Stream<T2>, private val stream2: Stream<T2>,
private val transform: (T1, T2) -> V private val transform: (T1, T2) -> V
@@ -193,6 +222,10 @@ public class Multistream<T>(private val stream: Stream<Stream<T>>) : Stream<T> {
} }
} }
/**
* A stream that returns at most [count] values from the underlying [stream], and stops returning values
* as soon as that count is reached.
*/
public class TakeStream<T>(private val stream: Stream<T>, public class TakeStream<T>(private val stream: Stream<T>,
private val count: Int private val count: Int
) : Stream<T> { ) : Stream<T> {
@@ -218,6 +251,10 @@ public class TakeStream<T>(private val stream: Stream<T>,
} }
} }
/**
* A stream that returns values from the underlying [stream] while the [predicate] function returns
* `true`, and stops returning values once the function returns `false` for the next element.
*/
public class TakeWhileStream<T>(private val stream: Stream<T>, public class TakeWhileStream<T>(private val stream: Stream<T>,
private val predicate: (T) -> Boolean private val predicate: (T) -> Boolean
) : Stream<T> { ) : Stream<T> {
@@ -382,7 +419,7 @@ public class FunctionStream<T : Any>(private val producer: () -> T?) : Stream<T>
} }
/** /**
* Returns a stream which invokes the function to calculate the next value on each iteration until the function returns *null* * Returns a stream which invokes the function to calculate the next value on each iteration until the function returns `null`.
*/ */
public fun <T : Any> stream(nextFunction: () -> T?): Stream<T> { public fun <T : Any> stream(nextFunction: () -> T?): Stream<T> {
return FunctionStream(nextFunction) return FunctionStream(nextFunction)
@@ -390,7 +427,7 @@ public fun <T : Any> stream(nextFunction: () -> T?): Stream<T> {
/** /**
* Returns a stream which invokes the function to calculate the next value based on the previous one on each iteration * Returns a stream which invokes the function to calculate the next value based on the previous one on each iteration
* until the function returns *null* * until the function returns `null`.
*/ */
public /*inline*/ fun <T : Any> stream(initialValue: T, nextFunction: (T) -> T?): Stream<T> = public /*inline*/ fun <T : Any> stream(initialValue: T, nextFunction: (T) -> T?): Stream<T> =
stream(nextFunction.toGenerator(initialValue)) stream(nextFunction.toGenerator(initialValue))
@@ -54,7 +54,8 @@ public inline fun <T> ReentrantReadWriteLock.write(action: () -> T): T {
} }
/** /**
* Executes the given [action] and await for CountDownLatch * Executes the given [operation] and awaits for CountDownLatch.
*
* @return the return value of the action. * @return the return value of the action.
*/ */
public fun <T> Int.latch(operation: CountDownLatch.() -> T): T { public fun <T> Int.latch(operation: CountDownLatch.() -> T): T {
@@ -2,36 +2,65 @@ package kotlin.concurrent
import java.util.concurrent.* import java.util.concurrent.*
/**
* Returns the current thread.
*/
public val currentThread: Thread public val currentThread: Thread
get() = Thread.currentThread() get() = Thread.currentThread()
/**
* Exposes the name of this thread as a property.
*/
public var Thread.name: String public var Thread.name: String
get() = getName() get() = getName()
set(value) { set(value) {
setName(value) setName(value)
} }
/**
* Exposes the daemon flag of this thread as a property.
* The Java Virtual Machine exits when the only threads running are all daemon threads.
*/
public var Thread.daemon: Boolean public var Thread.daemon: Boolean
get() = isDaemon() get() = isDaemon()
set(value) { set(value) {
setDaemon(value) setDaemon(value)
} }
/**
* Exposes the alive state of this thread as a property.
*/
public val Thread.alive: Boolean public val Thread.alive: Boolean
get() = isAlive() get() = isAlive()
/**
* Exposes the priority of this thread as a property.
*/
public var Thread.priority: Int public var Thread.priority: Int
get() = getPriority() get() = getPriority()
set(value) { set(value) {
setPriority(value) setPriority(value)
} }
/**
* Exposes the context class loader of this thread as a property.
*/
public var Thread.contextClassLoader: ClassLoader? public var Thread.contextClassLoader: ClassLoader?
get() = getContextClassLoader() get() = getContextClassLoader()
set(value) { set(value) {
setContextClassLoader(value) setContextClassLoader(value)
} }
/**
* Creates a thread that runs the specified [block] of code.\
*
* @param start if `true`, the thread is immediately started.
* @param daemon if `true`, the thread is created as a daemon thread. The Java Virtual Machine exits when
* the only threads running are all daemon threads.
* @param contextClassLoader the class loader to use for loading classes and resources in this thread.
* @param name the name of the thread.
* @param priority the priority of the thread.
*/
public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: () -> Unit): Thread { public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: () -> Unit): Thread {
val thread = object : Thread() { val thread = object : Thread() {
public override fun run() { public override fun run() {
@@ -53,15 +82,15 @@ public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLo
/** /**
* Allows you to use the executor as a function to * Allows you to use the executor as a function to
* execute the given block on the [[Executor]]. * execute the given block on the [Executor].
*/ */
public fun Executor.invoke(action: () -> Unit) { public fun Executor.invoke(action: () -> Unit) {
execute(action) execute(action)
} }
/** /**
* Allows you to use the executor as a function to * Allows you to use the executor service as a function to
* execute the given block on the [[Executor]]. * execute the given block on the [ExecutorService].
*/ */
public fun <T> ExecutorService.invoke(action: () -> T): Future<T> { public fun <T> ExecutorService.invoke(action: () -> T): Future<T> {
return submit(action) return submit(action)
@@ -4,66 +4,123 @@ import java.util.Timer
import java.util.TimerTask import java.util.TimerTask
import java.util.Date import java.util.Date
/**
* Schedules an [action] to be executed after the specified [delay] (expressed in milliseconds).
*/
public fun Timer.schedule(delay: Long, action: TimerTask.() -> Unit): TimerTask { public fun Timer.schedule(delay: Long, action: TimerTask.() -> Unit): TimerTask {
val task = timerTask(action) val task = timerTask(action)
schedule(task, delay) schedule(task, delay)
return task return task
} }
/**
* Schedules an [action] to be executed at the specified [time].
*/
public fun Timer.schedule(time: Date, action: TimerTask.() -> Unit): TimerTask { public fun Timer.schedule(time: Date, action: TimerTask.() -> Unit): TimerTask {
val task = timerTask(action) val task = timerTask(action)
schedule(task, time) schedule(task, time)
return task return task
} }
/**
* Schedules an [action] to be executed periodically, starting after the specified [delay] (expressed
* in milliseconds) and with the interval of [period] milliseconds between the end of the previous task
* and the start of the next one.
*/
public fun Timer.schedule(delay: Long, period: Long, action: TimerTask.() -> Unit): TimerTask { public fun Timer.schedule(delay: Long, period: Long, action: TimerTask.() -> Unit): TimerTask {
val task = timerTask(action) val task = timerTask(action)
schedule(task, delay, period) schedule(task, delay, period)
return task return task
} }
/**
* Schedules an [action] to be executed periodically, starting at the specified [time] and with the
* interval of [period] milliseconds between the end of the previous task and the start of the next one.
*/
public fun Timer.schedule(time: Date, period: Long, action: TimerTask.() -> Unit): TimerTask { public fun Timer.schedule(time: Date, period: Long, action: TimerTask.() -> Unit): TimerTask {
val task = timerTask(action) val task = timerTask(action)
schedule(task, time, period) schedule(task, time, period)
return task return task
} }
/**
* Schedules an [action] to be executed periodically, starting after the specified [delay] (expressed
* in milliseconds) and with the interval of [period] milliseconds between the start of the previous task
* and the start of the next one.
*/
public fun Timer.scheduleAtFixedRate(delay: Long, period: Long, action: TimerTask.() -> Unit): TimerTask { public fun Timer.scheduleAtFixedRate(delay: Long, period: Long, action: TimerTask.() -> Unit): TimerTask {
val task = timerTask(action) val task = timerTask(action)
scheduleAtFixedRate(task, delay, period) scheduleAtFixedRate(task, delay, period)
return task return task
} }
/**
* Schedules an [action] to be executed periodically, starting at the specified [time] and with the
* interval of [period] milliseconds between the start of the previous task and the start of the next one.
*/
public fun Timer.scheduleAtFixedRate(time: Date, period: Long, action: TimerTask.() -> Unit): TimerTask { public fun Timer.scheduleAtFixedRate(time: Date, period: Long, action: TimerTask.() -> Unit): TimerTask {
val task = timerTask(action) val task = timerTask(action)
scheduleAtFixedRate(task, time, period) scheduleAtFixedRate(task, time, period)
return task return task
} }
/**
* Creates a timer that executes the specified [action] periodically, starting after the specified [initialDelay]
* (expressed in milliseconds) and with the interval of [period] milliseconds between the end of the previous task
* and the start of the next one.
*
* @param name the name to use for the thread which is running the timer.
* @param daemon if true, the thread is started as a daemon thread (the VM will exit when only daemon threads are running)
*/
public fun timer(name: String? = null, daemon: Boolean = false, initialDelay: Long = 0.toLong(), period: Long, action: TimerTask.() -> Unit): Timer { public fun timer(name: String? = null, daemon: Boolean = false, initialDelay: Long = 0.toLong(), period: Long, action: TimerTask.() -> Unit): Timer {
val timer = if (name == null) Timer(daemon) else Timer(name, daemon) val timer = if (name == null) Timer(daemon) else Timer(name, daemon)
timer.schedule(initialDelay, period, action) timer.schedule(initialDelay, period, action)
return timer return timer
} }
/**
* Creates a timer that executes the specified [action] periodically, starting at the specified [startAt] date
* and with the interval of [period] milliseconds between the end of the previous task and the start of the next one.
*
* @param name the name to use for the thread which is running the timer.
* @param daemon if true, the thread is started as a daemon thread (the VM will exit when only daemon threads are running)
*/
public fun timer(name: String? = null, daemon: Boolean = false, startAt: Date, period: Long, action: TimerTask.() -> Unit): Timer { public fun timer(name: String? = null, daemon: Boolean = false, startAt: Date, period: Long, action: TimerTask.() -> Unit): Timer {
val timer = if (name == null) Timer(daemon) else Timer(name, daemon) val timer = if (name == null) Timer(daemon) else Timer(name, daemon)
timer.schedule(startAt, period, action) timer.schedule(startAt, period, action)
return timer return timer
} }
/**
* Creates a timer that executes the specified [action] periodically, starting after the specified [initialDelay]
* (expressed in milliseconds) and with the interval of [period] milliseconds between the start of the previous task
* and the start of the next one.
*
* @param name the name to use for the thread which is running the timer.
* @param daemon if true, the thread is started as a daemon thread (the VM will exit when only daemon threads are running)
*/
public fun fixedRateTimer(name: String? = null, daemon: Boolean = false, initialDelay: Long = 0.toLong(), period: Long, action: TimerTask.() -> Unit): Timer { public fun fixedRateTimer(name: String? = null, daemon: Boolean = false, initialDelay: Long = 0.toLong(), period: Long, action: TimerTask.() -> Unit): Timer {
val timer = if (name == null) Timer(daemon) else Timer(name, daemon) val timer = if (name == null) Timer(daemon) else Timer(name, daemon)
timer.scheduleAtFixedRate(initialDelay, period, action) timer.scheduleAtFixedRate(initialDelay, period, action)
return timer return timer
} }
/**
* Creates a timer that executes the specified [action] periodically, starting at the specified [startAt] date
* and with the interval of [period] milliseconds between the start of the previous task and the start of the next one.
*
* @param name the name to use for the thread which is running the timer.
* @param daemon if true, the thread is started as a daemon thread (the VM will exit when only daemon threads are running)
*/
public fun fixedRateTimer(name: String? = null, daemon: Boolean = false, startAt: Date, period: Long, action: TimerTask.() -> Unit): Timer { public fun fixedRateTimer(name: String? = null, daemon: Boolean = false, startAt: Date, period: Long, action: TimerTask.() -> Unit): Timer {
val timer = if (name == null) Timer(daemon) else Timer(name, daemon) val timer = if (name == null) Timer(daemon) else Timer(name, daemon)
timer.scheduleAtFixedRate(startAt, period, action) timer.scheduleAtFixedRate(startAt, period, action)
return timer return timer
} }
/**
* Wraps the specified [action] in a `TimerTask`.
*/
public fun timerTask(action: TimerTask.() -> Unit): TimerTask = object : TimerTask() { public fun timerTask(action: TimerTask.() -> Unit): TimerTask = object : TimerTask() {
public override fun run() { public override fun run() {
action() action()
+23 -22
View File
@@ -9,88 +9,88 @@ import java.io.BufferedReader
*/ */
public val defaultBufferSize: Int = 64 * 1024 public val defaultBufferSize: Int = 64 * 1024
/** Prints the given message to [System.out] */ /** Prints the given message to the standard output stream. */
public fun print(message: Any?) { public fun print(message: Any?) {
System.out.print(message) System.out.print(message)
} }
/** Prints the given message to [System.out] */ /** Prints the given message to the standard output stream. */
public fun print(message: Int) { public fun print(message: Int) {
System.out.print(message) System.out.print(message)
} }
/** Prints the given message to [System.out] */ /** Prints the given message to the standard output stream. */
public fun print(message: Long) { public fun print(message: Long) {
System.out.print(message) System.out.print(message)
} }
/** Prints the given message to [System.out] */ /** Prints the given message to the standard output stream. */
public fun print(message: Byte) { public fun print(message: Byte) {
System.out.print(message) System.out.print(message)
} }
/** Prints the given message to [System.out] */ /** Prints the given message to the standard output stream. */
public fun print(message: Short) { public fun print(message: Short) {
System.out.print(message) System.out.print(message)
} }
/** Prints the given message to [System.out] */ /** Prints the given message to the standard output stream. */
public fun print(message: Char) { public fun print(message: Char) {
System.out.print(message) System.out.print(message)
} }
/** Prints the given message to [System.out] */ /** Prints the given message to the standard output stream. */
public fun print(message: Boolean) { public fun print(message: Boolean) {
System.out.print(message) System.out.print(message)
} }
/** Prints the given message to [System.out] */ /** Prints the given message to the standard output stream. */
public fun print(message: Float) { public fun print(message: Float) {
System.out.print(message) System.out.print(message)
} }
/** Prints the given message to [System.out] */ /** Prints the given message to the standard output stream. */
public fun print(message: Double) { public fun print(message: Double) {
System.out.print(message) System.out.print(message)
} }
/** Prints the given message to [System.out] */ /** Prints the given message to the standard output stream. */
public fun print(message: CharArray) { public fun print(message: CharArray) {
System.out.print(message) System.out.print(message)
} }
/** Prints the given message and newline to [System.out] */ /** Prints the given message and newline to the standard output stream. */
public fun println(message: Any?) { public fun println(message: Any?) {
System.out.println(message) System.out.println(message)
} }
/** Prints the given message and newline to [System.out] */ /** Prints the given message and newline to the standard output stream. */
public fun println(message: Int) { public fun println(message: Int) {
System.out.println(message) System.out.println(message)
} }
/** Prints the given message and newline to [System.out] */ /** Prints the given message and newline to the standard output stream. */
public fun println(message: Long) { public fun println(message: Long) {
System.out.println(message) System.out.println(message)
} }
/** Prints the given message and newline to [System.out] */ /** Prints the given message and newline to the standard output stream. */
public fun println(message: Byte) { public fun println(message: Byte) {
System.out.println(message) System.out.println(message)
} }
/** Prints the given message and newline to [System.out] */ /** Prints the given message and newline to the standard output stream. */
public fun println(message: Short) { public fun println(message: Short) {
System.out.println(message) System.out.println(message)
} }
/** Prints the given message and newline to [System.out] */ /** Prints the given message and newline to the standard output stream. */
public fun println(message: Char) { public fun println(message: Char) {
System.out.println(message) System.out.println(message)
} }
/** Prints the given message and newline to [System.out] */ /** Prints the given message and newline to the standard output stream. */
public fun println(message: Boolean) { public fun println(message: Boolean) {
System.out.println(message) System.out.println(message)
} }
/** Prints the given message and newline to [System.out] */ /** Prints the given message and newline to the standard output stream. */
public fun println(message: Float) { public fun println(message: Float) {
System.out.println(message) System.out.println(message)
} }
/** Prints the given message and newline to [System.out] */ /** Prints the given message and newline to the standard output stream. */
public fun println(message: Double) { public fun println(message: Double) {
System.out.println(message) System.out.println(message)
} }
/** Prints the given message and newline to [System.out] */ /** Prints the given message and newline to the standard output stream. */
public fun println(message: CharArray) { public fun println(message: CharArray) {
System.out.println(message) System.out.println(message)
} }
/** Prints a newline to [System.out] */ /** Prints a newline to the standard output stream. */
public fun println() { public fun println() {
System.out.println() System.out.println()
} }
@@ -137,7 +137,8 @@ private val stdin: BufferedReader = BufferedReader(InputStreamReader(object : In
})) }))
/** /**
* Reads a line of input from [System.in] * Reads a line of input from the standard input stream.
*
* @return the line read or null if the input stream is redirected to a file and the end of file has been reached. * @return the line read or null if the input stream is redirected to a file and the end of file has been reached.
*/ */
public fun readLine(): String? = stdin.readLine() public fun readLine(): String? = stdin.readLine()
@@ -15,20 +15,56 @@
*/ */
package kotlin.jvm package kotlin.jvm
/**
* A constant holding the minimum value an `Int` can have, -2^31.
*/
public val Int.Default.MIN_VALUE: Int get() = java.lang.Integer.MIN_VALUE public val Int.Default.MIN_VALUE: Int get() = java.lang.Integer.MIN_VALUE
/**
* A constant holding the maximum value an `Int` can have, 2^31-1.
*/
public val Int.Default.MAX_VALUE: Int get() = java.lang.Integer.MAX_VALUE public val Int.Default.MAX_VALUE: Int get() = java.lang.Integer.MAX_VALUE
/**
* A constant holding the smallest positive nonzero value of type `Double`, 2^-1074.
*/
public val Double.Default.MIN_VALUE: Double get() = java.lang.Double.MIN_VALUE public val Double.Default.MIN_VALUE: Double get() = java.lang.Double.MIN_VALUE
/**
* A constant holding the largest positive finite value of type `Double`, (2-2^-52)*2^1023.
*/
public val Double.Default.MAX_VALUE: Double get() = java.lang.Double.MAX_VALUE public val Double.Default.MAX_VALUE: Double get() = java.lang.Double.MAX_VALUE
/**
* A constant holding the smallest positive nonzero value of type `Float`, 2^-149.
*/
public val Float.Default.MIN_VALUE: Float get() = java.lang.Float.MIN_VALUE public val Float.Default.MIN_VALUE: Float get() = java.lang.Float.MIN_VALUE
/**
* * A constant holding the largest positive finite value of type `Float`, (2-2^-23)*2^127.
*/
public val Float.Default.MAX_VALUE: Float get() = java.lang.Float.MAX_VALUE public val Float.Default.MAX_VALUE: Float get() = java.lang.Float.MAX_VALUE
/**
* A constant holding the minimum value a `Long` can have, -2^63.
*/
public val Long.Default.MIN_VALUE: Long get() = java.lang.Long.MIN_VALUE public val Long.Default.MIN_VALUE: Long get() = java.lang.Long.MIN_VALUE
/**
* A constant holding the maximum value a `Long` can have, 2^63-1.
*/
public val Long.Default.MAX_VALUE: Long get() = java.lang.Long.MAX_VALUE public val Long.Default.MAX_VALUE: Long get() = java.lang.Long.MAX_VALUE
/**
* A constant holding the minimum value a `Short` can have, -2^15.
*/
public val Short.Default.MIN_VALUE: Short get() = java.lang.Short.MIN_VALUE public val Short.Default.MIN_VALUE: Short get() = java.lang.Short.MIN_VALUE
/**
* A constant holding the maximum value a `Short` can have, 2^15-1.
*/
public val Short.Default.MAX_VALUE: Short get() = java.lang.Short.MAX_VALUE public val Short.Default.MAX_VALUE: Short get() = java.lang.Short.MAX_VALUE
/**
* A constant holding the minimum value a `Byte` can have, -128.
*/
public val Byte.Default.MIN_VALUE: Byte get() = java.lang.Byte.MIN_VALUE public val Byte.Default.MIN_VALUE: Byte get() = java.lang.Byte.MIN_VALUE
/**
* A constant holding the maximum value a `Byte` can have, 127.
*/
public val Byte.Default.MAX_VALUE: Byte get() = java.lang.Byte.MAX_VALUE public val Byte.Default.MAX_VALUE: Byte get() = java.lang.Byte.MAX_VALUE
@@ -21,6 +21,7 @@ package kotlin.platform
* which is generated from this element. * which is generated from this element.
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/java-interop.html#handling-signature-clashes-with-platformname) * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/java-interop.html#handling-signature-clashes-with-platformname)
* for more information. * for more information.
* @property name the name of the element.
*/ */
public annotation class platformName(public val name: String) public annotation class platformName(public val name: String)
+32 -1
View File
@@ -89,18 +89,49 @@ public fun fails(block: () -> Unit): Throwable? {
} }
/** /**
* A plugin for performing assertions which can reuse JUnit or TestNG * Abstracts the logic for performing assertions. Specific implementations of [Asserter] can use JUnit
* or TestNG assertion facilities.
*/ */
public trait Asserter { public trait Asserter {
/**
* Asserts that the specified value is true.
*
* @param message the message to report if the assertion fails.
*/
public fun assertTrue(message: String, actual: Boolean): Unit public fun assertTrue(message: String, actual: Boolean): Unit
/**
* Asserts that the specified values are equal.
*
* @param message the message to report if the assertion fails.
*/
public fun assertEquals(message: String, expected: Any?, actual: Any?): Unit public fun assertEquals(message: String, expected: Any?, actual: Any?): Unit
/**
* Asserts that the specified values are not equal.
*
* @param message the message to report if the assertion fails.
*/
public fun assertNotEquals(message: String, illegal: Any?, actual: Any?): Unit public fun assertNotEquals(message: String, illegal: Any?, actual: Any?): Unit
/**
* Asserts that the specified value is not null.
*
* @param message the message to report if the assertion fails.
*/
public fun assertNotNull(message: String, actual: Any?): Unit public fun assertNotNull(message: String, actual: Any?): Unit
/**
* Asserts that the specified value is null.
*
* @param message the message to report if the assertion fails.
*/
public fun assertNull(message: String, actual: Any?): Unit public fun assertNull(message: String, actual: Any?): Unit
/**
* Fails the current test with the specified message.
*
* @param message the message to report.
*/
public fun fail(message: String): Unit public fun fail(message: String): Unit
} }
+5 -1
View File
@@ -26,6 +26,10 @@ public inline fun todo(block: ()-> Any) {
private var _asserter: Asserter? = null private var _asserter: Asserter? = null
/**
* The active implementation of [Asserter]. An implementation of [Asserter] can be provided
* using the [Java service loader](http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html) mechanism.
*/
public var asserter: Asserter public var asserter: Asserter
get() { get() {
if (_asserter == null) { if (_asserter == null) {
@@ -51,7 +55,7 @@ public var asserter: Asserter
/** /**
* Default implementation to avoid dependency on JUnit or TestNG * Default [Asserter] implementation to avoid dependency on JUnit or TestNG.
*/ */
private class DefaultAsserter() : Asserter { private class DefaultAsserter() : Asserter {
+27 -5
View File
@@ -16,37 +16,59 @@
package kotlin package kotlin
/**
* Returns `true` if this character (Unicode code point) is defined in Unicode.
*/
public fun Char.isDefined(): Boolean = Character.isDefined(this) public fun Char.isDefined(): Boolean = Character.isDefined(this)
/**
* Returns `true` if this character (Unicode code point) is a digit.
*/
public fun Char.isDigit(): Boolean = Character.isDigit(this) public fun Char.isDigit(): Boolean = Character.isDigit(this)
/**
* Returns `true` if this character is a Unicode high-surrogate code unit (also known as leading-surrogate code unit).
*/
public fun Char.isHighSurrogate(): Boolean = Character.isHighSurrogate(this) public fun Char.isHighSurrogate(): Boolean = Character.isHighSurrogate(this)
/**
* Returns `true` if this character (Unicode code point) should be regarded as an ignorable
* character in a Java identifier or a Unicode identifier.
*/
public fun Char.isIdentifierIgnorable(): Boolean = Character.isIdentifierIgnorable(this) public fun Char.isIdentifierIgnorable(): Boolean = Character.isIdentifierIgnorable(this)
/**
* Returns `true` if this character is an ISO control character.
*/
public fun Char.isISOControl(): Boolean = Character.isISOControl(this) public fun Char.isISOControl(): Boolean = Character.isISOControl(this)
/**
* Returns `true` if this character (Unicode code point) may be part of a Java identifier as other than the first character.
*/
public fun Char.isJavaIdentifierPart(): Boolean = Character.isJavaIdentifierPart(this) public fun Char.isJavaIdentifierPart(): Boolean = Character.isJavaIdentifierPart(this)
/**
* Returns `true` if this character is permissible as the first character in a Java identifier.
*/
public fun Char.isJavaIdentifierStart(): Boolean = Character.isJavaIdentifierStart(this) public fun Char.isJavaIdentifierStart(): Boolean = Character.isJavaIdentifierStart(this)
deprecated("Please use Char.isJavaIdentifierStart() instead")
public fun Char.isJavaLetter(): Boolean = Character.isJavaLetter(this) public fun Char.isJavaLetter(): Boolean = Character.isJavaLetter(this)
deprecated("Please use Char.isJavaIdentifierPart() instead")
public fun Char.isJavaLetterOrDigit(): Boolean = Character.isJavaLetterOrDigit(this) public fun Char.isJavaLetterOrDigit(): Boolean = Character.isJavaLetterOrDigit(this)
/** /**
* Returns true if the character is whitespace * Returns `true` if the character is whitespace.
*
* @includeFunctionBody ../../test/text/StringTest.kt count
*/ */
public fun Char.isWhitespace(): Boolean = Character.isWhitespace(this) public fun Char.isWhitespace(): Boolean = Character.isWhitespace(this)
/** /**
* Returns true if this character is upper case * Returns `true` if this character is upper case.
*/ */
public fun Char.isUpperCase(): Boolean = Character.isUpperCase(this) public fun Char.isUpperCase(): Boolean = Character.isUpperCase(this)
/** /**
* Returns true if this character is lower case * Returns `true` if this character is lower case.
*/ */
public fun Char.isLowerCase(): Boolean = Character.isLowerCase(this) public fun Char.isLowerCase(): Boolean = Character.isLowerCase(this)
+245 -2
View File
@@ -7,127 +7,363 @@ import java.util.regex.MatchResult
import java.util.regex.Pattern import java.util.regex.Pattern
import java.nio.charset.Charset import java.nio.charset.Charset
/**
* Returns the index within this string of the last occurrence of the specified substring.
*/
public fun String.lastIndexOf(str: String): Int = (this as java.lang.String).lastIndexOf(str) public fun String.lastIndexOf(str: String): Int = (this as java.lang.String).lastIndexOf(str)
/**
* Returns the index within this string of the last occurrence of the specified character.
*/
public fun String.lastIndexOf(ch: Char): Int = (this as java.lang.String).lastIndexOf(ch.toString()) public fun String.lastIndexOf(ch: Char): Int = (this as java.lang.String).lastIndexOf(ch.toString())
/**
* Compares this string to another string, ignoring case considerations.
*/
public fun String.equalsIgnoreCase(anotherString: String): Boolean = (this as java.lang.String).equalsIgnoreCase(anotherString) public fun String.equalsIgnoreCase(anotherString: String): Boolean = (this as java.lang.String).equalsIgnoreCase(anotherString)
/**
* Returns the hash code of this string.
*/
public fun String.hashCode(): Int = (this as java.lang.String).hashCode() public fun String.hashCode(): Int = (this as java.lang.String).hashCode()
/**
* Returns the index within this string of the first occurrence of the specified substring.
*/
public fun String.indexOf(str: String): Int = (this as java.lang.String).indexOf(str) public fun String.indexOf(str: String): Int = (this as java.lang.String).indexOf(str)
/**
* Returns the index within this string of the first occurrence of the specified substring, starting from the specified offset.
*/
public fun String.indexOf(str: String, fromIndex: Int): Int = (this as java.lang.String).indexOf(str, fromIndex) public fun String.indexOf(str: String, fromIndex: Int): Int = (this as java.lang.String).indexOf(str, fromIndex)
/**
* Returns a copy of this string with all occurrences of [oldChar] replaced with [newChar].
*/
public fun String.replace(oldChar: Char, newChar: Char): String = (this as java.lang.String).replace(oldChar, newChar) public fun String.replace(oldChar: Char, newChar: Char): String = (this as java.lang.String).replace(oldChar, newChar)
/**
* Returns a new string obtained by replacing each substring of this string that matches the given regular expression
* with the given [replacement].
*/
public fun String.replaceAll(regex: String, replacement: String): String = (this as java.lang.String).replaceAll(regex, replacement) public fun String.replaceAll(regex: String, replacement: String): String = (this as java.lang.String).replaceAll(regex, replacement)
/**
* Returns a copy of this string with leading and trailing whitespace trimmed.
*/
public fun String.trim(): String = (this as java.lang.String).trim() public fun String.trim(): String = (this as java.lang.String).trim()
/**
* Returns a copy of this string converted to upper case using the rules of the default locale.
*/
public fun String.toUpperCase(): String = (this as java.lang.String).toUpperCase() public fun String.toUpperCase(): String = (this as java.lang.String).toUpperCase()
/**
* Returns a copy of this string converted to lower case using the rules of the default locale.
*/
public fun String.toLowerCase(): String = (this as java.lang.String).toLowerCase() public fun String.toLowerCase(): String = (this as java.lang.String).toLowerCase()
/**
* Returns a new character array containing the characters from this string.
*/
public fun String.toCharArray(): CharArray = (this as java.lang.String).toCharArray() public fun String.toCharArray(): CharArray = (this as java.lang.String).toCharArray()
/**
* Uses this string as a format string and returns a string obtained by substituting the specified arguments,
* using the default locale.
*/
public fun String.format(vararg args: Any?): String = java.lang.String.format(this, *args) public fun String.format(vararg args: Any?): String = java.lang.String.format(this, *args)
/**
* Uses this string as a format string and returns a string obtained by substituting the specified arguments, using
* the specified locale.
*/
public fun String.format(locale: Locale, vararg args : Any?) : String = java.lang.String.format(locale, this, *args) public fun String.format(locale: Locale, vararg args : Any?) : String = java.lang.String.format(locale, this, *args)
/**
* Splits this string around matches of the given regular expression.
*/
public fun String.split(regex: String): Array<String> = (this as java.lang.String).split(regex) public fun String.split(regex: String): Array<String> = (this as java.lang.String).split(regex)
/**
* Splits this string around occurrences of the specified character.
*/
public fun String.split(ch: Char): Array<String> = (this as java.lang.String).split(java.util.regex.Pattern.quote(ch.toString())) public fun String.split(ch: Char): Array<String> = (this as java.lang.String).split(java.util.regex.Pattern.quote(ch.toString()))
/**
* Returns a substring of this string starting with the specified index.
*/
public fun String.substring(beginIndex: Int): String = (this as java.lang.String).substring(beginIndex) public fun String.substring(beginIndex: Int): String = (this as java.lang.String).substring(beginIndex)
/**
* Returns the substring of this string starting and ending at the specified indices.
*/
public fun String.substring(beginIndex: Int, endIndex: Int): String = (this as java.lang.String).substring(beginIndex, endIndex) public fun String.substring(beginIndex: Int, endIndex: Int): String = (this as java.lang.String).substring(beginIndex, endIndex)
/**
* Returns `true` if this string starts with the specified prefix.
*/
public fun String.startsWith(prefix: String): Boolean = (this as java.lang.String).startsWith(prefix) public fun String.startsWith(prefix: String): Boolean = (this as java.lang.String).startsWith(prefix)
/**
* Returns `true` if a subsring of this string starting at the specified offset starts with the specified prefix.
*/
public fun String.startsWith(prefix: String, toffset: Int): Boolean = (this as java.lang.String).startsWith(prefix, toffset) public fun String.startsWith(prefix: String, toffset: Int): Boolean = (this as java.lang.String).startsWith(prefix, toffset)
/**
* Returns `true` if this string starts with the specified character.
*/
public fun String.startsWith(ch: Char): Boolean = (this as java.lang.String).startsWith(ch.toString()) public fun String.startsWith(ch: Char): Boolean = (this as java.lang.String).startsWith(ch.toString())
/**
* Returns `true` if this string contains the specified sequence of characters as a substring.
*/
public fun String.contains(seq: CharSequence): Boolean = (this as java.lang.String).contains(seq) public fun String.contains(seq: CharSequence): Boolean = (this as java.lang.String).contains(seq)
/**
* Returns `true` if this string ends with the specified suffix.
*/
public fun String.endsWith(suffix: String): Boolean = (this as java.lang.String).endsWith(suffix) public fun String.endsWith(suffix: String): Boolean = (this as java.lang.String).endsWith(suffix)
/**
* Returns `true` if this string ends with the specified character.
*/
public fun String.endsWith(ch: Char): Boolean = (this as java.lang.String).endsWith(ch.toString()) public fun String.endsWith(ch: Char): Boolean = (this as java.lang.String).endsWith(ch.toString())
// "constructors" for String // "constructors" for String
/**
* Converts the data from a portion of the specified array of bytes to characters using the specified character set
* and returns the conversion result as a string.
*
* @param bytes the source array for the conversion.
* @param offset the offset in the array of the data to be converted.
* @param length the number of bytes to be converted.
* @param charsetName the name of the character set to use.
*/
public fun String(bytes: ByteArray, offset: Int, length: Int, charsetName: String): String = java.lang.String(bytes, offset, length, charsetName) as String public fun String(bytes: ByteArray, offset: Int, length: Int, charsetName: String): String = java.lang.String(bytes, offset, length, charsetName) as String
/**
* Converts the data from a portion of the specified array of bytes to characters using the specified character set
* and returns the conversion result as a string.
*
* @param bytes the source array for the conversion.
* @param offset the offset in the array of the data to be converted.
* @param length the number of bytes to be converted.
* @param charset the character set to use.
*/
public fun String(bytes: ByteArray, offset: Int, length: Int, charset: Charset): String = java.lang.String(bytes, offset, length, charset) as String public fun String(bytes: ByteArray, offset: Int, length: Int, charset: Charset): String = java.lang.String(bytes, offset, length, charset) as String
/**
* Converts the data from the specified array of bytes to characters using the specified character set
* and returns the conversion result as a string.
*/
public fun String(bytes: ByteArray, charsetName: String): String = java.lang.String(bytes, charsetName) as String public fun String(bytes: ByteArray, charsetName: String): String = java.lang.String(bytes, charsetName) as String
/**
* Converts the data from the specified array of bytes to characters using the specified character set
* and returns the conversion result as a string.
*/
public fun String(bytes: ByteArray, charset: Charset): String = java.lang.String(bytes, charset) as String public fun String(bytes: ByteArray, charset: Charset): String = java.lang.String(bytes, charset) as String
public fun String(bytes: ByteArray, i: Int, i1: Int): String = java.lang.String(bytes, i, i1, Charsets.UTF_8) as String /**
* Converts the data from a portion of the specified array of bytes to characters using the UTF-8 character set
* and returns the conversion result as a string.
*
* @param bytes the source array for the conversion.
* @param offset the offset in the array of the data to be converted.
* @param length the number of bytes to be converted.
*/
public fun String(bytes: ByteArray, offset: Int, length: Int): String = java.lang.String(bytes, offset, length, Charsets.UTF_8) as String
/**
* Converts the data from the specified array of bytes to characters using the UTF-8 character set
* and returns the conversion result as a string.
*/
public fun String(bytes: ByteArray): String = java.lang.String(bytes, Charsets.UTF_8) as String public fun String(bytes: ByteArray): String = java.lang.String(bytes, Charsets.UTF_8) as String
/**
* Converts the characters in the specified array to a string.
*/
public fun String(chars: CharArray): String = java.lang.String(chars) as String public fun String(chars: CharArray): String = java.lang.String(chars) as String
/**
* Converts the contents of the specified StringBuffer to a string.
*/
public fun String(stringBuffer: java.lang.StringBuffer): String = java.lang.String(stringBuffer) as String public fun String(stringBuffer: java.lang.StringBuffer): String = java.lang.String(stringBuffer) as String
/**
* Converts the contents of the specified StringBuilder to a string.
*/
public fun String(stringBuilder: java.lang.StringBuilder): String = java.lang.String(stringBuilder) as String public fun String(stringBuilder: java.lang.StringBuilder): String = java.lang.String(stringBuilder) as String
/**
* Replaces the first substring of this string that matches the given regular expression with the given replacement.
*/
public fun String.replaceFirst(regex: String, replacement: String): String = (this as java.lang.String).replaceFirst(regex, replacement) public fun String.replaceFirst(regex: String, replacement: String): String = (this as java.lang.String).replaceFirst(regex, replacement)
/**
* Splits this string into at most [limit] chunks around matches of the given regular expression.
*/
public fun String.split(regex: String, limit: Int): Array<String> = (this as java.lang.String).split(regex, limit) public fun String.split(regex: String, limit: Int): Array<String> = (this as java.lang.String).split(regex, limit)
/**
* Returns the character (Unicode code point) at the specified index.
*/
public fun String.codePointAt(index: Int): Int = (this as java.lang.String).codePointAt(index) public fun String.codePointAt(index: Int): Int = (this as java.lang.String).codePointAt(index)
/**
* Returns the character (Unicode code point) before the specified index.
*/
public fun String.codePointBefore(index: Int): Int = (this as java.lang.String).codePointBefore(index) public fun String.codePointBefore(index: Int): Int = (this as java.lang.String).codePointBefore(index)
/**
* Returns the number of Unicode code points in the specified text range of this String.
*/
public fun String.codePointCount(beginIndex: Int, endIndex: Int): Int = (this as java.lang.String).codePointCount(beginIndex, endIndex) public fun String.codePointCount(beginIndex: Int, endIndex: Int): Int = (this as java.lang.String).codePointCount(beginIndex, endIndex)
/**
* Compares two strings lexicographically, ignoring case differences.
*/
public fun String.compareToIgnoreCase(str: String): Int = (this as java.lang.String).compareToIgnoreCase(str) public fun String.compareToIgnoreCase(str: String): Int = (this as java.lang.String).compareToIgnoreCase(str)
/**
* Returns a new string obtained by concatenating this string and the specified string.
*/
public fun String.concat(str: String): String = (this as java.lang.String).concat(str) public fun String.concat(str: String): String = (this as java.lang.String).concat(str)
/**
* Returns `true` if this string is equal to the contents of the specified CharSequence.
*/
public fun String.contentEquals(cs: CharSequence): Boolean = (this as java.lang.String).contentEquals(cs) public fun String.contentEquals(cs: CharSequence): Boolean = (this as java.lang.String).contentEquals(cs)
/**
* Returns `true` if this string is equal to the contents of the specified StringBuffer.
*/
public fun String.contentEquals(sb: StringBuffer): Boolean = (this as java.lang.String).contentEquals(sb) public fun String.contentEquals(sb: StringBuffer): Boolean = (this as java.lang.String).contentEquals(sb)
/**
* Copies the characters from a substring of this string into the specified character array.
* @param srcBegin the start offset (inclusive) of the substring to copy.
* @param srcEnd the end offset (exclusive) of the substring to copy.
* @param dst the array to copy to.
* @param dstBegin the position in the array to copy to.
*/
public fun String.getChars(srcBegin: Int, srcEnd: Int, dst: CharArray, dstBegin: Int): Unit = (this as java.lang.String).getChars(srcBegin, srcEnd, dst, dstBegin) public fun String.getChars(srcBegin: Int, srcEnd: Int, dst: CharArray, dstBegin: Int): Unit = (this as java.lang.String).getChars(srcBegin, srcEnd, dst, dstBegin)
/**
* Returns the index within this string of the first occurrence of the specified character.
*/
public fun String.indexOf(ch: Char): Int = (this as java.lang.String).indexOf(ch.toString()) public fun String.indexOf(ch: Char): Int = (this as java.lang.String).indexOf(ch.toString())
/**
* Returns the index within this string of the first occurrence of the specified character, starting from the specified offset.
*/
public fun String.indexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).indexOf(ch.toString(), fromIndex) public fun String.indexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).indexOf(ch.toString(), fromIndex)
/**
* Returns a canonical representation for this string object.
*/
public fun String.intern(): String = (this as java.lang.String).intern() public fun String.intern(): String = (this as java.lang.String).intern()
/**
* Returns `true` if this string is empty (contains no characters).
*/
public fun String.isEmpty(): Boolean = (this as java.lang.String).isEmpty() public fun String.isEmpty(): Boolean = (this as java.lang.String).isEmpty()
/**
* Returns the index within this string of the last occurrence of the specified character.
*/
public fun String.lastIndexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).lastIndexOf(ch.toString(), fromIndex) public fun String.lastIndexOf(ch: Char, fromIndex: Int): Int = (this as java.lang.String).lastIndexOf(ch.toString(), fromIndex)
/**
* Returns the index within this string of the last occurrence of the specified character, starting from the specified offset.
*/
public fun String.lastIndexOf(str: String, fromIndex: Int): Int = (this as java.lang.String).lastIndexOf(str, fromIndex) public fun String.lastIndexOf(str: String, fromIndex: Int): Int = (this as java.lang.String).lastIndexOf(str, fromIndex)
/**
* Returns `true` if this string matches the given regular expression.
*/
public fun String.matches(regex: String): Boolean = (this as java.lang.String).matches(regex) public fun String.matches(regex: String): Boolean = (this as java.lang.String).matches(regex)
/**
* Returns the index within this string that is offset from the given [index] by [codePointOffset] code points.
*/
public fun String.offsetByCodePoints(index: Int, codePointOffset: Int): Int = (this as java.lang.String).offsetByCodePoints(index, codePointOffset) public fun String.offsetByCodePoints(index: Int, codePointOffset: Int): Int = (this as java.lang.String).offsetByCodePoints(index, codePointOffset)
/**
* Returns `true` if the specified range in this string is equal to the specified range in another string.
* @param ignoreCase if `true`, character case is ignored when comparing.
* @param toffset the start offset in this string of the substring to compare.
* @param other the string against a substring of which the comparison is performed.
* @param ooffset the start offset in the other string of the substring to compare.
* @param len the length of the substring to compare.
*/
public fun String.regionMatches(ignoreCase: Boolean, toffset: Int, other: String, ooffset: Int, len: Int): Boolean = (this as java.lang.String).regionMatches(ignoreCase, toffset, other, ooffset, len) public fun String.regionMatches(ignoreCase: Boolean, toffset: Int, other: String, ooffset: Int, len: Int): Boolean = (this as java.lang.String).regionMatches(ignoreCase, toffset, other, ooffset, len)
/**
* Returns `true` if the specified range in this string is equal to the specified range in another string.
* @param toffset the start offset in this string of the substring to compare.
* @param other the string against a substring of which the comparison is performed.
* @param ooffset the start offset in the other string of the substring to compare.
* @param len the length of the substring to compare.
*/
public fun String.regionMatches(toffset: Int, other: String, ooffset: Int, len: Int): Boolean = (this as java.lang.String).regionMatches(toffset, other, ooffset, len) public fun String.regionMatches(toffset: Int, other: String, ooffset: Int, len: Int): Boolean = (this as java.lang.String).regionMatches(toffset, other, ooffset, len)
/**
* Returns a new string obtained by replacing all occurrences of the [target] substring in this string
* with the specified [replacement] string.
*/
public fun String.replace(target: CharSequence, replacement: CharSequence): String = (this as java.lang.String).replace(target, replacement) public fun String.replace(target: CharSequence, replacement: CharSequence): String = (this as java.lang.String).replace(target, replacement)
/**
* Returns a copy of this string converted to lower case using the rules of the specified locale.
*/
public fun String.toLowerCase(locale: java.util.Locale): String = (this as java.lang.String).toLowerCase(locale) public fun String.toLowerCase(locale: java.util.Locale): String = (this as java.lang.String).toLowerCase(locale)
/**
* Returns a copy of this string converted to upper case using the rules of the specified locale.
*/
public fun String.toUpperCase(locale: java.util.Locale): String = (this as java.lang.String).toUpperCase(locale) public fun String.toUpperCase(locale: java.util.Locale): String = (this as java.lang.String).toUpperCase(locale)
/**
* Returns `true` if the contents of this string is equal to the word "true", ignoring case, and `false` otherwise.
*/
public fun String.toBoolean(): Boolean = java.lang.Boolean.parseBoolean(this) public fun String.toBoolean(): Boolean = java.lang.Boolean.parseBoolean(this)
/**
* Parses the string as a [Short] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public fun String.toShort(): Short = java.lang.Short.parseShort(this) public fun String.toShort(): Short = java.lang.Short.parseShort(this)
/**
* Parses the string as an [Int] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public fun String.toInt(): Int = java.lang.Integer.parseInt(this) public fun String.toInt(): Int = java.lang.Integer.parseInt(this)
/**
* Parses the string as a [Long] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public fun String.toLong(): Long = java.lang.Long.parseLong(this) public fun String.toLong(): Long = java.lang.Long.parseLong(this)
/**
* Parses the string as a [Float] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public fun String.toFloat(): Float = java.lang.Float.parseFloat(this) public fun String.toFloat(): Float = java.lang.Float.parseFloat(this)
/**
* Parses the string as a [Double] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public fun String.toDouble(): Double = java.lang.Double.parseDouble(this) public fun String.toDouble(): Double = java.lang.Double.parseDouble(this)
/**
* Returns the list of all characters in this string.
*/
public fun String.toCharList(): List<Char> = toCharArray().toList() public fun String.toCharList(): List<Char> = toCharArray().toList()
/** /**
@@ -138,7 +374,14 @@ public fun String.toCharList(): List<Char> = toCharArray().toList()
*/ */
public fun CharSequence.get(start: Int, end: Int): CharSequence = subSequence(start, end) public fun CharSequence.get(start: Int, end: Int): CharSequence = subSequence(start, end)
/**
* Encodes the contents of this string using the specified character set and returns the resulting byte array.
*/
public fun String.toByteArray(charset: String): ByteArray = (this as java.lang.String).getBytes(charset) public fun String.toByteArray(charset: String): ByteArray = (this as java.lang.String).getBytes(charset)
/**
* Encodes the contents of this string using the specified character set and returns the resulting byte array.
*/
public fun String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray = (this as java.lang.String).getBytes(charset) public fun String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray = (this as java.lang.String).getBytes(charset)
deprecated("Use toByteArray() instead to emphasize copy behaviour") deprecated("Use toByteArray() instead to emphasize copy behaviour")
@@ -151,7 +394,7 @@ deprecated("Use toByteArray(charset) instead to emphasize copy behaviour")
public fun String.getBytes(charset: String): ByteArray = (this as java.lang.String).getBytes(charset) public fun String.getBytes(charset: String): ByteArray = (this as java.lang.String).getBytes(charset)
/** /**
* Returns a subsequence specified by given [range]. * Returns a subsequence of this sequence specified by given [range].
*/ */
public fun CharSequence.slice(range: IntRange): CharSequence { public fun CharSequence.slice(range: IntRange): CharSequence {
return subSequence(range.start, range.end + 1) // inclusive return subSequence(range.start, range.end + 1) // inclusive
+39 -1
View File
@@ -4,42 +4,80 @@ package kotlin
* Defines names for Unicode symbols used in proper Typography * Defines names for Unicode symbols used in proper Typography
*/ */
public object Typography { public object Typography {
/** The character &#x22; */
public val quote: Char = '\u0022' public val quote: Char = '\u0022'
/** The character &#x26; */
public val amp: Char = '\u0026' public val amp: Char = '\u0026'
/** The character &#x3C; */
public val less: Char = '\u003C' public val less: Char = '\u003C'
/** The character &#x3E; */
public val greater: Char = '\u003E' public val greater: Char = '\u003E'
/** The non-breaking space character */
public val nbsp: Char = '\u00A0' public val nbsp: Char = '\u00A0'
/** The character &#xD7; */
public val times: Char = '\u00D7' public val times: Char = '\u00D7'
/** The character &#xA2; */
public val cent: Char = '\u00A2' public val cent: Char = '\u00A2'
/** The character &#xA3; */
public val pound: Char = '\u00A3' public val pound: Char = '\u00A3'
/** The character &#xA7; */
public val section: Char = '\u00A7' public val section: Char = '\u00A7'
/** The character &#xA9; */
public val copyright: Char = '\u00A9' public val copyright: Char = '\u00A9'
/** The character &#xAB; */
public val leftGuillemete: Char = '\u00AB' public val leftGuillemete: Char = '\u00AB'
/** The character &#xBB; */
public val rightGuillemete: Char = '\u00BB' public val rightGuillemete: Char = '\u00BB'
/** The character &#xAE; */
public val registered: Char = '\u00AE' public val registered: Char = '\u00AE'
/** The character &#xB0; */
public val degree: Char = '\u00B0' public val degree: Char = '\u00B0'
/** The character &#xB1; */
public val plusMinus: Char = '\u00B1' public val plusMinus: Char = '\u00B1'
/** The character &#xB6; */
public val paragraph: Char = '\u00B6' public val paragraph: Char = '\u00B6'
/** The character &#xB7; */
public val middleDot: Char = '\u00B7' public val middleDot: Char = '\u00B7'
/** The character &#xBD; */
public val half: Char = '\u00BD' public val half: Char = '\u00BD'
/** The character &#x2013; */
public val ndash: Char = '\u2013' public val ndash: Char = '\u2013'
/** The character &#x2014; */
public val mdash: Char = '\u2014' public val mdash: Char = '\u2014'
/** The character &#x2018; */
public val leftSingleQuote: Char = '\u2018' public val leftSingleQuote: Char = '\u2018'
/** The character &#x2019; */
public val rightSingleQuote: Char = '\u2019' public val rightSingleQuote: Char = '\u2019'
/** The character &#x201A; */
public val lowSingleQuote: Char = '\u201A' public val lowSingleQuote: Char = '\u201A'
/** The character &#x201C; */
public val leftDoubleQuote: Char = '\u201C' public val leftDoubleQuote: Char = '\u201C'
/** The character &#x201D; */
public val rightDoubleQuote: Char = '\u201D' public val rightDoubleQuote: Char = '\u201D'
public val lowDoubleQuote: Char = '\u201D' /** The character &#x201E; */
public val lowDoubleQuote: Char = '\u201E'
/** The character &#x2020; */
public val dagger: Char = '\u2020' public val dagger: Char = '\u2020'
/** The character &#x2021; */
public val doubleDagger: Char = '\u2021' public val doubleDagger: Char = '\u2021'
/** The character &#x2022; */
public val bullet: Char = '\u2022' public val bullet: Char = '\u2022'
/** The character &#x2026; */
public val ellipsis: Char = '\u2026' public val ellipsis: Char = '\u2026'
/** The character &#x2032; */
public val prime: Char = '\u2032' public val prime: Char = '\u2032'
/** The character &#x2033; */
public val doublePrime: Char = '\u2033' public val doublePrime: Char = '\u2033'
/** The character &#x20AC; */
public val euro: Char = '\u20AC' public val euro: Char = '\u20AC'
/** The character &#x2122; */
public val tm: Char = '\u2122' public val tm: Char = '\u2122'
/** The character &#x2248; */
public val almostEqual: Char = '\u2248' public val almostEqual: Char = '\u2248'
/** The character &#x2260; */
public val notEqual: Char = '\u2260' public val notEqual: Char = '\u2260'
/** The character &#x2264; */
public val lessOrEqual: Char = '\u2264' public val lessOrEqual: Char = '\u2264'
/** The character &#x2265; */
public val greaterOrEqual: Char = '\u2265' public val greaterOrEqual: Char = '\u2265'
} }
@@ -1,5 +1,10 @@
package kotlin package kotlin
/**
* Converts a function that takes one argument and returns a value of the same type to a generator function.
* The generator function calls this function, passing to it either [initialValue] on the first iteration
* or the previously returned value on subsequent iterations, and returns the returned value.
*/
public fun <T: Any> Function1<T, T?>.toGenerator(initialValue: T): Function0<T?> { public fun <T: Any> Function1<T, T?>.toGenerator(initialValue: T): Function0<T?> {
var nextValue: T? = initialValue var nextValue: T? = initialValue
return { return {
+6 -1
View File
@@ -6,7 +6,7 @@ import kotlin.jvm.internal.unsafe.*
import kotlin.jvm.internal.Intrinsic import kotlin.jvm.internal.Intrinsic
/** /**
* This annotation indicates what exceptions should be declared by a function when compiled to a JVM method * This annotation indicates what exceptions should be declared by a function when compiled to a JVM method.
* *
* Example: * Example:
* *
@@ -20,6 +20,8 @@ import kotlin.jvm.internal.Intrinsic
* ``` * ```
* String readFile(String name) throws IOException {...} * String readFile(String name) throws IOException {...}
* ``` * ```
*
* @property exceptionClasses the list of checked exception classes that may be thrown by the function.
*/ */
Retention(RetentionPolicy.SOURCE) Retention(RetentionPolicy.SOURCE)
public annotation class throws(public vararg val exceptionClasses: Class<out Throwable>) public annotation class throws(public vararg val exceptionClasses: Class<out Throwable>)
@@ -48,5 +50,8 @@ public inline fun <R> synchronized(lock: Any, block: () -> R): R {
} }
} }
/**
* Returns the annotation type of this annotation.
*/
public fun <T : Annotation> T.annotationType() : Class<out T> = public fun <T : Annotation> T.annotationType() : Class<out T> =
(this as java.lang.annotation.Annotation).annotationType() as Class<out T> (this as java.lang.annotation.Annotation).annotationType() as Class<out T>
+7 -7
View File
@@ -13,8 +13,8 @@ import java.io.Serializable
* *
* @param A type of the first value * @param A type of the first value
* @param B type of the second value * @param B type of the second value
* @param first First value * @property first First value
* @param second Second value * @property second Second value
* @constructor Creates a new instance of Pair. * @constructor Creates a new instance of Pair.
*/ */
public data class Pair<out A, out B>( public data class Pair<out A, out B>(
@@ -29,7 +29,7 @@ public data class Pair<out A, out B>(
} }
/** /**
* Converts a pair into a list. * Converts this pair into a list.
*/ */
public fun <T> Pair<T, T>.toList(): List<T> = listOf(first, second) public fun <T> Pair<T, T>.toList(): List<T> = listOf(first, second)
@@ -44,9 +44,9 @@ public fun <T> Pair<T, T>.toList(): List<T> = listOf(first, second)
* @param A type of the first value * @param A type of the first value
* @param B type of the second value * @param B type of the second value
* @param C type of the third value * @param C type of the third value
* @param first First value * @property first First value
* @param second Second value * @property second Second value
* @param third Third value * @property third Third value
*/ */
public data class Triple<out A, out B, out C>( public data class Triple<out A, out B, out C>(
public val first: A, public val first: A,
@@ -61,6 +61,6 @@ public data class Triple<out A, out B, out C>(
} }
/** /**
* Converts triple into a list * Converts this triple into a list.
*/ */
public fun <T> Triple<T, T, T>.toList(): List<T> = listOf(first, second, third) public fun <T> Triple<T, T, T>.toList(): List<T> = listOf(first, second, third)
@@ -32,6 +32,11 @@ private fun generateDownTos(outputFile: File, header: String) {
} }
writer.println(""" writer.println("""
/**
* Returns a progression from this value down to the specified [to] value.
*
* The [to] value has to be less than this value.
*/
public fun $fromType.downTo(to: $toType): $progressionType { public fun $fromType.downTo(to: $toType): $progressionType {
return $progressionType($fromExpr, $toExpr, $incrementExpr) return $progressionType($fromExpr, $toExpr, $incrementExpr)
}""") }""")
@@ -277,7 +277,7 @@ fun elements(): List<GenericFunction> {
templates add f("first(predicate: (T) -> Boolean)") { templates add f("first(predicate: (T) -> Boolean)") {
inline(true) inline(true)
doc { """"Returns the first element matching the given [predicate]. doc { """Returns the first element matching the given [predicate].
@throws NoSuchElementException if no such element is found.""" } @throws NoSuchElementException if no such element is found.""" }
doc(Strings) { """Returns the first character matching the given [predicate]. doc(Strings) { """Returns the first character matching the given [predicate].
@throws NoSuchElementException if no such character is found.""" } @throws NoSuchElementException if no such character is found.""" }
@@ -293,8 +293,8 @@ fun elements(): List<GenericFunction> {
templates add f("firstOrNull(predicate: (T) -> Boolean)") { templates add f("firstOrNull(predicate: (T) -> Boolean)") {
inline(true) inline(true)
doc { "Returns first element matching the given [predicate], or `null` if element was not found" } doc { "Returns the first element matching the given [predicate], or `null` if element was not found" }
doc(Strings) { "Returns first character matching the given [predicate], or `null` if character was not found" } doc(Strings) { "Returns the first character matching the given [predicate], or `null` if character was not found" }
returns("T?") returns("T?")
body { body {
""" """