Use LinkedHashMap everywhere to preserve order.

This commit is contained in:
Ilya Ryzhenkov
2014-06-11 18:10:46 +04:00
parent cb17f0c635
commit a9da7cfeea
8 changed files with 57 additions and 66 deletions
+12 -12
View File
@@ -245,84 +245,84 @@ public inline fun <T, R, C : MutableCollection<in R>> Stream<T>.flatMapTo(destin
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <T, K> Array<out T>.groupBy(toKey: (T) -> K): Map<K, List<T>> {
return groupByTo(HashMap<K, MutableList<T>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<T>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <K> BooleanArray.groupBy(toKey: (Boolean) -> K): Map<K, List<Boolean>> {
return groupByTo(HashMap<K, MutableList<Boolean>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<Boolean>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <K> ByteArray.groupBy(toKey: (Byte) -> K): Map<K, List<Byte>> {
return groupByTo(HashMap<K, MutableList<Byte>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<Byte>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <K> CharArray.groupBy(toKey: (Char) -> K): Map<K, List<Char>> {
return groupByTo(HashMap<K, MutableList<Char>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<Char>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <K> DoubleArray.groupBy(toKey: (Double) -> K): Map<K, List<Double>> {
return groupByTo(HashMap<K, MutableList<Double>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<Double>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <K> FloatArray.groupBy(toKey: (Float) -> K): Map<K, List<Float>> {
return groupByTo(HashMap<K, MutableList<Float>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<Float>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <K> IntArray.groupBy(toKey: (Int) -> K): Map<K, List<Int>> {
return groupByTo(HashMap<K, MutableList<Int>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<Int>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <K> LongArray.groupBy(toKey: (Long) -> K): Map<K, List<Long>> {
return groupByTo(HashMap<K, MutableList<Long>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<Long>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <K> ShortArray.groupBy(toKey: (Short) -> K): Map<K, List<Short>> {
return groupByTo(HashMap<K, MutableList<Short>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<Short>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <T, K> Iterable<T>.groupBy(toKey: (T) -> K): Map<K, List<T>> {
return groupByTo(HashMap<K, MutableList<T>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<T>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <T, K> Stream<T>.groupBy(toKey: (T) -> K): Map<K, List<T>> {
return groupByTo(HashMap<K, MutableList<T>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<T>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
*/
public inline fun <K> String.groupBy(toKey: (Char) -> K): Map<K, List<Char>> {
return groupByTo(HashMap<K, MutableList<Char>>(), toKey)
return groupByTo(LinkedHashMap<K, MutableList<Char>>(), toKey)
}
/**
+12 -12
View File
@@ -511,7 +511,7 @@ public fun String.toList(): List<Char> {
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <T, K> Array<out T>.toMap(selector: (T) -> K): Map<K, T> {
val result = HashMap<K, T>()
val result = LinkedHashMap<K, T>()
for (element in this) {
result.put(selector(element), element)
}
@@ -522,7 +522,7 @@ public inline fun <T, K> Array<out T>.toMap(selector: (T) -> K): Map<K, T> {
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <K> BooleanArray.toMap(selector: (Boolean) -> K): Map<K, Boolean> {
val result = HashMap<K, Boolean>()
val result = LinkedHashMap<K, Boolean>()
for (element in this) {
result.put(selector(element), element)
}
@@ -533,7 +533,7 @@ public inline fun <K> BooleanArray.toMap(selector: (Boolean) -> K): Map<K, Boole
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <K> ByteArray.toMap(selector: (Byte) -> K): Map<K, Byte> {
val result = HashMap<K, Byte>()
val result = LinkedHashMap<K, Byte>()
for (element in this) {
result.put(selector(element), element)
}
@@ -544,7 +544,7 @@ public inline fun <K> ByteArray.toMap(selector: (Byte) -> K): Map<K, Byte> {
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <K> CharArray.toMap(selector: (Char) -> K): Map<K, Char> {
val result = HashMap<K, Char>()
val result = LinkedHashMap<K, Char>()
for (element in this) {
result.put(selector(element), element)
}
@@ -555,7 +555,7 @@ public inline fun <K> CharArray.toMap(selector: (Char) -> K): Map<K, Char> {
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <K> DoubleArray.toMap(selector: (Double) -> K): Map<K, Double> {
val result = HashMap<K, Double>()
val result = LinkedHashMap<K, Double>()
for (element in this) {
result.put(selector(element), element)
}
@@ -566,7 +566,7 @@ public inline fun <K> DoubleArray.toMap(selector: (Double) -> K): Map<K, Double>
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <K> FloatArray.toMap(selector: (Float) -> K): Map<K, Float> {
val result = HashMap<K, Float>()
val result = LinkedHashMap<K, Float>()
for (element in this) {
result.put(selector(element), element)
}
@@ -577,7 +577,7 @@ public inline fun <K> FloatArray.toMap(selector: (Float) -> K): Map<K, Float> {
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <K> IntArray.toMap(selector: (Int) -> K): Map<K, Int> {
val result = HashMap<K, Int>()
val result = LinkedHashMap<K, Int>()
for (element in this) {
result.put(selector(element), element)
}
@@ -588,7 +588,7 @@ public inline fun <K> IntArray.toMap(selector: (Int) -> K): Map<K, Int> {
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <K> LongArray.toMap(selector: (Long) -> K): Map<K, Long> {
val result = HashMap<K, Long>()
val result = LinkedHashMap<K, Long>()
for (element in this) {
result.put(selector(element), element)
}
@@ -599,7 +599,7 @@ public inline fun <K> LongArray.toMap(selector: (Long) -> K): Map<K, Long> {
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <K> ShortArray.toMap(selector: (Short) -> K): Map<K, Short> {
val result = HashMap<K, Short>()
val result = LinkedHashMap<K, Short>()
for (element in this) {
result.put(selector(element), element)
}
@@ -610,7 +610,7 @@ public inline fun <K> ShortArray.toMap(selector: (Short) -> K): Map<K, Short> {
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <T, K> Iterable<T>.toMap(selector: (T) -> K): Map<K, T> {
val result = HashMap<K, T>()
val result = LinkedHashMap<K, T>()
for (element in this) {
result.put(selector(element), element)
}
@@ -621,7 +621,7 @@ public inline fun <T, K> Iterable<T>.toMap(selector: (T) -> K): Map<K, T> {
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <T, K> Stream<T>.toMap(selector: (T) -> K): Map<K, T> {
val result = HashMap<K, T>()
val result = LinkedHashMap<K, T>()
for (element in this) {
result.put(selector(element), element)
}
@@ -632,7 +632,7 @@ public inline fun <T, K> Stream<T>.toMap(selector: (T) -> K): Map<K, T> {
* Returns Map containing all the values from the given collection indexed by *selector*
*/
public inline fun <K> String.toMap(selector: (Char) -> K): Map<K, Char> {
val result = HashMap<K, Char>()
val result = LinkedHashMap<K, Char>()
for (element in this) {
result.put(selector(element), element)
}