Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
846a7823
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
846a7823
编写于
5月 20, 2020
作者:
A
Abduqodiri Qurbonzoda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce minOrNull and maxOrNull extension functions #KT-39064
上级
a8cd8ad8
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
871 addition
and
555 deletion
+871
-555
libraries/stdlib/common/src/generated/_Arrays.kt
libraries/stdlib/common/src/generated/_Arrays.kt
+315
-195
libraries/stdlib/common/src/generated/_Collections.kt
libraries/stdlib/common/src/generated/_Collections.kt
+95
-59
libraries/stdlib/common/src/generated/_Sequences.kt
libraries/stdlib/common/src/generated/_Sequences.kt
+101
-65
libraries/stdlib/common/src/generated/_Strings.kt
libraries/stdlib/common/src/generated/_Strings.kt
+30
-18
libraries/stdlib/common/src/generated/_UArrays.kt
libraries/stdlib/common/src/generated/_UArrays.kt
+132
-76
libraries/stdlib/src/kotlin/text/Indent.kt
libraries/stdlib/src/kotlin/text/Indent.kt
+1
-1
libraries/stdlib/test/collections/ArraysTest.kt
libraries/stdlib/test/collections/ArraysTest.kt
+40
-40
libraries/stdlib/test/collections/CollectionTest.kt
libraries/stdlib/test/collections/CollectionTest.kt
+22
-22
libraries/stdlib/test/collections/IterableTests.kt
libraries/stdlib/test/collections/IterableTests.kt
+4
-4
libraries/stdlib/test/collections/UnsignedArraysTest.kt
libraries/stdlib/test/collections/UnsignedArraysTest.kt
+20
-20
libraries/stdlib/test/numbers/NaNPropagationTest.kt
libraries/stdlib/test/numbers/NaNPropagationTest.kt
+44
-44
libraries/stdlib/test/text/StringTest.kt
libraries/stdlib/test/text/StringTest.kt
+2
-2
libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt
...tor/reference-public-api/kotlin-stdlib-runtime-merged.txt
+42
-0
libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt
...aries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt
+23
-9
未找到文件。
libraries/stdlib/common/src/generated/_Arrays.kt
浏览文件 @
846a7823
此差异已折叠。
点击以展开。
libraries/stdlib/common/src/generated/_Collections.kt
浏览文件 @
846a7823
...
...
@@ -1719,52 +1719,21 @@ public inline fun <T> Iterable<T>.forEachIndexed(action: (index: Int, T) -> Unit
for
(
item
in
this
)
action
(
checkIndexOverflow
(
index
++),
item
)
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
@SinceKotlin
(
"1.1"
)
public
fun
Iterable
<
Double
>.
max
():
Double
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
max
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
max
=
maxOf
(
max
,
e
)
}
return
max
return
maxOrNull
()
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
@SinceKotlin
(
"1.1"
)
public
fun
Iterable
<
Float
>.
max
():
Float
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
max
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
max
=
maxOf
(
max
,
e
)
}
return
max
return
maxOrNull
()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
public
fun
<
T
:
Comparable
<
T
>>
Iterable
<
T
>.
max
():
T
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
max
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
if
(
max
<
e
)
max
=
e
}
return
max
return
maxOrNull
()
}
/**
...
...
@@ -1966,65 +1935,83 @@ public inline fun <T, R> Iterable<T>.maxOfWithOrNull(comparator: Comparator<in R
}
/**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
public
fun
<
T
>
Iterable
<
T
>.
maxWith
(
comparator
:
Comparator
<
in
T
>):
T
?
{
@SinceKotlin
(
"1.4"
)
public
fun
Iterable
<
Double
>.
maxOrNull
():
Double
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
max
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
max
=
maxOf
(
max
,
e
)
}
return
max
}
/**
* Returns the
small
est element or `null` if there are no elements.
* Returns the
larg
est element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin
(
"1.
1
"
)
public
fun
Iterable
<
Double
>.
min
():
Double
?
{
@SinceKotlin
(
"1.
4
"
)
public
fun
Iterable
<
Float
>.
maxOrNull
():
Float
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
m
in
=
iterator
.
next
()
var
m
ax
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
m
in
=
minOf
(
min
,
e
)
m
ax
=
maxOf
(
max
,
e
)
}
return
m
in
return
m
ax
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
* Returns the largest element or `null` if there are no elements.
*/
@SinceKotlin
(
"1.
1
"
)
public
fun
Iterable
<
Float
>.
min
():
Float
?
{
@SinceKotlin
(
"1.
4
"
)
public
fun
<
T
:
Comparable
<
T
>>
Iterable
<
T
>.
maxOrNull
():
T
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
m
in
=
iterator
.
next
()
var
m
ax
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
min
=
minOf
(
min
,
e
)
if
(
max
<
e
)
max
=
e
}
return
m
in
return
m
ax
}
/**
* Returns the
smallest element
or `null` if there are no elements.
* Returns the
first element having the largest value according to the provided [comparator]
or `null` if there are no elements.
*/
public
fun
<
T
:
Comparable
<
T
>>
Iterable
<
T
>.
min
(
):
T
?
{
public
fun
<
T
>
Iterable
<
T
>.
maxWith
(
comparator
:
Comparator
<
in
T
>
):
T
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
m
in
=
iterator
.
next
()
var
m
ax
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
if
(
min
>
e
)
min
=
e
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
}
return
min
return
max
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
@SinceKotlin
(
"1.1"
)
public
fun
Iterable
<
Double
>.
min
():
Double
?
{
return
minOrNull
()
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
@SinceKotlin
(
"1.1"
)
public
fun
Iterable
<
Float
>.
min
():
Float
?
{
return
minOrNull
()
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
public
fun
<
T
:
Comparable
<
T
>>
Iterable
<
T
>.
min
():
T
?
{
return
minOrNull
()
}
/**
...
...
@@ -2225,6 +2212,55 @@ public inline fun <T, R> Iterable<T>.minOfWithOrNull(comparator: Comparator<in R
return
minValue
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin
(
"1.4"
)
public
fun
Iterable
<
Double
>.
minOrNull
():
Double
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
min
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
min
=
minOf
(
min
,
e
)
}
return
min
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*/
@SinceKotlin
(
"1.4"
)
public
fun
Iterable
<
Float
>.
minOrNull
():
Float
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
min
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
min
=
minOf
(
min
,
e
)
}
return
min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin
(
"1.4"
)
public
fun
<
T
:
Comparable
<
T
>>
Iterable
<
T
>.
minOrNull
():
T
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
min
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
if
(
min
>
e
)
min
=
e
}
return
min
}
/**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/
...
...
libraries/stdlib/common/src/generated/_Sequences.kt
浏览文件 @
846a7823
...
...
@@ -1166,58 +1166,21 @@ public inline fun <T> Sequence<T>.forEachIndexed(action: (index: Int, T) -> Unit
for
(
item
in
this
)
action
(
checkIndexOverflow
(
index
++),
item
)
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
@SinceKotlin
(
"1.1"
)
public
fun
Sequence
<
Double
>.
max
():
Double
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
max
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
max
=
maxOf
(
max
,
e
)
}
return
max
return
maxOrNull
()
}
/**
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
@SinceKotlin
(
"1.1"
)
public
fun
Sequence
<
Float
>.
max
():
Float
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
max
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
max
=
maxOf
(
max
,
e
)
}
return
max
return
maxOrNull
()
}
/**
* Returns the largest element or `null` if there are no elements.
*
* The operation is _terminal_.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
public
fun
<
T
:
Comparable
<
T
>>
Sequence
<
T
>.
max
():
T
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
max
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
if
(
max
<
e
)
max
=
e
}
return
max
return
maxOrNull
()
}
/**
...
...
@@ -1437,73 +1400,91 @@ public inline fun <T, R> Sequence<T>.maxOfWithOrNull(comparator: Comparator<in R
}
/**
* Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
* Returns the largest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
public
fun
<
T
>
Sequence
<
T
>.
maxWith
(
comparator
:
Comparator
<
in
T
>):
T
?
{
@SinceKotlin
(
"1.4"
)
public
fun
Sequence
<
Double
>.
maxOrNull
():
Double
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
max
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
max
=
maxOf
(
max
,
e
)
}
return
max
}
/**
* Returns the
small
est element or `null` if there are no elements.
* Returns the
larg
est element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@SinceKotlin
(
"1.
1
"
)
public
fun
Sequence
<
Double
>.
min
():
Double
?
{
@SinceKotlin
(
"1.
4
"
)
public
fun
Sequence
<
Float
>.
maxOrNull
():
Float
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
m
in
=
iterator
.
next
()
var
m
ax
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
m
in
=
minOf
(
min
,
e
)
m
ax
=
maxOf
(
max
,
e
)
}
return
m
in
return
m
ax
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
* Returns the largest element or `null` if there are no elements.
*
* The operation is _terminal_.
*/
@SinceKotlin
(
"1.
1
"
)
public
fun
Sequence
<
Float
>.
min
():
Float
?
{
@SinceKotlin
(
"1.
4
"
)
public
fun
<
T
:
Comparable
<
T
>>
Sequence
<
T
>.
maxOrNull
():
T
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
m
in
=
iterator
.
next
()
var
m
ax
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
min
=
minOf
(
min
,
e
)
if
(
max
<
e
)
max
=
e
}
return
m
in
return
m
ax
}
/**
* Returns the
smallest element
or `null` if there are no elements.
* Returns the
first element having the largest value according to the provided [comparator]
or `null` if there are no elements.
*
* The operation is _terminal_.
*/
public
fun
<
T
:
Comparable
<
T
>>
Sequence
<
T
>.
min
(
):
T
?
{
public
fun
<
T
>
Sequence
<
T
>.
maxWith
(
comparator
:
Comparator
<
in
T
>
):
T
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
m
in
=
iterator
.
next
()
var
m
ax
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
if
(
min
>
e
)
min
=
e
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
}
return
min
return
max
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
@SinceKotlin
(
"1.1"
)
public
fun
Sequence
<
Double
>.
min
():
Double
?
{
return
minOrNull
()
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
@SinceKotlin
(
"1.1"
)
public
fun
Sequence
<
Float
>.
min
():
Float
?
{
return
minOrNull
()
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
public
fun
<
T
:
Comparable
<
T
>>
Sequence
<
T
>.
min
():
T
?
{
return
minOrNull
()
}
/**
...
...
@@ -1722,6 +1703,61 @@ public inline fun <T, R> Sequence<T>.minOfWithOrNull(comparator: Comparator<in R
return
minValue
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@SinceKotlin
(
"1.4"
)
public
fun
Sequence
<
Double
>.
minOrNull
():
Double
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
min
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
min
=
minOf
(
min
,
e
)
}
return
min
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* If any of elements is `NaN` returns `NaN`.
*
* The operation is _terminal_.
*/
@SinceKotlin
(
"1.4"
)
public
fun
Sequence
<
Float
>.
minOrNull
():
Float
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
min
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
min
=
minOf
(
min
,
e
)
}
return
min
}
/**
* Returns the smallest element or `null` if there are no elements.
*
* The operation is _terminal_.
*/
@SinceKotlin
(
"1.4"
)
public
fun
<
T
:
Comparable
<
T
>>
Sequence
<
T
>.
minOrNull
():
T
?
{
val
iterator
=
iterator
()
if
(!
iterator
.
hasNext
())
return
null
var
min
=
iterator
.
next
()
while
(
iterator
.
hasNext
())
{
val
e
=
iterator
.
next
()
if
(
min
>
e
)
min
=
e
}
return
min
}
/**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*
...
...
libraries/stdlib/common/src/generated/_Strings.kt
浏览文件 @
846a7823
...
...
@@ -1088,17 +1088,9 @@ public inline fun CharSequence.forEachIndexed(action: (index: Int, Char) -> Unit
for
(
item
in
this
)
action
(
index
++,
item
)
}
/**
* Returns the largest character or `null` if there are no characters.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
public
fun
CharSequence
.
max
():
Char
?
{
if
(
isEmpty
())
return
null
var
max
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
max
<
e
)
max
=
e
}
return
max
return
maxOrNull
()
}
/**
...
...
@@ -1292,29 +1284,35 @@ public inline fun <R> CharSequence.maxOfWithOrNull(comparator: Comparator<in R>,
}
/**
* Returns the
first character having the largest value according to the provided [comparator]
or `null` if there are no characters.
* Returns the
largest character
or `null` if there are no characters.
*/
public
fun
CharSequence
.
maxWith
(
comparator
:
Comparator
<
in
Char
>):
Char
?
{
@SinceKotlin
(
"1.4"
)
public
fun
CharSequence
.
maxOrNull
():
Char
?
{
if
(
isEmpty
())
return
null
var
max
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
if
(
max
<
e
)
max
=
e
}
return
max
}
/**
* Returns the
smallest character
or `null` if there are no characters.
* Returns the
first character having the largest value according to the provided [comparator]
or `null` if there are no characters.
*/
public
fun
CharSequence
.
m
in
(
):
Char
?
{
public
fun
CharSequence
.
m
axWith
(
comparator
:
Comparator
<
in
Char
>
):
Char
?
{
if
(
isEmpty
())
return
null
var
m
in
=
this
[
0
]
var
m
ax
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
min
>
e
)
min
=
e
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
}
return
min
return
max
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
public
fun
CharSequence
.
min
():
Char
?
{
return
minOrNull
()
}
/**
...
...
@@ -1507,6 +1505,20 @@ public inline fun <R> CharSequence.minOfWithOrNull(comparator: Comparator<in R>,
return
minValue
}
/**
* Returns the smallest character or `null` if there are no characters.
*/
@SinceKotlin
(
"1.4"
)
public
fun
CharSequence
.
minOrNull
():
Char
?
{
if
(
isEmpty
())
return
null
var
min
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
min
>
e
)
min
=
e
}
return
min
}
/**
* Returns the first character having the smallest value according to the provided [comparator] or `null` if there are no characters.
*/
...
...
libraries/stdlib/common/src/generated/_UArrays.kt
浏览文件 @
846a7823
...
...
@@ -5702,64 +5702,32 @@ public inline fun UShortArray.forEachIndexed(action: (index: Int, UShort) -> Uni
for
(
item
in
this
)
action
(
index
++,
item
)
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
UIntArray
.
max
():
UInt
?
{
if
(
isEmpty
())
return
null
var
max
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
max
<
e
)
max
=
e
}
return
max
return
maxOrNull
()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
ULongArray
.
max
():
ULong
?
{
if
(
isEmpty
())
return
null
var
max
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
max
<
e
)
max
=
e
}
return
max
return
maxOrNull
()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
UByteArray
.
max
():
UByte
?
{
if
(
isEmpty
())
return
null
var
max
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
max
<
e
)
max
=
e
}
return
max
return
maxOrNull
()
}
/**
* Returns the largest element or `null` if there are no elements.
*/
@Deprecated
(
"Use maxOrNull instead."
,
ReplaceWith
(
"maxOrNull()"
))
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
UShortArray
.
max
():
UShort
?
{
if
(
isEmpty
())
return
null
var
max
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
max
<
e
)
max
=
e
}
return
max
return
maxOrNull
()
}
/**
...
...
@@ -6567,123 +6535,151 @@ public inline fun <R> UShortArray.maxOfWithOrNull(comparator: Comparator<in R>,
}
/**
* Returns the
first element having the largest value according to the provided [comparator]
or `null` if there are no elements.
* Returns the
largest element
or `null` if there are no elements.
*/
@SinceKotlin
(
"1.
3
"
)
@SinceKotlin
(
"1.
4
"
)
@ExperimentalUnsignedTypes
public
fun
UIntArray
.
max
With
(
comparator
:
Comparator
<
in
UInt
>
):
UInt
?
{
public
fun
UIntArray
.
max
OrNull
(
):
UInt
?
{
if
(
isEmpty
())
return
null
var
max
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
if
(
max
<
e
)
max
=
e
}
return
max
}
/**
* Returns the
first element having the largest value according to the provided [comparator]
or `null` if there are no elements.
* Returns the
largest element
or `null` if there are no elements.
*/
@SinceKotlin
(
"1.
3
"
)
@SinceKotlin
(
"1.
4
"
)
@ExperimentalUnsignedTypes
public
fun
ULongArray
.
max
With
(
comparator
:
Comparator
<
in
ULong
>
):
ULong
?
{
public
fun
ULongArray
.
max
OrNull
(
):
ULong
?
{
if
(
isEmpty
())
return
null
var
max
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
if
(
max
<
e
)
max
=
e
}
return
max
}
/**
* Returns the
first element having the largest value according to the provided [comparator]
or `null` if there are no elements.
* Returns the
largest element
or `null` if there are no elements.
*/
@SinceKotlin
(
"1.
3
"
)
@SinceKotlin
(
"1.
4
"
)
@ExperimentalUnsignedTypes
public
fun
UByteArray
.
max
With
(
comparator
:
Comparator
<
in
UByte
>
):
UByte
?
{
public
fun
UByteArray
.
max
OrNull
(
):
UByte
?
{
if
(
isEmpty
())
return
null
var
max
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
if
(
max
<
e
)
max
=
e
}
return
max
}
/**
* Returns the
first element having the largest value according to the provided [comparator]
or `null` if there are no elements.
* Returns the
largest element
or `null` if there are no elements.
*/
@SinceKotlin
(
"1.
3
"
)
@SinceKotlin
(
"1.
4
"
)
@ExperimentalUnsignedTypes
public
fun
UShortArray
.
max
With
(
comparator
:
Comparator
<
in
UShort
>
):
UShort
?
{
public
fun
UShortArray
.
max
OrNull
(
):
UShort
?
{
if
(
isEmpty
())
return
null
var
max
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
if
(
max
<
e
)
max
=
e
}
return
max
}
/**
* Returns the
smallest element
or `null` if there are no elements.
* Returns the
first element having the largest value according to the provided [comparator]
or `null` if there are no elements.
*/
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
UIntArray
.
m
in
(
):
UInt
?
{
public
fun
UIntArray
.
m
axWith
(
comparator
:
Comparator
<
in
UInt
>
):
UInt
?
{
if
(
isEmpty
())
return
null
var
m
in
=
this
[
0
]
var
m
ax
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
min
>
e
)
min
=
e
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
}
return
m
in
return
m
ax
}
/**
* Returns the
smallest element
or `null` if there are no elements.
* Returns the
first element having the largest value according to the provided [comparator]
or `null` if there are no elements.
*/
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
ULongArray
.
m
in
(
):
ULong
?
{
public
fun
ULongArray
.
m
axWith
(
comparator
:
Comparator
<
in
ULong
>
):
ULong
?
{
if
(
isEmpty
())
return
null
var
m
in
=
this
[
0
]
var
m
ax
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
min
>
e
)
min
=
e
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
}
return
m
in
return
m
ax
}
/**
* Returns the
smallest element
or `null` if there are no elements.
* Returns the
first element having the largest value according to the provided [comparator]
or `null` if there are no elements.
*/
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
UByteArray
.
m
in
(
):
UByte
?
{
public
fun
UByteArray
.
m
axWith
(
comparator
:
Comparator
<
in
UByte
>
):
UByte
?
{
if
(
isEmpty
())
return
null
var
m
in
=
this
[
0
]
var
m
ax
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
min
>
e
)
min
=
e
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
}
return
m
in
return
m
ax
}
/**
* Returns the
smallest element
or `null` if there are no elements.
* Returns the
first element having the largest value according to the provided [comparator]
or `null` if there are no elements.
*/
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
UShortArray
.
m
in
(
):
UShort
?
{
public
fun
UShortArray
.
m
axWith
(
comparator
:
Comparator
<
in
UShort
>
):
UShort
?
{
if
(
isEmpty
())
return
null
var
m
in
=
this
[
0
]
var
m
ax
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
min
>
e
)
min
=
e
if
(
comparator
.
compare
(
max
,
e
)
<
0
)
max
=
e
}
return
min
return
max
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
UIntArray
.
min
():
UInt
?
{
return
minOrNull
()
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
ULongArray
.
min
():
ULong
?
{
return
minOrNull
()
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
UByteArray
.
min
():
UByte
?
{
return
minOrNull
()
}
@Deprecated
(
"Use minOrNull instead."
,
ReplaceWith
(
"minOrNull()"
))
@SinceKotlin
(
"1.3"
)
@ExperimentalUnsignedTypes
public
fun
UShortArray
.
min
():
UShort
?
{
return
minOrNull
()
}
/**
...
...
@@ -7490,6 +7486,66 @@ public inline fun <R> UShortArray.minOfWithOrNull(comparator: Comparator<in R>,
return
minValue
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin
(
"1.4"
)
@ExperimentalUnsignedTypes
public
fun
UIntArray
.
minOrNull
():
UInt
?
{
if
(
isEmpty
())
return
null
var
min
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
min
>
e
)
min
=
e
}
return
min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin
(
"1.4"
)
@ExperimentalUnsignedTypes
public
fun
ULongArray
.
minOrNull
():
ULong
?
{
if
(
isEmpty
())
return
null
var
min
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
min
>
e
)
min
=
e
}
return
min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin
(
"1.4"
)
@ExperimentalUnsignedTypes
public
fun
UByteArray
.
minOrNull
():
UByte
?
{
if
(
isEmpty
())
return
null
var
min
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
min
>
e
)
min
=
e
}
return
min
}
/**
* Returns the smallest element or `null` if there are no elements.
*/
@SinceKotlin
(
"1.4"
)
@ExperimentalUnsignedTypes
public
fun
UShortArray
.
minOrNull
():
UShort
?
{
if
(
isEmpty
())
return
null
var
min
=
this
[
0
]
for
(
i
in
1
..
lastIndex
)
{
val
e
=
this
[
i
]
if
(
min
>
e
)
min
=
e
}
return
min
}
/**
* Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
*/
...
...
libraries/stdlib/src/kotlin/text/Indent.kt
浏览文件 @
846a7823
...
...
@@ -71,7 +71,7 @@ public fun String.replaceIndent(newIndent: String = ""): String {
val
minCommonIndent
=
lines
.
filter
(
String
::
isNotBlank
)
.
map
(
String
::
indentWidth
)
.
min
()
?:
0
.
min
OrNull
()
?:
0
return
lines
.
reindent
(
length
+
newIndent
.
length
*
lines
.
size
,
getIndentFunction
(
newIndent
),
{
line
->
line
.
drop
(
minCommonIndent
)
})
}
...
...
libraries/stdlib/test/collections/ArraysTest.kt
浏览文件 @
846a7823
...
...
@@ -348,46 +348,46 @@ class ArraysTest {
@Test
fun
min
()
{
expect
(
null
,
{
arrayOf
<
Int
>().
min
()
})
expect
(
1
,
{
arrayOf
(
1
).
min
()
})
expect
(
2
,
{
arrayOf
(
2
,
3
).
min
()
})
expect
(
2000000000000
,
{
arrayOf
(
3000000000000
,
2000000000000
).
min
()
})
expect
(
'a'
,
{
arrayOf
(
'a'
,
'b'
).
min
()
})
expect
(
"a"
,
{
arrayOf
(
"a"
,
"b"
).
min
()
})
}
@Test
fun
minInPrimitiveArrays
()
{
expect
(
null
,
{
intArrayOf
().
min
()
})
expect
(
1
,
{
intArrayOf
(
1
).
min
()
})
expect
(
2
,
{
intArrayOf
(
2
,
3
).
min
()
})
expect
(
2000000000000
,
{
longArrayOf
(
3000000000000
,
2000000000000
).
min
()
})
expect
(
1
,
{
byteArrayOf
(
1
,
3
,
2
).
min
()
})
expect
(
2
,
{
shortArrayOf
(
3
,
2
).
min
()
})
expect
(
2.0F
,
{
floatArrayOf
(
3.0F
,
2.0F
).
min
()
})
expect
(
2.0
,
{
doubleArrayOf
(
2.0
,
3.0
).
min
()
})
expect
(
'a'
,
{
charArrayOf
(
'a'
,
'b'
).
min
()
})
}
@Test
fun
max
()
{
expect
(
null
,
{
arrayOf
<
Int
>().
max
()
})
expect
(
1
,
{
arrayOf
(
1
).
max
()
})
expect
(
3
,
{
arrayOf
(
2
,
3
).
max
()
})
expect
(
3000000000000
,
{
arrayOf
(
3000000000000
,
2000000000000
).
max
()
})
expect
(
'b'
,
{
arrayOf
(
'a'
,
'b'
).
max
()
})
expect
(
"b"
,
{
arrayOf
(
"a"
,
"b"
).
max
()
})
}
@Test
fun
maxInPrimitiveArrays
()
{
expect
(
null
,
{
intArrayOf
().
max
()
})
expect
(
1
,
{
intArrayOf
(
1
).
max
()
})
expect
(
3
,
{
intArrayOf
(
2
,
3
).
max
()
})
expect
(
3000000000000
,
{
longArrayOf
(
3000000000000
,
2000000000000
).
max
()
})
expect
(
3
,
{
byteArrayOf
(
1
,
3
,
2
).
max
()
})
expect
(
3
,
{
shortArrayOf
(
3
,
2
).
max
()
})
expect
(
3.0F
,
{
floatArrayOf
(
3.0F
,
2.0F
).
max
()
})
expect
(
3.0
,
{
doubleArrayOf
(
2.0
,
3.0
).
max
()
})
expect
(
'b'
,
{
charArrayOf
(
'a'
,
'b'
).
max
()
})
@Test
fun
min
OrNull
()
{
expect
(
null
,
{
arrayOf
<
Int
>().
min
OrNull
()
})
expect
(
1
,
{
arrayOf
(
1
).
min
OrNull
()
})
expect
(
2
,
{
arrayOf
(
2
,
3
).
min
OrNull
()
})
expect
(
2000000000000
,
{
arrayOf
(
3000000000000
,
2000000000000
).
min
OrNull
()
})
expect
(
'a'
,
{
arrayOf
(
'a'
,
'b'
).
min
OrNull
()
})
expect
(
"a"
,
{
arrayOf
(
"a"
,
"b"
).
min
OrNull
()
})
}
@Test
fun
min
OrNull
InPrimitiveArrays
()
{
expect
(
null
,
{
intArrayOf
().
min
OrNull
()
})
expect
(
1
,
{
intArrayOf
(
1
).
min
OrNull
()
})
expect
(
2
,
{
intArrayOf
(
2
,
3
).
min
OrNull
()
})
expect
(
2000000000000
,
{
longArrayOf
(
3000000000000
,
2000000000000
).
min
OrNull
()
})
expect
(
1
,
{
byteArrayOf
(
1
,
3
,
2
).
min
OrNull
()
})
expect
(
2
,
{
shortArrayOf
(
3
,
2
).
min
OrNull
()
})
expect
(
2.0F
,
{
floatArrayOf
(
3.0F
,
2.0F
).
min
OrNull
()
})
expect
(
2.0
,
{
doubleArrayOf
(
2.0
,
3.0
).
min
OrNull
()
})
expect
(
'a'
,
{
charArrayOf
(
'a'
,
'b'
).
min
OrNull
()
})
}
@Test
fun
max
OrNull
()
{
expect
(
null
,
{
arrayOf
<
Int
>().
max
OrNull
()
})
expect
(
1
,
{
arrayOf
(
1
).
max
OrNull
()
})
expect
(
3
,
{
arrayOf
(
2
,
3
).
max
OrNull
()
})
expect
(
3000000000000
,
{
arrayOf
(
3000000000000
,
2000000000000
).
max
OrNull
()
})
expect
(
'b'
,
{
arrayOf
(
'a'
,
'b'
).
max
OrNull
()
})
expect
(
"b"
,
{
arrayOf
(
"a"
,
"b"
).
max
OrNull
()
})
}
@Test
fun
max
OrNull
InPrimitiveArrays
()
{
expect
(
null
,
{
intArrayOf
().
max
OrNull
()
})
expect
(
1
,
{
intArrayOf
(
1
).
max
OrNull
()
})
expect
(
3
,
{
intArrayOf
(
2
,
3
).
max
OrNull
()
})
expect
(
3000000000000
,
{
longArrayOf
(
3000000000000
,
2000000000000
).
max
OrNull
()
})
expect
(
3
,
{
byteArrayOf
(
1
,
3
,
2
).
max
OrNull
()
})
expect
(
3
,
{
shortArrayOf
(
3
,
2
).
max
OrNull
()
})
expect
(
3.0F
,
{
floatArrayOf
(
3.0F
,
2.0F
).
max
OrNull
()
})
expect
(
3.0
,
{
doubleArrayOf
(
2.0
,
3.0
).
max
OrNull
()
})
expect
(
'b'
,
{
charArrayOf
(
'a'
,
'b'
).
max
OrNull
()
})
}
@Test
fun
minWith
()
{
...
...
libraries/stdlib/test/collections/CollectionTest.kt
浏览文件 @
846a7823
...
...
@@ -823,32 +823,32 @@ class CollectionTest {
assertTrue
(
hashSetOf
(
45
,
14
,
13
).
toIterable
().
contains
(
14
))
}
@Test
fun
min
()
{
expect
(
null
,
{
listOf
<
Int
>().
min
()
})
expect
(
1
,
{
listOf
(
1
).
min
()
})
expect
(
2
,
{
listOf
(
2
,
3
).
min
()
})
expect
(
2000000000000
,
{
listOf
(
3000000000000
,
2000000000000
).
min
()
})
expect
(
'a'
,
{
listOf
(
'a'
,
'b'
).
min
()
})
expect
(
"a"
,
{
listOf
(
"a"
,
"b"
).
min
()
})
expect
(
null
,
{
listOf
<
Int
>().
asSequence
().
min
()
})
expect
(
2
,
{
listOf
(
2
,
3
).
asSequence
().
min
()
})
@Test
fun
min
OrNull
()
{
expect
(
null
,
{
listOf
<
Int
>().
min
OrNull
()
})
expect
(
1
,
{
listOf
(
1
).
min
OrNull
()
})
expect
(
2
,
{
listOf
(
2
,
3
).
min
OrNull
()
})
expect
(
2000000000000
,
{
listOf
(
3000000000000
,
2000000000000
).
min
OrNull
()
})
expect
(
'a'
,
{
listOf
(
'a'
,
'b'
).
min
OrNull
()
})
expect
(
"a"
,
{
listOf
(
"a"
,
"b"
).
min
OrNull
()
})
expect
(
null
,
{
listOf
<
Int
>().
asSequence
().
min
OrNull
()
})
expect
(
2
,
{
listOf
(
2
,
3
).
asSequence
().
min
OrNull
()
})
assertIsNegativeZero
(
listOf
(
0.0
,
-
0.0
).
shuffled
().
min
()
!!
)
assertIsNegativeZero
(
listOf
(
0.0F
,
-
0.0F
).
shuffled
().
min
()
!!
.
toDouble
())
assertIsNegativeZero
(
listOf
(
0.0
,
-
0.0
).
shuffled
().
min
OrNull
()
!!
)
assertIsNegativeZero
(
listOf
(
0.0F
,
-
0.0F
).
shuffled
().
min
OrNull
()
!!
.
toDouble
())
}
@Test
fun
max
()
{
expect
(
null
,
{
listOf
<
Int
>().
max
()
})
expect
(
1
,
{
listOf
(
1
).
max
()
})
expect
(
3
,
{
listOf
(
2
,
3
).
max
()
})
expect
(
3000000000000
,
{
listOf
(
3000000000000
,
2000000000000
).
max
()
})
expect
(
'b'
,
{
listOf
(
'a'
,
'b'
).
max
()
})
expect
(
"b"
,
{
listOf
(
"a"
,
"b"
).
max
()
})
expect
(
null
,
{
listOf
<
Int
>().
asSequence
().
max
()
})
expect
(
3
,
{
listOf
(
2
,
3
).
asSequence
().
max
()
})
assertIsPositiveZero
(
listOf
(
0.0
,
-
0.0
).
shuffled
().
max
()
!!
)
assertIsPositiveZero
(
listOf
(
0.0F
,
-
0.0F
).
shuffled
().
max
()
!!
.
toDouble
())
expect
(
null
,
{
listOf
<
Int
>().
max
OrNull
()
})
expect
(
1
,
{
listOf
(
1
).
max
OrNull
()
})
expect
(
3
,
{
listOf
(
2
,
3
).
max
OrNull
()
})
expect
(
3000000000000
,
{
listOf
(
3000000000000
,
2000000000000
).
max
OrNull
()
})
expect
(
'b'
,
{
listOf
(
'a'
,
'b'
).
max
OrNull
()
})
expect
(
"b"
,
{
listOf
(
"a"
,
"b"
).
max
OrNull
()
})
expect
(
null
,
{
listOf
<
Int
>().
asSequence
().
max
OrNull
()
})
expect
(
3
,
{
listOf
(
2
,
3
).
asSequence
().
max
OrNull
()
})
assertIsPositiveZero
(
listOf
(
0.0
,
-
0.0
).
shuffled
().
max
OrNull
()
!!
)
assertIsPositiveZero
(
listOf
(
0.0F
,
-
0.0F
).
shuffled
().
max
OrNull
()
!!
.
toDouble
())
}
@Test
fun
minWith
()
{
...
...
libraries/stdlib/test/collections/IterableTests.kt
浏览文件 @
846a7823
...
...
@@ -394,14 +394,14 @@ abstract class IterableTests<T : Iterable<String>>(val createFrom: (Array<out St
}
@Test
fun
max
()
{
expect
(
"foo"
)
{
data
.
max
()
}
fun
max
OrNull
()
{
expect
(
"foo"
)
{
data
.
max
OrNull
()
}
expect
(
"bar"
)
{
data
.
maxBy
{
it
.
last
()
}
}
}
@Test
fun
min
()
{
expect
(
"bar"
)
{
data
.
min
()
}
fun
min
OrNull
()
{
expect
(
"bar"
)
{
data
.
min
OrNull
()
}
expect
(
"foo"
)
{
data
.
minBy
{
it
.
last
()
}
}
}
...
...
libraries/stdlib/test/collections/UnsignedArraysTest.kt
浏览文件 @
846a7823
...
...
@@ -419,35 +419,35 @@ class UnsignedArraysTest {
}
@Test
fun
min
()
{
expect
(
null
)
{
arrayOf
<
UByte
>().
min
()
}
expect
(
1u
)
{
arrayOf
<
UShort
>(
1
).
min
()
}
expect
(
2u
)
{
arrayOf
<
UInt
>(
2
,
3
).
min
()
}
expect
(
2uL
)
{
arrayOf
<
ULong
>(
3
,
2
).
min
()
}
fun
min
OrNull
()
{
expect
(
null
)
{
arrayOf
<
UByte
>().
min
OrNull
()
}
expect
(
1u
)
{
arrayOf
<
UShort
>(
1
).
min
OrNull
()
}
expect
(
2u
)
{
arrayOf
<
UInt
>(
2
,
3
).
min
OrNull
()
}
expect
(
2uL
)
{
arrayOf
<
ULong
>(
3
,
2
).
min
OrNull
()
}
}
@Test
fun
minInUnsignedArrays
()
{
expect
(
null
)
{
ubyteArrayOf
().
min
()
}
expect
(
1u
)
{
ushortArrayOf
(
1
).
min
()
}
expect
(
2u
)
{
uintArrayOf
(
2
,
3
).
min
()
}
expect
(
2uL
)
{
ulongArrayOf
(
3
,
2
).
min
()
}
fun
min
OrNull
InUnsignedArrays
()
{
expect
(
null
)
{
ubyteArrayOf
().
min
OrNull
()
}
expect
(
1u
)
{
ushortArrayOf
(
1
).
min
OrNull
()
}
expect
(
2u
)
{
uintArrayOf
(
2
,
3
).
min
OrNull
()
}
expect
(
2uL
)
{
ulongArrayOf
(
3
,
2
).
min
OrNull
()
}
}
@Test
fun
max
()
{
expect
(
null
)
{
arrayOf
<
UByte
>().
max
()
}
expect
(
1u
)
{
arrayOf
<
UShort
>(
1
).
max
()
}
expect
(
3u
)
{
arrayOf
<
UInt
>(
2
,
3
).
max
()
}
expect
(
3uL
)
{
arrayOf
<
ULong
>(
3
,
2
).
max
()
}
fun
max
OrNull
()
{
expect
(
null
)
{
arrayOf
<
UByte
>().
max
OrNull
()
}
expect
(
1u
)
{
arrayOf
<
UShort
>(
1
).
max
OrNull
()
}
expect
(
3u
)
{
arrayOf
<
UInt
>(
2
,
3
).
max
OrNull
()
}
expect
(
3uL
)
{
arrayOf
<
ULong
>(
3
,
2
).
max
OrNull
()
}
}
@Test
fun
maxInUnsignedArrays
()
{
expect
(
null
)
{
ubyteArrayOf
().
max
()
}
expect
(
1u
)
{
ushortArrayOf
(
1
).
max
()
}
expect
(
3u
)
{
uintArrayOf
(
2
,
3
).
max
()
}
expect
(
3uL
)
{
ulongArrayOf
(
3
,
2
).
max
()
}
fun
max
OrNull
InUnsignedArrays
()
{
expect
(
null
)
{
ubyteArrayOf
().
max
OrNull
()
}
expect
(
1u
)
{
ushortArrayOf
(
1
).
max
OrNull
()
}
expect
(
3u
)
{
uintArrayOf
(
2
,
3
).
max
OrNull
()
}
expect
(
3uL
)
{
ulongArrayOf
(
3
,
2
).
max
OrNull
()
}
}
@Test
...
...
libraries/stdlib/test/numbers/NaNPropagationTest.kt
浏览文件 @
846a7823
...
...
@@ -83,20 +83,20 @@ class NaNPropagationTest {
}
@Test
fun
arrayMin
()
{
fun
arrayMin
OrNull
()
{
propagateOf2
(
{
a
,
b
->
arrayOf
(
a
,
b
).
min
()
!!
},
{
a
,
b
->
arrayOf
(
a
,
b
).
min
()
!!
},
"arrayOf().min()"
{
a
,
b
->
arrayOf
(
a
,
b
).
min
OrNull
()
!!
},
{
a
,
b
->
arrayOf
(
a
,
b
).
min
OrNull
()
!!
},
"arrayOf().min
OrNull
()"
)
}
@Test
fun
arrayMax
()
{
fun
arrayMax
OrNull
()
{
propagateOf2
(
{
a
,
b
->
arrayOf
(
a
,
b
).
max
()
!!
},
{
a
,
b
->
arrayOf
(
a
,
b
).
max
()
!!
},
"arrayOf().max()"
{
a
,
b
->
arrayOf
(
a
,
b
).
max
OrNull
()
!!
},
{
a
,
b
->
arrayOf
(
a
,
b
).
max
OrNull
()
!!
},
"arrayOf().max
OrNull
()"
)
}
...
...
@@ -108,7 +108,7 @@ class NaNPropagationTest {
"arrayOf().minOf()"
)
}
@Test
fun
arrayMaxOf
()
{
propagateOf3
(
...
...
@@ -119,20 +119,20 @@ class NaNPropagationTest {
}
@Test
fun
primitiveArrayMin
()
{
fun
primitiveArrayMin
OrNull
()
{
propagateOf2
(
{
a
,
b
->
doubleArrayOf
(
a
,
b
).
min
()
!!
},
{
a
,
b
->
floatArrayOf
(
a
,
b
).
min
()
!!
},
"primitiveArrayOf().min()"
{
a
,
b
->
doubleArrayOf
(
a
,
b
).
min
OrNull
()
!!
},
{
a
,
b
->
floatArrayOf
(
a
,
b
).
min
OrNull
()
!!
},
"primitiveArrayOf().min
OrNull
()"
)
}
@Test
fun
primitiveArrayMax
()
{
propagateOf2
(
{
a
,
b
->
doubleArrayOf
(
a
,
b
).
m
ax
()
!!
},
{
a
,
b
->
floatArrayOf
(
a
,
b
).
m
ax
()
!!
},
"primitiveArrayOf().max()"
{
a
,
b
->
doubleArrayOf
(
a
,
b
).
m
inOrNull
()
!!
},
{
a
,
b
->
floatArrayOf
(
a
,
b
).
m
inOrNull
()
!!
},
"primitiveArrayOf().max
OrNull
()"
)
}
...
...
@@ -165,20 +165,20 @@ class NaNPropagationTest {
}
@Test
fun
listMin
()
{
fun
listMin
OrNull
()
{
propagateOf2
(
{
a
,
b
->
listOf
(
a
,
b
).
min
()
!!
},
{
a
,
b
->
listOf
(
a
,
b
).
min
()
!!
},
"listOf().min()"
{
a
,
b
->
listOf
(
a
,
b
).
min
OrNull
()
!!
},
{
a
,
b
->
listOf
(
a
,
b
).
min
OrNull
()
!!
},
"listOf().min
OrNull
()"
)
}
@Test
fun
listMax
()
{
fun
listMax
OrNull
()
{
propagateOf2
(
{
a
,
b
->
listOf
(
a
,
b
).
max
()
!!
},
{
a
,
b
->
listOf
(
a
,
b
).
max
()
!!
},
"listOf().max()"
{
a
,
b
->
listOf
(
a
,
b
).
max
OrNull
()
!!
},
{
a
,
b
->
listOf
(
a
,
b
).
max
OrNull
()
!!
},
"listOf().max
OrNull
()"
)
}
...
...
@@ -201,20 +201,20 @@ class NaNPropagationTest {
}
@Test
fun
sequenceMin
()
{
fun
sequenceMin
OrNull
()
{
propagateOf2
(
{
a
,
b
->
sequenceOf
(
a
,
b
).
min
()
!!
},
{
a
,
b
->
sequenceOf
(
a
,
b
).
min
()
!!
},
"sequenceOf().min()"
{
a
,
b
->
sequenceOf
(
a
,
b
).
min
OrNull
()
!!
},
{
a
,
b
->
sequenceOf
(
a
,
b
).
min
OrNull
()
!!
},
"sequenceOf().min
OrNull
()"
)
}
@Test
fun
sequenceMax
()
{
fun
sequenceMax
OrNull
()
{
propagateOf2
(
{
a
,
b
->
sequenceOf
(
a
,
b
).
max
()
!!
},
{
a
,
b
->
sequenceOf
(
a
,
b
).
max
()
!!
},
"sequenceOf().max()"
{
a
,
b
->
sequenceOf
(
a
,
b
).
max
OrNull
()
!!
},
{
a
,
b
->
sequenceOf
(
a
,
b
).
max
OrNull
()
!!
},
"sequenceOf().max
OrNull
()"
)
}
...
...
@@ -266,34 +266,34 @@ class NaNTotalOrderTest {
}
@Test
fun
arrayTMin
()
{
totalOrderMinOf2
<
Comparable
<
Any
>>({
a
,
b
->
arrayOf
(
a
,
b
).
min
()
!!
},
"arrayOf().min
()"
)
fun
arrayTMin
OrNull
()
{
totalOrderMinOf2
<
Comparable
<
Any
>>({
a
,
b
->
arrayOf
(
a
,
b
).
min
OrNull
()
!!
},
"arrayOf().minOrNull
()"
)
}
@Test
fun
arrayTMax
()
{
totalOrderMaxOf2
<
Comparable
<
Any
>>({
a
,
b
->
arrayOf
(
a
,
b
).
max
()
!!
},
"arrayOf().max
()"
)
fun
arrayTMax
OrNull
()
{
totalOrderMaxOf2
<
Comparable
<
Any
>>({
a
,
b
->
arrayOf
(
a
,
b
).
max
OrNull
()
!!
},
"arrayOf().maxOrNull
()"
)
}
@Test
fun
listTMin
()
{
totalOrderMinOf2
<
Comparable
<
Any
>>({
a
,
b
->
listOf
(
a
,
b
).
min
()
!!
},
"listOf().min
()"
)
fun
listTMin
OrNull
()
{
totalOrderMinOf2
<
Comparable
<
Any
>>({
a
,
b
->
listOf
(
a
,
b
).
min
OrNull
()
!!
},
"listOf().minOrNull
()"
)
}
@Test
fun
listTMax
()
{
totalOrderMaxOf2
<
Comparable
<
Any
>>({
a
,
b
->
listOf
(
a
,
b
).
max
()
!!
},
"listOf().max
()"
)
fun
listTMax
OrNull
()
{
totalOrderMaxOf2
<
Comparable
<
Any
>>({
a
,
b
->
listOf
(
a
,
b
).
max
OrNull
()
!!
},
"listOf().maxOrNull
()"
)
}
@Test
fun
sequenceTMin
()
{
totalOrderMinOf2
<
Comparable
<
Any
>>({
a
,
b
->
sequenceOf
(
a
,
b
).
min
()
!!
},
"sequenceOf().min
()"
)
fun
sequenceTMin
OrNull
()
{
totalOrderMinOf2
<
Comparable
<
Any
>>({
a
,
b
->
sequenceOf
(
a
,
b
).
min
OrNull
()
!!
},
"sequenceOf().minOrNull
()"
)
}
@Test
fun
sequenceTMax
()
{
totalOrderMaxOf2
<
Comparable
<
Any
>>({
a
,
b
->
sequenceOf
(
a
,
b
).
max
()
!!
},
"sequenceOf().max
()"
)
fun
sequenceTMax
OrNull
()
{
totalOrderMaxOf2
<
Comparable
<
Any
>>({
a
,
b
->
sequenceOf
(
a
,
b
).
max
OrNull
()
!!
},
"sequenceOf().maxOrNull
()"
)
}
}
libraries/stdlib/test/text/StringTest.kt
浏览文件 @
846a7823
...
...
@@ -1635,8 +1635,8 @@ ${" "}
assertEquals
(
23
,
deindented
.
lines
().
size
)
val
indents
=
deindented
.
lines
().
map
{
"^\\s*"
.
toRegex
().
find
(
it
)
!!
.
value
.
length
}
assertEquals
(
0
,
indents
.
min
())
assertEquals
(
42
,
indents
.
max
())
assertEquals
(
0
,
indents
.
min
OrNull
())
assertEquals
(
42
,
indents
.
max
OrNull
())
assertEquals
(
1
,
deindented
.
lines
().
count
{
it
.
isEmpty
()
})
}
...
...
libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt
浏览文件 @
846a7823
...
...
@@ -1393,6 +1393,16 @@ public final class kotlin/collections/ArraysKt {
public static final fun maxBy ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun maxBy ([SLkotlin/jvm/functions/Function1;)Ljava/lang/Short;
public static final fun maxBy ([ZLkotlin/jvm/functions/Function1;)Ljava/lang/Boolean;
public static final fun maxOrNull ([B)Ljava/lang/Byte;
public static final fun maxOrNull ([C)Ljava/lang/Character;
public static final fun maxOrNull ([D)Ljava/lang/Double;
public static final fun maxOrNull ([F)Ljava/lang/Float;
public static final fun maxOrNull ([I)Ljava/lang/Integer;
public static final fun maxOrNull ([J)Ljava/lang/Long;
public static final fun maxOrNull ([Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun maxOrNull ([Ljava/lang/Double;)Ljava/lang/Double;
public static final fun maxOrNull ([Ljava/lang/Float;)Ljava/lang/Float;
public static final fun maxOrNull ([S)Ljava/lang/Short;
public static final fun maxWith ([BLjava/util/Comparator;)Ljava/lang/Byte;
public static final fun maxWith ([CLjava/util/Comparator;)Ljava/lang/Character;
public static final fun maxWith ([DLjava/util/Comparator;)Ljava/lang/Double;
...
...
@@ -1421,6 +1431,16 @@ public final class kotlin/collections/ArraysKt {
public static final fun minBy ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun minBy ([SLkotlin/jvm/functions/Function1;)Ljava/lang/Short;
public static final fun minBy ([ZLkotlin/jvm/functions/Function1;)Ljava/lang/Boolean;
public static final fun minOrNull ([B)Ljava/lang/Byte;
public static final fun minOrNull ([C)Ljava/lang/Character;
public static final fun minOrNull ([D)Ljava/lang/Double;
public static final fun minOrNull ([F)Ljava/lang/Float;
public static final fun minOrNull ([I)Ljava/lang/Integer;
public static final fun minOrNull ([J)Ljava/lang/Long;
public static final fun minOrNull ([Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun minOrNull ([Ljava/lang/Double;)Ljava/lang/Double;
public static final fun minOrNull ([Ljava/lang/Float;)Ljava/lang/Float;
public static final fun minOrNull ([S)Ljava/lang/Short;
public static final fun minWith ([BLjava/util/Comparator;)Ljava/lang/Byte;
public static final fun minWith ([CLjava/util/Comparator;)Ljava/lang/Character;
public static final fun minWith ([DLjava/util/Comparator;)Ljava/lang/Double;
...
...
@@ -2195,11 +2215,17 @@ public final class kotlin/collections/CollectionsKt {
public static final fun max (Ljava/lang/Iterable;)Ljava/lang/Double;
public static final fun max (Ljava/lang/Iterable;)Ljava/lang/Float;
public static final fun maxBy (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun maxOrNull (Ljava/lang/Iterable;)Ljava/lang/Comparable;
public static final fun maxOrNull (Ljava/lang/Iterable;)Ljava/lang/Double;
public static final fun maxOrNull (Ljava/lang/Iterable;)Ljava/lang/Float;
public static final fun maxWith (Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/lang/Object;
public static final fun min (Ljava/lang/Iterable;)Ljava/lang/Comparable;
public static final fun min (Ljava/lang/Iterable;)Ljava/lang/Double;
public static final fun min (Ljava/lang/Iterable;)Ljava/lang/Float;
public static final fun minBy (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun minOrNull (Ljava/lang/Iterable;)Ljava/lang/Comparable;
public static final fun minOrNull (Ljava/lang/Iterable;)Ljava/lang/Double;
public static final fun minOrNull (Ljava/lang/Iterable;)Ljava/lang/Float;
public static final fun minWith (Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/lang/Object;
public static final fun minus (Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
public static final fun minus (Ljava/lang/Iterable;Ljava/lang/Object;)Ljava/util/List;
...
...
@@ -2615,6 +2641,10 @@ public final class kotlin/collections/unsigned/UArraysKt {
public static final fun max-GBYM_sE ([B)Lkotlin/UByte;
public static final fun max-QwZRm1k ([J)Lkotlin/ULong;
public static final fun max-rL5Bavg ([S)Lkotlin/UShort;
public static final fun maxOrNull--ajY-9A ([I)Lkotlin/UInt;
public static final fun maxOrNull-GBYM_sE ([B)Lkotlin/UByte;
public static final fun maxOrNull-QwZRm1k ([J)Lkotlin/ULong;
public static final fun maxOrNull-rL5Bavg ([S)Lkotlin/UShort;
public static final fun maxWith-XMRcp5o ([BLjava/util/Comparator;)Lkotlin/UByte;
public static final fun maxWith-YmdZ_VM ([ILjava/util/Comparator;)Lkotlin/UInt;
public static final fun maxWith-eOHTfZs ([SLjava/util/Comparator;)Lkotlin/UShort;
...
...
@@ -2623,6 +2653,10 @@ public final class kotlin/collections/unsigned/UArraysKt {
public static final fun min-GBYM_sE ([B)Lkotlin/UByte;
public static final fun min-QwZRm1k ([J)Lkotlin/ULong;
public static final fun min-rL5Bavg ([S)Lkotlin/UShort;
public static final fun minOrNull--ajY-9A ([I)Lkotlin/UInt;
public static final fun minOrNull-GBYM_sE ([B)Lkotlin/UByte;
public static final fun minOrNull-QwZRm1k ([J)Lkotlin/ULong;
public static final fun minOrNull-rL5Bavg ([S)Lkotlin/UShort;
public static final fun minWith-XMRcp5o ([BLjava/util/Comparator;)Lkotlin/UByte;
public static final fun minWith-YmdZ_VM ([ILjava/util/Comparator;)Lkotlin/UInt;
public static final fun minWith-eOHTfZs ([SLjava/util/Comparator;)Lkotlin/UShort;
...
...
@@ -4838,11 +4872,17 @@ public final class kotlin/sequences/SequencesKt {
public static final fun max (Lkotlin/sequences/Sequence;)Ljava/lang/Double;
public static final fun max (Lkotlin/sequences/Sequence;)Ljava/lang/Float;
public static final fun maxBy (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun maxOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Comparable;
public static final fun maxOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Double;
public static final fun maxOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Float;
public static final fun maxWith (Lkotlin/sequences/Sequence;Ljava/util/Comparator;)Ljava/lang/Object;
public static final fun min (Lkotlin/sequences/Sequence;)Ljava/lang/Comparable;
public static final fun min (Lkotlin/sequences/Sequence;)Ljava/lang/Double;
public static final fun min (Lkotlin/sequences/Sequence;)Ljava/lang/Float;
public static final fun minBy (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun minOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Comparable;
public static final fun minOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Double;
public static final fun minOrNull (Lkotlin/sequences/Sequence;)Ljava/lang/Float;
public static final fun minWith (Lkotlin/sequences/Sequence;Ljava/util/Comparator;)Ljava/lang/Object;
public static final fun minus (Lkotlin/sequences/Sequence;Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
public static final fun minus (Lkotlin/sequences/Sequence;Ljava/lang/Object;)Lkotlin/sequences/Sequence;
...
...
@@ -5241,9 +5281,11 @@ public final class kotlin/text/StringsKt {
public static final fun mapTo (Ljava/lang/CharSequence;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/util/Collection;
public static final fun max (Ljava/lang/CharSequence;)Ljava/lang/Character;
public static final fun maxBy (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Character;
public static final fun maxOrNull (Ljava/lang/CharSequence;)Ljava/lang/Character;
public static final fun maxWith (Ljava/lang/CharSequence;Ljava/util/Comparator;)Ljava/lang/Character;
public static final fun min (Ljava/lang/CharSequence;)Ljava/lang/Character;
public static final fun minBy (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/Character;
public static final fun minOrNull (Ljava/lang/CharSequence;)Ljava/lang/Character;
public static final fun minWith (Ljava/lang/CharSequence;Ljava/util/Comparator;)Ljava/lang/Character;
public static final fun none (Ljava/lang/CharSequence;)Z
public static final fun none (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Z
...
...
libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt
浏览文件 @
846a7823
...
...
@@ -306,11 +306,11 @@ object Aggregates : TemplateGroupBase() {
}
val
f_minMax
=
run
{
val
f_minMax
=
sequence
{
val
genericSpecializations
=
PrimitiveType
.
floatingPointPrimitives
+
setOf
(
null
)
listOf
(
"min"
,
"max"
).
map
{
op
->
fn
(
"$op()"
)
{
fun
def
(
op
:
String
,
nullable
:
Boolean
,
orNull
:
String
=
"OrNull"
.
ifOrEmpty
(
nullable
))
=
fn
(
"$op
$orNull
()"
)
{
include
(
Iterables
,
genericSpecializations
)
include
(
Sequences
,
genericSpecializations
)
include
(
ArraysOfObjects
,
genericSpecializations
)
...
...
@@ -318,19 +318,30 @@ object Aggregates : TemplateGroupBase() {
include
(
ArraysOfUnsigned
)
include
(
CharSequences
)
}
builder
{
typeParam
(
"T : Comparable<T>"
)
returns
(
"T?"
)
val
isFloat
=
primitive
?.
isFloatingPoint
()
==
true
val
isGeneric
=
f
in
listOf
(
Iterables
,
Sequences
,
ArraysOfObjects
)
typeParam
(
"T : Comparable<T>"
)
if
(
primitive
!=
null
)
{
if
(
isFloat
&&
isGeneric
)
if
(!
nullable
)
{
deprecate
(
Deprecation
(
"Use ${op}OrNull instead."
,
"${op}OrNull()"
,
DeprecationLevel
.
WARNING
))
val
isGeneric
=
f
in
listOf
(
Iterables
,
Sequences
,
ArraysOfObjects
)
if
(
isFloat
&&
isGeneric
)
{
since
(
"1.1"
)
}
body
{
"return ${op}OrNull()"
}
return
@builder
}
since
(
"1.4"
)
doc
{
"Returns the ${if (op == "
max
") "
largest
" else "
smallest
"} ${f.element} or `null` if there are no ${f.element.pluralize()}."
+
if
(
isFloat
)
"\n\n"
+
"If any of ${f.element.pluralize()} is `NaN` returns `NaN`."
else
""
}
returns
(
"T?"
)
val
acc
=
op
val
cmpBlock
=
if
(
isFloat
)
...
...
@@ -361,7 +372,10 @@ object Aggregates : TemplateGroupBase() {
"""
}
}
}
for
(
op
in
listOf
(
"min"
,
"max"
))
for
(
nullable
in
listOf
(
false
,
true
))
yield
(
def
(
op
,
nullable
))
}
val
f_minBy
=
fn
(
"minBy(selector: (T) -> R)"
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录