Add samples for coerceIn, coerceAtLeast, coerceAtMost for comparable types

#KT-20357
This commit is contained in:
Ilya Gorbunov
2018-01-10 17:46:52 +03:00
parent 17573a3c21
commit 8fc83e3ff5
5 changed files with 57 additions and 12 deletions
@@ -472,7 +472,7 @@ public expect infix fun Short.until(to: Short): IntRange
* Ensures that this value is not less than the specified [minimumValue].
*
* @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise.
* @sample samples.comparisons.ComparableOps.coerceAtLeast
* @sample samples.comparisons.ComparableOps.coerceAtLeastComparable
*/
public expect fun <T: Comparable<T>> T.coerceAtLeast(minimumValue: T): T
@@ -528,7 +528,7 @@ public expect fun Double.coerceAtLeast(minimumValue: Double): Double
* Ensures that this value is not greater than the specified [maximumValue].
*
* @return this value if it's less than or equal to the [maximumValue] or the [maximumValue] otherwise.
* @sample samples.comparisons.ComparableOps.coerceAtMost
* @sample samples.comparisons.ComparableOps.coerceAtMostComparable
*/
public expect fun <T: Comparable<T>> T.coerceAtMost(maximumValue: T): T
@@ -584,6 +584,7 @@ public expect fun Double.coerceAtMost(maximumValue: Double): Double
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
* @sample samples.comparisons.ComparableOps.coerceInComparable
*/
public expect fun <T: Comparable<T>> T.coerceIn(minimumValue: T?, maximumValue: T?): T
@@ -591,6 +592,7 @@ public expect fun <T: Comparable<T>> T.coerceIn(minimumValue: T?, maximumValue:
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
* @sample samples.comparisons.ComparableOps.coerceIn
*/
public expect fun Byte.coerceIn(minimumValue: Byte, maximumValue: Byte): Byte
@@ -598,6 +600,7 @@ public expect fun Byte.coerceIn(minimumValue: Byte, maximumValue: Byte): Byte
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
* @sample samples.comparisons.ComparableOps.coerceIn
*/
public expect fun Short.coerceIn(minimumValue: Short, maximumValue: Short): Short
@@ -605,6 +608,7 @@ public expect fun Short.coerceIn(minimumValue: Short, maximumValue: Short): Shor
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
* @sample samples.comparisons.ComparableOps.coerceIn
*/
public expect fun Int.coerceIn(minimumValue: Int, maximumValue: Int): Int
@@ -612,6 +616,7 @@ public expect fun Int.coerceIn(minimumValue: Int, maximumValue: Int): Int
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
* @sample samples.comparisons.ComparableOps.coerceIn
*/
public expect fun Long.coerceIn(minimumValue: Long, maximumValue: Long): Long
@@ -619,6 +624,7 @@ public expect fun Long.coerceIn(minimumValue: Long, maximumValue: Long): Long
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
* @sample samples.comparisons.ComparableOps.coerceIn
*/
public expect fun Float.coerceIn(minimumValue: Float, maximumValue: Float): Float
@@ -626,6 +632,7 @@ public expect fun Float.coerceIn(minimumValue: Float, maximumValue: Float): Floa
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
* @sample samples.comparisons.ComparableOps.coerceIn
*/
public expect fun Double.coerceIn(minimumValue: Double, maximumValue: Double): Double
@@ -641,7 +648,7 @@ public expect fun <T: Comparable<T>> T.coerceIn(range: ClosedFloatingPointRange<
* Ensures that this value lies in the specified [range].
*
* @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
* @sample samples.comparisons.ComparableOps.coerceIn
* @sample samples.comparisons.ComparableOps.coerceInComparable
*/
public expect fun <T: Comparable<T>> T.coerceIn(range: ClosedRange<T>): T