diff --git a/libraries/stdlib/common/src/kotlin/CollectionsH.kt b/libraries/stdlib/common/src/kotlin/CollectionsH.kt deleted file mode 100644 index 4d6582e9d85..00000000000 --- a/libraries/stdlib/common/src/kotlin/CollectionsH.kt +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin.collections - -open expect class ArrayList : MutableList { - constructor(capacity: Int) - constructor() - constructor(c: Collection) - - fun trimToSize() - fun ensureCapacity(minCapacity: Int) - - // From List - override val size: Int - override fun isEmpty(): Boolean - override fun contains(element: @UnsafeVariance E): Boolean - override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean - override operator fun get(index: Int): E - override fun indexOf(element: @UnsafeVariance E): Int - override fun lastIndexOf(element: @UnsafeVariance E): Int - - // From MutableCollection - override fun iterator(): MutableIterator - - // From MutableList - override fun add(element: E): Boolean - override fun remove(element: E): Boolean - override fun addAll(elements: Collection): Boolean - override fun addAll(index: Int, elements: Collection): Boolean - override fun removeAll(elements: Collection): Boolean - override fun retainAll(elements: Collection): Boolean - override fun clear() - override operator fun set(index: Int, element: E): E - override fun add(index: Int, element: E) - override fun removeAt(index: Int): E - override fun listIterator(): MutableListIterator - override fun listIterator(index: Int): MutableListIterator - override fun subList(fromIndex: Int, toIndex: Int): MutableList -} - -open expect class HashMap : MutableMap { - constructor() - constructor(initialCapacity: Int) - constructor(initialCapacity: Int, loadFactor: Float) - constructor(original: Map) - - // From Map - override val size: Int - override fun isEmpty(): Boolean - override fun containsKey(key: K): Boolean - override fun containsValue(value: @UnsafeVariance V): Boolean - override operator fun get(key: K): V? - - // From MutableMap - override fun put(key: K, value: V): V? - override fun remove(key: K): V? - override fun putAll(from: Map) - override fun clear() - override val keys: MutableSet - override val values: MutableCollection - override val entries: MutableSet> -} - -open expect class LinkedHashMap : HashMap { - constructor() - constructor(initialCapacity: Int) - constructor(initialCapacity: Int, loadFactor: Float) - constructor(original: Map) -} - -open expect class HashSet : MutableSet { - constructor() - constructor(initialCapacity: Int) - constructor(initialCapacity: Int, loadFactor: Float) - constructor(c: Collection) - - // From Set - override val size: Int - override fun isEmpty(): Boolean - override fun contains(element: @UnsafeVariance E): Boolean - override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean - - // From MutableSet - override fun iterator(): MutableIterator - override fun add(element: E): Boolean - override fun remove(element: E): Boolean - override fun addAll(elements: Collection): Boolean - override fun removeAll(elements: Collection): Boolean - override fun retainAll(elements: Collection): Boolean - override fun clear() -} - -open expect class LinkedHashSet : HashSet { - constructor() - constructor(initialCapacity: Int) - constructor(initialCapacity: Int, loadFactor: Float) - constructor(c: Collection) -} - -expect interface RandomAccess - - -expect abstract class AbstractMutableList : MutableList { - protected constructor() - - // From List - override fun isEmpty(): Boolean - override fun contains(element: @UnsafeVariance E): Boolean - override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean - override fun indexOf(element: @UnsafeVariance E): Int - override fun lastIndexOf(element: @UnsafeVariance E): Int - - // From MutableCollection - override fun iterator(): MutableIterator - - // From MutableList - override fun add(element: E): Boolean - override fun remove(element: E): Boolean - override fun addAll(elements: Collection): Boolean - override fun addAll(index: Int, elements: Collection): Boolean - override fun removeAll(elements: Collection): Boolean - override fun retainAll(elements: Collection): Boolean - override fun clear() - override fun listIterator(): MutableListIterator - override fun listIterator(index: Int): MutableListIterator - override fun subList(fromIndex: Int, toIndex: Int): MutableList -} - - -// From collections.kt - -/** Returns the array if it's not `null`, or an empty array otherwise. */ -expect inline fun Array?.orEmpty(): Array - - -expect inline fun Collection.toTypedArray(): Array - -@SinceKotlin("1.2") -expect fun MutableList.fill(value: T): Unit -@SinceKotlin("1.2") -expect fun MutableList.shuffle(): Unit -@SinceKotlin("1.2") -expect fun Iterable.shuffled(): List - -expect fun > MutableList.sort(): Unit -expect fun MutableList.sortWith(comparator: Comparator): Unit - - -// from Grouping.kt -public expect fun Grouping.eachCount(): Map -// public expect inline fun Grouping.eachSumOf(valueSelector: (T) -> Int): Map - -internal expect fun copyToArrayImpl(collection: Collection<*>): Array - -internal expect fun copyToArrayImpl(collection: Collection<*>, array: Array): Array - -internal expect fun arrayOfNulls(reference: Array, size: Int): Array -internal expect fun Map.toSingletonMapOrSelf(): Map -internal expect fun Map.toSingletonMap(): Map -internal expect fun Array.copyToArrayOfAny(isVarargs: Boolean): Array diff --git a/libraries/stdlib/common/src/kotlin/collections/AbstractMutableList.kt b/libraries/stdlib/common/src/kotlin/collections/AbstractMutableList.kt new file mode 100644 index 00000000000..129fc494182 --- /dev/null +++ b/libraries/stdlib/common/src/kotlin/collections/AbstractMutableList.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.collections + +expect abstract class AbstractMutableList : MutableList { + protected constructor() + + // From List + override fun isEmpty(): Boolean + override fun contains(element: @UnsafeVariance E): Boolean + override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean + override fun indexOf(element: @UnsafeVariance E): Int + override fun lastIndexOf(element: @UnsafeVariance E): Int + + // From MutableCollection + override fun iterator(): MutableIterator + + // From MutableList + override fun add(element: E): Boolean + override fun remove(element: E): Boolean + override fun addAll(elements: Collection): Boolean + override fun addAll(index: Int, elements: Collection): Boolean + override fun removeAll(elements: Collection): Boolean + override fun retainAll(elements: Collection): Boolean + override fun clear() + override fun listIterator(): MutableListIterator + override fun listIterator(index: Int): MutableListIterator + override fun subList(fromIndex: Int, toIndex: Int): MutableList +} \ No newline at end of file diff --git a/libraries/stdlib/common/src/kotlin/collections/AbstractMutableMap.kt b/libraries/stdlib/common/src/kotlin/collections/AbstractMutableMap.kt new file mode 100644 index 00000000000..c720f7a012c --- /dev/null +++ b/libraries/stdlib/common/src/kotlin/collections/AbstractMutableMap.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.collections + +expect abstract class AbstractMutableMap : MutableMap { + + protected constructor() + + /** + * Associates the specified [value] with the specified [key] in the map. + * + * This method is redeclared as abstract, because it's not implemented in the base class, + * so it must be always overridden in the concrete mutable collection implementation. + * + * @return the previous value associated with the key, or `null` if the key was not present in the map. + */ + abstract override fun put(key: K, value: V): V? +} \ No newline at end of file diff --git a/libraries/stdlib/common/src/kotlin/collections/AbstractMutableSet.kt b/libraries/stdlib/common/src/kotlin/collections/AbstractMutableSet.kt new file mode 100644 index 00000000000..1919741644d --- /dev/null +++ b/libraries/stdlib/common/src/kotlin/collections/AbstractMutableSet.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.collections + +expect abstract class AbstractMutableSet : MutableSet { + protected constructor() + + abstract override fun add(element: E): Boolean +} \ No newline at end of file diff --git a/libraries/stdlib/common/src/kotlin/collections/ArrayList.kt b/libraries/stdlib/common/src/kotlin/collections/ArrayList.kt new file mode 100644 index 00000000000..b35e0204183 --- /dev/null +++ b/libraries/stdlib/common/src/kotlin/collections/ArrayList.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.collections + +expect open class ArrayList : MutableList { + constructor() + constructor(initialCapacity: Int) + constructor(elements: Collection) + + fun trimToSize() + fun ensureCapacity(minCapacity: Int) + + // From List + override val size: Int + override fun isEmpty(): Boolean + override fun contains(element: @UnsafeVariance E): Boolean + override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean + override operator fun get(index: Int): E + override fun indexOf(element: @UnsafeVariance E): Int + override fun lastIndexOf(element: @UnsafeVariance E): Int + + // From MutableCollection + override fun iterator(): MutableIterator + + // From MutableList + override fun add(element: E): Boolean + override fun remove(element: E): Boolean + override fun addAll(elements: Collection): Boolean + override fun addAll(index: Int, elements: Collection): Boolean + override fun removeAll(elements: Collection): Boolean + override fun retainAll(elements: Collection): Boolean + override fun clear() + override operator fun set(index: Int, element: E): E + override fun add(index: Int, element: E) + override fun removeAt(index: Int): E + override fun listIterator(): MutableListIterator + override fun listIterator(index: Int): MutableListIterator + override fun subList(fromIndex: Int, toIndex: Int): MutableList +} \ No newline at end of file diff --git a/libraries/stdlib/common/src/kotlin/collections/CollectionsH.kt b/libraries/stdlib/common/src/kotlin/collections/CollectionsH.kt new file mode 100644 index 00000000000..cb87688b851 --- /dev/null +++ b/libraries/stdlib/common/src/kotlin/collections/CollectionsH.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.collections + +expect interface RandomAccess + +/** Returns the array if it's not `null`, or an empty array otherwise. */ +expect inline fun Array?.orEmpty(): Array + + +expect inline fun Collection.toTypedArray(): Array + +@SinceKotlin("1.2") +expect fun MutableList.fill(value: T): Unit +@SinceKotlin("1.2") +expect fun MutableList.shuffle(): Unit +@SinceKotlin("1.2") +expect fun Iterable.shuffled(): List + +expect fun > MutableList.sort(): Unit +expect fun MutableList.sortWith(comparator: Comparator): Unit + + +// from Grouping.kt +public expect fun Grouping.eachCount(): Map +// public expect inline fun Grouping.eachSumOf(valueSelector: (T) -> Int): Map + +internal expect fun copyToArrayImpl(collection: Collection<*>): Array + +internal expect fun copyToArrayImpl(collection: Collection<*>, array: Array): Array + +internal expect fun arrayOfNulls(reference: Array, size: Int): Array +internal expect fun Map.toSingletonMapOrSelf(): Map +internal expect fun Map.toSingletonMap(): Map +internal expect fun Array.copyToArrayOfAny(isVarargs: Boolean): Array diff --git a/libraries/stdlib/common/src/kotlin/collections/HashMap.kt b/libraries/stdlib/common/src/kotlin/collections/HashMap.kt new file mode 100644 index 00000000000..fd12b3445d6 --- /dev/null +++ b/libraries/stdlib/common/src/kotlin/collections/HashMap.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.collections + +open expect class HashMap : MutableMap { + constructor() + constructor(initialCapacity: Int) + constructor(initialCapacity: Int, loadFactor: Float) + constructor(original: Map) + + // From Map + override val size: Int + override fun isEmpty(): Boolean + override fun containsKey(key: K): Boolean + override fun containsValue(value: @UnsafeVariance V): Boolean + override operator fun get(key: K): V? + + // From MutableMap + override fun put(key: K, value: V): V? + override fun remove(key: K): V? + override fun putAll(from: Map) + override fun clear() + override val keys: MutableSet + override val values: MutableCollection + override val entries: MutableSet> +} \ No newline at end of file diff --git a/libraries/stdlib/common/src/kotlin/collections/HashSet.kt b/libraries/stdlib/common/src/kotlin/collections/HashSet.kt new file mode 100644 index 00000000000..9f572996bae --- /dev/null +++ b/libraries/stdlib/common/src/kotlin/collections/HashSet.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.collections + +open expect class HashSet : MutableSet { + constructor() + constructor(initialCapacity: Int) + constructor(initialCapacity: Int, loadFactor: Float) + constructor(elements: Collection) + + // From Set + override val size: Int + override fun isEmpty(): Boolean + override fun contains(element: @UnsafeVariance E): Boolean + override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean + + // From MutableSet + override fun iterator(): MutableIterator + override fun add(element: E): Boolean + override fun remove(element: E): Boolean + override fun addAll(elements: Collection): Boolean + override fun removeAll(elements: Collection): Boolean + override fun retainAll(elements: Collection): Boolean + override fun clear() +} \ No newline at end of file diff --git a/libraries/stdlib/common/src/kotlin/collections/LinkedHashMap.kt b/libraries/stdlib/common/src/kotlin/collections/LinkedHashMap.kt new file mode 100644 index 00000000000..f466fca41fe --- /dev/null +++ b/libraries/stdlib/common/src/kotlin/collections/LinkedHashMap.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.collections + +open expect class LinkedHashMap : HashMap { + constructor() + constructor(initialCapacity: Int) + constructor(initialCapacity: Int, loadFactor: Float) + constructor(original: Map) +} \ No newline at end of file diff --git a/libraries/stdlib/common/src/kotlin/collections/LinkedHashSet.kt b/libraries/stdlib/common/src/kotlin/collections/LinkedHashSet.kt new file mode 100644 index 00000000000..341be8db208 --- /dev/null +++ b/libraries/stdlib/common/src/kotlin/collections/LinkedHashSet.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.collections + +open expect class LinkedHashSet : HashSet { + constructor() + constructor(initialCapacity: Int) + constructor(initialCapacity: Int, loadFactor: Float) + constructor(elements: Collection) +} \ No newline at end of file