Merge stored empty lists and sets to singe object

This commit is contained in:
Nikolay Krasko
2014-11-02 01:15:07 +03:00
parent 87d372aad5
commit 7e1546d3e7
6 changed files with 28 additions and 19 deletions
@@ -20,6 +20,7 @@ import java.util.LinkedHashMap
import java.util.ArrayList
import java.util.HashMap
import java.util.HashSet
import java.util.Collections
public fun <K, V> Stream<V>.valuesToMap(key: (V) -> K): Map<K, V> {
val map = LinkedHashMap<K, V>()
@@ -94,3 +95,9 @@ public fun <K, V> newHashMapWithExpectedSize(expectedSize: Int): HashMap<K, V> {
public fun <E> newHashSetWithExpectedSize(expectedSize: Int): HashSet<E> {
return HashSet(if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1)
}
public fun <T> Collection<T>.toReadOnlyList(): List<T> =
if (isEmpty()) Collections.emptyList() else ArrayList(this)
public fun <T> Collection<T>.toReadOnlySet(): Set<T> =
if (isEmpty()) Collections.emptySet() else HashSet(this)