library changes after collections mapping

This commit is contained in:
Svetlana Isakova
2012-09-04 16:52:43 +04:00
parent 7c828b9ff7
commit 8b749084b5
75 changed files with 222 additions and 268 deletions
@@ -1,6 +1,5 @@
package kotlin
import java.util.List
import java.util.AbstractList
private class ImmutableArrayList<T>(
@@ -37,7 +36,7 @@ private class ImmutableArrayList<T>(
public override fun size() : Int = length
public override fun subList(fromIndex: Int, toIndex: Int) : List<T> {
public override fun subList(fromIndex: Int, toIndex: Int) : MutableList<T> {
if (fromIndex < 0) {
throw IndexOutOfBoundsException("Negative from index ($fromIndex)")
}
@@ -48,7 +47,7 @@ private class ImmutableArrayList<T>(
throw IndexOutOfBoundsException("fromIndex ($fromIndex) + toIndex ($toIndex) > length ($length)")
}
if (fromIndex == toIndex) {
return emptyImmutableArrayList as List<T>
return emptyImmutableArrayList as MutableList<T>
}
if (fromIndex == 0 && toIndex == length) {
return this
@@ -70,7 +70,7 @@ public inline fun <T> Iterable<T>.find(predicate: (T) -> Boolean) : T? {
*
* @includeFunctionBody ../../test/CollectionTest.kt filterIntoLinkedList
*/
public inline fun <T, C: Collection<in T>> Iterable<T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
public inline fun <T, C: MutableCollection<in T>> Iterable<T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (predicate(element)) result.add(element)
return result
}
@@ -80,7 +80,7 @@ public inline fun <T, C: Collection<in T>> Iterable<T>.filterTo(result: C, predi
*
* @includeFunctionBody ../../test/CollectionTest.kt filterNotIntoLinkedList
*/
public inline fun <T, C: Collection<in T>> Iterable<T>.filterNotTo(result: C, predicate: (T) -> Boolean) : C {
public inline fun <T, C: MutableCollection<in T>> Iterable<T>.filterNotTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (!predicate(element)) result.add(element)
return result
}
@@ -90,7 +90,7 @@ public inline fun <T, C: Collection<in T>> Iterable<T>.filterNotTo(result: C, pr
*
* @includeFunctionBody ../../test/CollectionTest.kt filterNotNullIntoLinkedList
*/
public inline fun <T, C: Collection<in T>> Iterable<T?>?.filterNotNullTo(result: C) : C {
public inline fun <T, C: MutableCollection<in T>> Iterable<T?>?.filterNotNullTo(result: C) : C {
if (this != null) {
for (element in this) if (element != null) result.add(element)
}
@@ -102,7 +102,7 @@ public inline fun <T, C: Collection<in T>> Iterable<T?>?.filterNotNullTo(result:
*
* @includeFunctionBody ../../test/CollectionTest.kt flatMap
*/
public inline fun <T, R> Iterable<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> {
public inline fun <T, R> Iterable<T>.flatMapTo(result: MutableCollection<R>, transform: (T) -> Collection<R>) : Collection<R> {
for (element in this) {
val list = transform(element)
if (list != null) {
@@ -172,14 +172,14 @@ public inline fun <T> Iterable<T>.reduceRight(operation: (T, T) -> T): T = rever
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <T, K> Iterable<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> = groupByTo<T,K>(HashMap<K, List<T>>(), toKey)
public inline fun <T, K> Iterable<T>.groupBy(toKey: (T) -> K) : Map<K, MutableList<T>> = groupByTo<T,K>(HashMap<K, MutableList<T>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <T, K> Iterable<T>.groupByTo(result: Map<K, List<T>>, toKey: (T) -> K) : Map<K, List<T>> {
public inline fun <T, K> Iterable<T>.groupByTo(result: MutableMap<K, MutableList<T>>, toKey: (T) -> K) : Map<K, MutableList<T>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<T>() }
@@ -203,7 +203,7 @@ public inline fun <T> Iterable<T>.makeString(separator: String = ", ", prefix: S
}
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
public inline fun <T, L: List<in T>> Iterable<T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
public inline fun <T, L: MutableList<in T>> Iterable<T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
var start = true
for (element in this) {
if (start && predicate(element)) {
@@ -217,13 +217,13 @@ public inline fun <T, L: List<in T>> Iterable<T>.dropWhileTo(result: L, predicat
}
/** Returns a list containing the first elements that satisfy the given *predicate* */
public inline fun <T, C: Collection<in T>> Iterable<T>.takeWhileTo(result: C, predicate: (T) -> Boolean) : C {
public inline fun <T, C: MutableCollection<in T>> Iterable<T>.takeWhileTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (predicate(element)) result.add(element) else break
return result
}
/** Copies all elements into the given collection */
public inline fun <in T, C: Collection<in T>> Iterable<T>.toCollection(result: C) : C {
public inline fun <in T, C: MutableCollection<in T>> Iterable<T>.toCollection(result: C) : C {
for (element in this) result.add(element)
return result
}
@@ -1,8 +1,6 @@
package kotlin
import java.util.ArrayList
import java.util.Collection
import java.util.List
//
// This file contains methods which could have a lazy implementation for things like
@@ -1,8 +1,6 @@
package kotlin
// Number of extension function for java.lang.Iterable that shouldn't participate in auto generation
import java.util.Collection
import java.util.List
import java.util.AbstractList
import java.util.Comparator
import java.util.ArrayList
@@ -59,7 +57,7 @@ public inline fun <T> Iterable<T>.first() : T {
// TODO: Specify type of the exception
public fun <T> Iterable<T>.last() : T {
if (this is List<T>) {
return this.get(this.size() - 1);
return this.get(this.size() - 1)
}
val iterator = this.iterator().sure()
@@ -98,7 +96,7 @@ public fun <T> Iterable<T>.contains(item : T) : Boolean {
*
* @includeFunctionBody ../../test/ListTest.kt withIndices
*/
public fun <T> Iterable<T>.withIndices(): java.util.List<#(Int, T)> {
public fun <T> Iterable<T>.withIndices(): List<#(Int, T)> {
val answer = ArrayList<#(Int, T)>()
var nextIndex = 0
for (e in this) {
@@ -1,10 +1,7 @@
package kotlin
import java.util.AbstractList
import java.util.Collection
import java.util.Comparator
import java.util.Iterator
import java.util.List
// TODO this function is here as it breaks the JS compiler; lets move back to JLangIterablesSpecial when it works again :)
@@ -15,7 +12,7 @@ import java.util.List
*
* @includeFunctionBody ../../test/CollectionTest.kt sortBy
*/
public inline fun <in T, R: Comparable<in R>> Iterable<T>.sortBy(f: (T) -> R): java.util.List<T> {
public inline fun <in T, R: Comparable<in R>> Iterable<T>.sortBy(f: (T) -> R): List<T> {
val sortedList = this.toList()
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) ->
val xr = f(x)
+5 -5
View File
@@ -19,7 +19,7 @@ val Int.indices: IntRange
/**
* Converts the collection to an array
*/
public inline fun <T> java.util.Collection<T>.toArray() : Array<T> {
public inline fun <T> Collection<T>.toArray() : Array<T> {
val answer = arrayOfNulls<T>(this.size)
var idx = 0
for (elem in this)
@@ -28,10 +28,10 @@ public inline fun <T> java.util.Collection<T>.toArray() : Array<T> {
}
/** Returns true if the collection is not empty */
public inline fun <T> java.util.Collection<T>.notEmpty() : Boolean = !this.isEmpty()
public inline fun <T> Collection<T>.notEmpty() : Boolean = !this.isEmpty()
/** Returns the Collection if its not null otherwise it returns the empty list */
public inline fun <T> java.util.Collection<T>?.orEmpty() : Collection<T>
public inline fun <T> Collection<T>?.orEmpty() : Collection<T>
= if (this != null) this else Collections.emptyList<T>() as Collection<T>
@@ -44,8 +44,8 @@ public inline fun <in T: Comparable<T>> Iterable<T>.toSortedList(comparator: jav
// List APIs
/** Returns the List if its not null otherwise returns the empty list */
public inline fun <T> java.util.List<T>?.orEmpty() : java.util.List<T>
= if (this != null) this else Collections.emptyList<T>() as java.util.List<T>
public inline fun <T> List<T>?.orEmpty() : List<T>
= if (this != null) this else Collections.emptyList<T>() as List<T>
/**
TODO figure out necessary variance/generics ninja stuff... :)
@@ -13,7 +13,7 @@ import java.util.*
* Transforms each element of this collection with the given *transform* function and
* adds each return value to the given *results* collection
*/
public inline fun <T, R, C: Collection<in R>> java.util.Collection<T>.mapTo(result: C, transform : (T) -> R) : C {
public inline fun <T, R, C: MutableCollection<in R>> Collection<T>.mapTo(result: C, transform : (T) -> R) : C {
for (item in this)
result.add(transform(item))
return result
@@ -14,6 +14,6 @@ import java.util.*
*
* @includeFunctionBody ../../test/CollectionTest.kt map
*/
public inline fun <T, R> java.util.Collection<T>.map(transform : (T) -> R) : java.util.List<R> {
public inline fun <T, R> Collection<T>.map(transform : (T) -> R) : List<R> {
return mapTo(java.util.ArrayList<R>(this.size), transform)
}
+2 -2
View File
@@ -75,8 +75,8 @@ public inline fun <K,V> linkedMap(vararg values: #(K,V)): LinkedHashMap<K,V> {
/** Returns the Set if its not null otherwise returns the empty set */
public inline fun <T> java.util.Set<T>?.orEmpty() : java.util.Set<T>
= if (this != null) this else Collections.EMPTY_SET as java.util.Set<T>
public inline fun <T> Set<T>?.orEmpty() : Set<T>
= if (this != null) this else Collections.EMPTY_SET as Set<T>
/** Returns a new ArrayList with a variable number of initial elements */
public inline fun arrayList<T>(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size))
+12 -16
View File
@@ -1,28 +1,24 @@
package kotlin
import java.util.Collection
import java.util.Collections
import java.util.HashMap
import java.util.List
import java.util.Map as JMap
import java.util.Map
// Map APIs
/** Returns the size of the map */
val JMap<*,*>.size : Int
val Map<*,*>.size : Int
get() = size()
/** Returns true if this map is empty */
val JMap<*,*>.empty : Boolean
val Map<*,*>.empty : Boolean
get() = isEmpty()
/** Provides [] access to maps */
public fun <K, V> JMap<K, V>.set(key : K, value : V) : V? = this.put(key, value)
public fun <K, V> MutableMap<K, V>.set(key : K, value : V) : V? = this.put(key, value)
/** Returns the [[Map]] if its not null otherwise it returns the empty [[Map]] */
public inline fun <K,V> java.util.Map<K,V>?.orEmpty() : java.util.Map<K,V>
= if (this != null) this else Collections.emptyMap<K,V>() as java.util.Map<K,V>
public inline fun <K,V> Map<K,V>?.orEmpty() : Map<K,V>
= if (this != null) this else Collections.emptyMap<K,V>() as Map<K,V>
/** Returns the key of the entry */
@@ -38,7 +34,7 @@ val <K,V> Map.Entry<K,V>.value : V
*
* @includeFunctionBody ../../test/MapTest.kt getOrElse
*/
public inline fun <K,V> java.util.Map<K,V>.getOrElse(key: K, defaultValue: ()-> V) : V {
public inline fun <K,V> Map<K,V>.getOrElse(key: K, defaultValue: ()-> V) : V {
val current = this.get(key)
if (current != null) {
return current
@@ -52,7 +48,7 @@ public inline fun <K,V> java.util.Map<K,V>.getOrElse(key: K, defaultValue: ()->
*
* @includeFunctionBody ../../test/MapTest.kt getOrElse
*/
public inline fun <K,V> java.util.Map<K,V>.getOrPut(key: K, defaultValue: ()-> V) : V {
public inline fun <K,V> MutableMap<K,V>.getOrPut(key: K, defaultValue: ()-> V) : V {
val current = this.get(key)
if (current != null) {
return current
@@ -69,7 +65,7 @@ public inline fun <K,V> java.util.Map<K,V>.getOrPut(key: K, defaultValue: ()-> V
*
* @includeFunctionBody ../../test/MapTest.kt iterateWithProperties
*/
public inline fun <K,V> java.util.Map<K,V>.iterator(): Iterator<java.util.Map.Entry<K,V>> {
public inline fun <K,V> Map<K,V>.iterator(): Iterator<Map.Entry<K,V>> {
val entrySet = this.entrySet()!!
return entrySet.iterator()!!
}
@@ -78,7 +74,7 @@ public inline fun <K,V> java.util.Map<K,V>.iterator(): Iterator<java.util.Map.En
* Transforms each [[Map.Entry]] in this [[Map]] with the given *transform* function and
* adds each return value to the given *results* collection
*/
public inline fun <K,V,R, C: Collection<in R>> java.util.Map<K,V>.mapTo(result: C, transform: (java.util.Map.Entry<K,V>) -> R) : C {
public inline fun <K,V,R, C: MutableCollection<in R>> Map<K,V>.mapTo(result: C, transform: (Map.Entry<K,V>) -> R) : C {
for (item in this)
result.add(transform(item))
return result
@@ -87,7 +83,7 @@ public inline fun <K,V,R, C: Collection<in R>> java.util.Map<K,V>.mapTo(result:
/**
* Populates the given *result* [[Map]] with the value returned by applying the *transform* function on each [[Map.Entry]] in this [[Map]]
*/
public inline fun <K,V,R,C: java.util.Map<K,R>> java.util.Map<K,V>.mapValuesTo(result: C, transform : (java.util.Map.Entry<K,V>) -> R) : C {
public inline fun <K,V,R,C: MutableMap<K,R>> MutableMap<K,V>.mapValuesTo(result: C, transform : (Map.Entry<K,V>) -> R) : C {
for (e in this) {
val newValue = transform(e)
result.put(e.key, newValue)
@@ -98,7 +94,7 @@ public inline fun <K,V,R,C: java.util.Map<K,R>> java.util.Map<K,V>.mapValuesTo(r
/**
* Puts all the entries into the map with the first value in the tuple being the key and the second the value
*/
public inline fun <K,V> java.util.Map<K,V>.putAll(vararg values: #(K,V)): Unit {
public inline fun <K,V> MutableMap<K,V>.putAll(vararg values: #(K,V)): Unit {
for (v in values) {
put(v._1, v._2)
}
@@ -107,7 +103,7 @@ public inline fun <K,V> java.util.Map<K,V>.putAll(vararg values: #(K,V)): Unit {
/**
* Copies the entries in this [[Map]] to the given *map*
*/
public inline fun <K,V> java.util.Map<K,V>.toMap(map: Map<K,V>): Map<K,V> {
public inline fun <K,V> Map<K,V>.toMap(map: MutableMap<K,V>): Map<K,V> {
map.putAll(this)
return map
}
+5 -8
View File
@@ -2,9 +2,6 @@ package kotlin
import java.util.Comparator
import java.util.LinkedHashMap
import java.util.Map as JMap
import java.util.Map
import java.util.Map.Entry as JEntry
import java.util.SortedMap
import java.util.TreeMap
import java.util.Properties
@@ -14,14 +11,14 @@ import java.util.Properties
/**
* Converts this [[Map]] to a [[LinkedHashMap]] so future insertion orders are maintained
*/
public inline fun <K,V> java.util.Map<K,V>.toLinkedMap(): LinkedHashMap<K,V> = toMap<K,V>(LinkedHashMap(size)) as LinkedHashMap<K,V>
public inline fun <K,V> Map<K,V>.toLinkedMap(): LinkedHashMap<K,V> = toMap<K,V>(LinkedHashMap(size)) as LinkedHashMap<K,V>
/**
* Converts this [[Map]] to a [[SortedMap]] so iteration order will be in key order
*
* @includeFunctionBody ../../test/MapTest.kt toSortedMap
*/
public inline fun <K,V> java.util.Map<K,V>.toSortedMap(): SortedMap<K,V> = toMap<K,V>(TreeMap()) as SortedMap<K,V>
public inline fun <K,V> Map<K,V>.toSortedMap(): SortedMap<K,V> = toMap<K,V>(TreeMap()) as SortedMap<K,V>
/**
* Converts this [[Map]] to a [[SortedMap]] using the given *comparator* so that iteration order will be in the order
@@ -29,7 +26,7 @@ public inline fun <K,V> java.util.Map<K,V>.toSortedMap(): SortedMap<K,V> = toMap
*
* @includeFunctionBody ../../test/MapTest.kt toSortedMapWithComparator
*/
public inline fun <K,V> java.util.Map<K,V>.toSortedMap(comparator: Comparator<K>): SortedMap<K,V> = toMap<K,V>(TreeMap(comparator)) as SortedMap<K,V>
public inline fun <K,V> Map<K,V>.toSortedMap(comparator: Comparator<K>): SortedMap<K,V> = toMap<K,V>(TreeMap(comparator)) as SortedMap<K,V>
/**
@@ -50,7 +47,7 @@ public inline fun Map<String, String>.toProperties(): Properties {
*
* @includeFunctionBody ../../test/CollectionTest.kt map
*/
public inline fun <K,V,R> java.util.Map<K,V>.map(transform: (java.util.Map.Entry<K,V>) -> R) : java.util.List<R> {
public inline fun <K,V,R> Map<K,V>.map(transform: (Map.Entry<K,V>) -> R) : List<R> {
return mapTo(java.util.ArrayList<R>(this.size), transform)
}
@@ -60,7 +57,7 @@ public inline fun <K,V,R> java.util.Map<K,V>.map(transform: (java.util.Map.Entry
*
* @includeFunctionBody ../../test/MapTest.kt mapValues
*/
public inline fun <K,V,R> java.util.Map<K,V>.mapValues(transform : (java.util.Map.Entry<K,V>) -> R): java.util.Map<K,R> {
public inline fun <K,V,R> MutableMap<K,V>.mapValues(transform : (Map.Entry<K,V>) -> R): Map<K,R> {
return mapValuesTo(java.util.HashMap<K,R>(this.size), transform)
}
-1
View File
@@ -1,7 +1,6 @@
package kotlin
import java.util.ArrayList
import java.util.Collection
import java.util.HashSet
import java.util.LinkedList
@@ -1,6 +1,5 @@
package kotlin
import java.util.Collection
import java.util.ArrayList
import java.util.LinkedList
import java.util.HashSet
-1
View File
@@ -1,6 +1,5 @@
package kotlin
import java.util.List
import java.util.ArrayList
/** Returns the string with leading and trailing text matching the given string removed */
@@ -1,7 +1,6 @@
package kotlin
import java.io.StringReader
import java.util.List
public inline fun String.lastIndexOf(str: String) : Int = (this as java.lang.String).lastIndexOf(str)
+1 -1
View File
@@ -118,7 +118,7 @@ fun Node.nextElements(): Iterator<Element> = nextSiblings().filterIsInstance<Nod
fun Node.previousElements(): Iterator<Element> = previousSiblings().filterIsInstance<Node, Element>(javaClass<Element>())
var Element.classSet : Set<String>
var Element.classSet : MutableSet<String>
get() {
val answer = LinkedHashSet<String>()
val array = this.classes.split("""\s""")
-1
View File
@@ -3,7 +3,6 @@ package kotlin.io
import java.io.*
import java.nio.charset.*
import java.util.NoSuchElementException
import java.util.List
import java.util.ArrayList
import java.net.URL
@@ -54,9 +54,9 @@ open class ModuleBuilder(val name: String): Module {
annotationsRoots0.add(name)
}
public override fun getSourceFiles(): List<String?>? = sourceFiles0
public override fun getClasspathRoots(): List<String?>? = classpathRoots0
public override fun getAnnotationsRoots(): List<String?>? = annotationsRoots0
public override fun getSourceFiles(): MutableList<String?>? = sourceFiles0
public override fun getClasspathRoots(): MutableList<String?>? = classpathRoots0
public override fun getAnnotationsRoots(): MutableList<String?>? = annotationsRoots0
public override fun getModuleName(): String? = name
}
@@ -26,7 +26,7 @@ public inline fun <T> T?.find(predicate: (T)-> Boolean): T? {
public inline fun <T> T?.filter(predicate: (T)-> Boolean): T? = find(predicate)
/** Filters all elements in this collection which match the given predicate into the given result collection */
public inline fun <T, C: Collection<in T>> T?.filterTo(result: C, predicate: (T)-> Boolean): C {
public inline fun <T, C: MutableCollection<in T>> T?.filterTo(result: C, predicate: (T)-> Boolean): C {
if (this != null && predicate(this))
result.add(this)
return result
@@ -36,7 +36,7 @@ public inline fun <T, C: Collection<in T>> T?.filterTo(result: C, predicate: (T)
public inline fun <T> T?.filterNotNull(): Collection<T> = filterNotNullTo(java.util.ArrayList<T>())
/** Filters all the null elements in this collection winto the given result collection */
public inline fun <T, C: Collection<in T>> T?.filterNotNullTo(result: C): C {
public inline fun <T, C: MutableCollection<in T>> T?.filterNotNullTo(result: C): C {
if (this != null) {
result.add(this)
}
@@ -47,7 +47,7 @@ public inline fun <T, C: Collection<in T>> T?.filterNotNullTo(result: C): C {
public inline fun <T> T?.filterNot(predicate: (T)-> Boolean): Collection<T> = filterNotTo(ArrayList<T>(), predicate)
/** Returns a new collection containing all elements in this collection which do not match the given predicate */
public inline fun <T, C: Collection<in T>> T?.filterNotTo(result: C, predicate: (T)-> Boolean): C {
public inline fun <T, C: MutableCollection<in T>> T?.filterNotTo(result: C, predicate: (T)-> Boolean): C {
if (this != null && !predicate(this)) {
result.add(this)
}
@@ -58,7 +58,7 @@ public inline fun <T, C: Collection<in T>> T?.filterNotTo(result: C, predicate:
* Returns the result of transforming each item in the collection to a one or more values which
* are concatenated together into a single collection
*/
public inline fun <T, R> T?.flatMap(transform: (T)-> Collection<R>): Collection<R> {
public inline fun <T, R> T?.flatMap(transform: (T)-> MutableCollection<R>): Collection<R> {
return flatMapTo(ArrayList<R>(), transform)
}
@@ -66,7 +66,7 @@ public inline fun <T, R> T?.flatMap(transform: (T)-> Collection<R>): Collection<
* Returns the result of transforming each item in the collection to a one or more values which
* are concatenated together into a single collection
*/
public inline fun <T, R> T?.flatMapTo(result: Collection<R>, transform: (T)-> Collection<R>): Collection<R> {
public inline fun <T, R> T?.flatMapTo(result: MutableCollection<R>, transform: (T)-> MutableCollection<R>): Collection<R> {
if (this != null) {
val coll = transform(this)
if (coll != null) {
@@ -111,7 +111,7 @@ public inline fun <T> T?.foldRight(initial: T, operation: (it: T, it2: T) -> T):
* Iterates through the collection performing the transformation on each element and using the result
* as the key in a map to group elements by the result
*/
public inline fun <T, K> T?.groupBy(result: Map<K, List<T>> = HashMap<K, List<T>>(), toKey: (T)-> K): Map<K, List<T>> {
public inline fun <T, K> T?.groupBy(result: MutableMap<K, MutableList<T>> = HashMap<K, MutableList<T>>(), toKey: (T)-> K): Map<K, MutableList<T>> {
if (this != null) {
val key = toKey(this)
val list = result.getOrPut(key){ ArrayList<T>() }
@@ -143,7 +143,7 @@ public inline fun <T, R> T?.map(transform : (T) -> R) : R? {
}
/** Transforms each element of this collection with the given function then adds the results to the given collection */
public inline fun <T, R, C: Collection<in R>> T?.mapTo(result: C, transform : (T) -> R) : C {
public inline fun <T, R, C: MutableCollection<in R>> T?.mapTo(result: C, transform : (T) -> R) : C {
if (this != null) {
result.add(transform(this))
}
@@ -156,7 +156,7 @@ public inline fun <T> T?.reverse(): T? {
}
/** Copies the collection into the given collection */
public inline fun <T, C: Collection<T>> T?.toCollection(result: C): C {
public inline fun <T, C: MutableCollection<T>> T?.toCollection(result: C): C {
if (this != null)
result.add(this)
return result
@@ -2,8 +2,6 @@ package kotlin.properties
import kotlin.*
import kotlin.util.*
import java.util.List
import java.util.Map
import java.util.HashMap
import java.util.ArrayList
@@ -23,8 +21,8 @@ public trait ChangeListener {
* change tracking mechanisms for persistence or distributed change notifications.
*/
public abstract class ChangeSupport {
private var allListeners: List<ChangeListener>? = null
private var nameListeners: Map<String, List<ChangeListener>>? = null
private var allListeners: MutableList<ChangeListener>? = null
private var nameListeners: MutableMap<String, MutableList<ChangeListener>>? = null
public fun addChangeListener(listener: ChangeListener) {
@@ -36,7 +34,7 @@ public abstract class ChangeSupport {
public fun addChangeListener(name: String, listener: ChangeListener) {
if (nameListeners == null) {
nameListeners = HashMap<String, List<ChangeListener>>()
nameListeners = HashMap<String, MutableList<ChangeListener>>()
}
var listeners = nameListeners?.get(name)
if (listeners == null) {