Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
e09c0ae2
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,发现更多精彩内容 >>
提交
e09c0ae2
编写于
10月 08, 2015
作者:
I
Ilya Gorbunov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename toMap { selector } to toMapBy.
#KT-6657
上级
fd7b6704
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
168 addition
and
98 deletion
+168
-98
libraries/stdlib/src/generated/_Arrays.kt
libraries/stdlib/src/generated/_Arrays.kt
+117
-72
libraries/stdlib/src/generated/_Collections.kt
libraries/stdlib/src/generated/_Collections.kt
+13
-8
libraries/stdlib/src/generated/_Sequences.kt
libraries/stdlib/src/generated/_Sequences.kt
+13
-8
libraries/stdlib/src/generated/_Strings.kt
libraries/stdlib/src/generated/_Strings.kt
+13
-8
libraries/stdlib/test/collections/MapTest.kt
libraries/stdlib/test/collections/MapTest.kt
+2
-2
libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt
libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt
+10
-0
未找到文件。
libraries/stdlib/src/generated/_Arrays.kt
浏览文件 @
e09c0ae2
...
...
@@ -5514,236 +5514,281 @@ public fun ShortArray.toList(): List<Short> {
return
this
.
toArrayList
()
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
T
,
K
>
Array
<
out
T
>.
toMap
(
selector
:
(
T
)
->
K
):
Map
<
K
,
T
>
{
return
toMapBy
(
selector
)
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
K
>
BooleanArray
.
toMap
(
selector
:
(
Boolean
)
->
K
):
Map
<
K
,
Boolean
>
{
return
toMapBy
(
selector
)
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
K
>
ByteArray
.
toMap
(
selector
:
(
Byte
)
->
K
):
Map
<
K
,
Byte
>
{
return
toMapBy
(
selector
)
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
K
>
CharArray
.
toMap
(
selector
:
(
Char
)
->
K
):
Map
<
K
,
Char
>
{
return
toMapBy
(
selector
)
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
K
>
DoubleArray
.
toMap
(
selector
:
(
Double
)
->
K
):
Map
<
K
,
Double
>
{
return
toMapBy
(
selector
)
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
K
>
FloatArray
.
toMap
(
selector
:
(
Float
)
->
K
):
Map
<
K
,
Float
>
{
return
toMapBy
(
selector
)
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
K
>
IntArray
.
toMap
(
selector
:
(
Int
)
->
K
):
Map
<
K
,
Int
>
{
return
toMapBy
(
selector
)
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
K
>
LongArray
.
toMap
(
selector
:
(
Long
)
->
K
):
Map
<
K
,
Long
>
{
return
toMapBy
(
selector
)
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
K
>
ShortArray
.
toMap
(
selector
:
(
Short
)
->
K
):
Map
<
K
,
Short
>
{
return
toMapBy
(
selector
)
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
T
,
K
>
Array
<
out
T
>.
toMap
(
selector
:
(
T
)
->
K
):
Map
<
K
,
T
>
{
public
inline
fun
<
T
,
K
,
V
>
Array
<
out
T
>.
toMap
(
selector
:
(
T
)
->
K
,
transform
:
(
T
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
T
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
>
BooleanArray
.
toMap
(
selector
:
(
Boolean
)
->
K
):
Map
<
K
,
Boolean
>
{
public
inline
fun
<
K
,
V
>
BooleanArray
.
toMap
(
selector
:
(
Boolean
)
->
K
,
transform
:
(
Boolean
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
Boolean
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
>
ByteArray
.
toMap
(
selector
:
(
Byte
)
->
K
):
Map
<
K
,
Byte
>
{
public
inline
fun
<
K
,
V
>
ByteArray
.
toMap
(
selector
:
(
Byte
)
->
K
,
transform
:
(
Byte
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
Byte
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
>
CharArray
.
toMap
(
selector
:
(
Char
)
->
K
):
Map
<
K
,
Char
>
{
public
inline
fun
<
K
,
V
>
CharArray
.
toMap
(
selector
:
(
Char
)
->
K
,
transform
:
(
Char
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
Char
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
>
DoubleArray
.
toMap
(
selector
:
(
Double
)
->
K
):
Map
<
K
,
Double
>
{
public
inline
fun
<
K
,
V
>
DoubleArray
.
toMap
(
selector
:
(
Double
)
->
K
,
transform
:
(
Double
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
Double
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
>
FloatArray
.
toMap
(
selector
:
(
Float
)
->
K
):
Map
<
K
,
Float
>
{
public
inline
fun
<
K
,
V
>
FloatArray
.
toMap
(
selector
:
(
Float
)
->
K
,
transform
:
(
Float
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
Float
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
>
IntArray
.
toMap
(
selector
:
(
Int
)
->
K
):
Map
<
K
,
Int
>
{
public
inline
fun
<
K
,
V
>
IntArray
.
toMap
(
selector
:
(
Int
)
->
K
,
transform
:
(
Int
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
Int
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
>
LongArray
.
toMap
(
selector
:
(
Long
)
->
K
):
Map
<
K
,
Long
>
{
public
inline
fun
<
K
,
V
>
LongArray
.
toMap
(
selector
:
(
Long
)
->
K
,
transform
:
(
Long
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
Long
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
>
ShortArray
.
toMap
(
selector
:
(
Short
)
->
K
):
Map
<
K
,
Short
>
{
public
inline
fun
<
K
,
V
>
ShortArray
.
toMap
(
selector
:
(
Short
)
->
K
,
transform
:
(
Short
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
Short
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
T
,
K
,
V
>
Array
<
out
T
>.
toMap
(
selector
:
(
T
)
->
K
,
transform
:
(
T
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
T
,
K
>
Array
<
out
T
>.
toMapBy
(
selector
:
(
T
)
->
K
):
Map
<
K
,
T
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
T
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
,
V
>
BooleanArray
.
toMap
(
selector
:
(
Boolean
)
->
K
,
transform
:
(
Boolean
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
K
>
BooleanArray
.
toMapBy
(
selector
:
(
Boolean
)
->
K
):
Map
<
K
,
Boolean
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
Boolean
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
,
V
>
ByteArray
.
toMap
(
selector
:
(
Byte
)
->
K
,
transform
:
(
Byte
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
K
>
ByteArray
.
toMapBy
(
selector
:
(
Byte
)
->
K
):
Map
<
K
,
Byte
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
Byte
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
,
V
>
CharArray
.
toMap
(
selector
:
(
Char
)
->
K
,
transform
:
(
Char
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
K
>
CharArray
.
toMapBy
(
selector
:
(
Char
)
->
K
):
Map
<
K
,
Char
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
Char
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
,
V
>
DoubleArray
.
toMap
(
selector
:
(
Double
)
->
K
,
transform
:
(
Double
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
K
>
DoubleArray
.
toMapBy
(
selector
:
(
Double
)
->
K
):
Map
<
K
,
Double
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
Double
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
,
V
>
FloatArray
.
toMap
(
selector
:
(
Float
)
->
K
,
transform
:
(
Float
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
K
>
FloatArray
.
toMapBy
(
selector
:
(
Float
)
->
K
):
Map
<
K
,
Float
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
Float
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
,
V
>
IntArray
.
toMap
(
selector
:
(
Int
)
->
K
,
transform
:
(
Int
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
K
>
IntArray
.
toMapBy
(
selector
:
(
Int
)
->
K
):
Map
<
K
,
Int
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
Int
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
,
V
>
LongArray
.
toMap
(
selector
:
(
Long
)
->
K
,
transform
:
(
Long
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
K
>
LongArray
.
toMapBy
(
selector
:
(
Long
)
->
K
):
Map
<
K
,
Long
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
Long
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
,
V
>
ShortArray
.
toMap
(
selector
:
(
Short
)
->
K
,
transform
:
(
Short
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
K
>
ShortArray
.
toMapBy
(
selector
:
(
Short
)
->
K
):
Map
<
K
,
Short
>
{
val
capacity
=
(
size
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
Short
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
...
...
libraries/stdlib/src/generated/_Collections.kt
浏览文件 @
e09c0ae2
...
...
@@ -894,28 +894,33 @@ public fun <T> Iterable<T>.toList(): List<T> {
return
this
.
toArrayList
()
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
T
,
K
>
Iterable
<
T
>.
toMap
(
selector
:
(
T
)
->
K
):
Map
<
K
,
T
>
{
return
toMapBy
(
selector
)
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
T
,
K
>
Iterable
<
T
>.
toMap
(
selector
:
(
T
)
->
K
):
Map
<
K
,
T
>
{
public
inline
fun
<
T
,
K
,
V
>
Iterable
<
T
>.
toMap
(
selector
:
(
T
)
->
K
,
transform
:
(
T
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
collectionSizeOrDefault
(
10
)/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
T
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
T
,
K
,
V
>
Iterable
<
T
>.
toMap
(
selector
:
(
T
)
->
K
,
transform
:
(
T
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
T
,
K
>
Iterable
<
T
>.
toMapBy
(
selector
:
(
T
)
->
K
):
Map
<
K
,
T
>
{
val
capacity
=
(
collectionSizeOrDefault
(
10
)/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
T
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
...
...
libraries/stdlib/src/generated/_Sequences.kt
浏览文件 @
e09c0ae2
...
...
@@ -441,26 +441,31 @@ public fun <T> Sequence<T>.toList(): List<T> {
return
this
.
toArrayList
()
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
T
,
K
>
Sequence
<
T
>.
toMap
(
selector
:
(
T
)
->
K
):
Map
<
K
,
T
>
{
return
toMapBy
(
selector
)
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
T
,
K
>
Sequence
<
T
>.
toMap
(
selector
:
(
T
)
->
K
):
Map
<
K
,
T
>
{
val
result
=
LinkedHashMap
<
K
,
T
>()
public
inline
fun
<
T
,
K
,
V
>
Sequence
<
T
>.
toMap
(
selector
:
(
T
)
->
K
,
transform
:
(
T
)
->
V
):
Map
<
K
,
V
>
{
val
result
=
LinkedHashMap
<
K
,
V
>()
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
T
,
K
,
V
>
Sequence
<
T
>.
toMap
(
selector
:
(
T
)
->
K
,
transform
:
(
T
)
->
V
):
Map
<
K
,
V
>
{
val
result
=
LinkedHashMap
<
K
,
V
>()
public
inline
fun
<
T
,
K
>
Sequence
<
T
>.
toMapBy
(
selector
:
(
T
)
->
K
):
Map
<
K
,
T
>
{
val
result
=
LinkedHashMap
<
K
,
T
>()
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
...
...
libraries/stdlib/src/generated/_Strings.kt
浏览文件 @
e09c0ae2
...
...
@@ -386,28 +386,33 @@ public fun String.toList(): List<Char> {
return
this
.
toArrayList
()
}
@Deprecated
(
"Use toMapBy instead."
,
ReplaceWith
(
"toMapBy(selector)"
))
public
inline
fun
<
K
>
String
.
toMap
(
selector
:
(
Char
)
->
K
):
Map
<
K
,
Char
>
{
return
toMapBy
(
selector
)
}
/**
* Returns Map containing the values
from the given collection indexed by [selector]
.
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
>
String
.
toMap
(
selector
:
(
Char
)
->
K
):
Map
<
K
,
Char
>
{
public
inline
fun
<
K
,
V
>
String
.
toMap
(
selector
:
(
Char
)
->
K
,
transform
:
(
Char
)
->
V
):
Map
<
K
,
V
>
{
val
capacity
=
(
length
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
Char
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
element
)
result
.
put
(
selector
(
element
),
transform
(
element
)
)
}
return
result
}
/**
* Returns Map containing the values
provided by [transform] and indexed by [selector] from the given collection
.
* Returns Map containing the values
from the given collection indexed by [selector]
.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public
inline
fun
<
K
,
V
>
String
.
toMap
(
selector
:
(
Char
)
->
K
,
transform
:
(
Char
)
->
V
):
Map
<
K
,
V
>
{
public
inline
fun
<
K
>
String
.
toMapBy
(
selector
:
(
Char
)
->
K
):
Map
<
K
,
Char
>
{
val
capacity
=
(
length
()/
.75f
)
+
1
val
result
=
LinkedHashMap
<
K
,
V
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
val
result
=
LinkedHashMap
<
K
,
Char
>(
Math
.
max
(
capacity
.
toInt
(),
16
))
for
(
element
in
this
)
{
result
.
put
(
selector
(
element
),
transform
(
element
)
)
result
.
put
(
selector
(
element
),
element
)
}
return
result
}
...
...
libraries/stdlib/test/collections/MapTest.kt
浏览文件 @
e09c0ae2
...
...
@@ -160,7 +160,7 @@ class MapTest {
}
@
test
fun
createWithSelector
()
{
val
map
=
listOf
(
"a"
,
"bb"
,
"ccc"
).
toMap
{
it
.
length
()
}
val
map
=
listOf
(
"a"
,
"bb"
,
"ccc"
).
toMap
By
{
it
.
length
()
}
assertEquals
(
3
,
map
.
size
())
assertEquals
(
"a"
,
map
.
get
(
1
))
assertEquals
(
"bb"
,
map
.
get
(
2
))
...
...
@@ -168,7 +168,7 @@ class MapTest {
}
@
test
fun
createWithSelectorAndOverwrite
()
{
val
map
=
listOf
(
"aa"
,
"bb"
,
"ccc"
).
toMap
{
it
.
length
()
}
val
map
=
listOf
(
"aa"
,
"bb"
,
"ccc"
).
toMap
By
{
it
.
length
()
}
assertEquals
(
2
,
map
.
size
())
assertEquals
(
"bb"
,
map
.
get
(
2
))
assertEquals
(
"ccc"
,
map
.
get
(
3
))
...
...
libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt
浏览文件 @
e09c0ae2
...
...
@@ -94,6 +94,16 @@ fun snapshots(): List<GenericFunction> {
}
templates
add
f
(
"toMap(selector: (T) -> K)"
)
{
inline
(
true
)
include
(
Strings
)
typeParam
(
"K"
)
returns
(
"Map<K, T>"
)
deprecate
(
"Use toMapBy instead."
)
deprecateReplacement
(
"toMapBy(selector)"
)
body
(
"return ${deprecateReplacement.default}"
)
}
templates
add
f
(
"toMapBy(selector: (T) -> K)"
)
{
inline
(
true
)
typeParam
(
"K"
)
doc
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录