Skip to content

Commit 07bccd5

Browse files
committed
Move collection interfaces to separate files.
1 parent a59b572 commit 07bccd5

File tree

5 files changed

+108
-110
lines changed

5 files changed

+108
-110
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package kotlinx.collections.immutable
2+
3+
public interface ImmutableCollection<out E>: Collection<E> {
4+
fun add(element: @UnsafeVariance E): ImmutableCollection<E>
5+
6+
fun addAll(elements: Collection<@UnsafeVariance E>): ImmutableCollection<E>
7+
8+
fun remove(element: @UnsafeVariance E): ImmutableCollection<E>
9+
10+
fun removeAll(elements: Collection<@UnsafeVariance E>): ImmutableCollection<E>
11+
12+
fun removeAll(predicate: (E) -> Boolean): ImmutableCollection<E>
13+
14+
fun clear(): ImmutableCollection<E>
15+
16+
interface Builder<E>: MutableCollection<E> {
17+
fun build(): ImmutableCollection<E>
18+
}
19+
20+
fun builder(): Builder<@UnsafeVariance E>
21+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package kotlinx.collections.immutable
2+
3+
public interface ImmutableList<out E>: List<E>, ImmutableCollection<E> {
4+
override fun add(element: @UnsafeVariance E): ImmutableList<E>
5+
6+
override fun addAll(elements: Collection<@UnsafeVariance E>): ImmutableList<E> // = super<ImmutableCollection>.addAll(elements) as ImmutableList
7+
8+
override fun remove(element: @UnsafeVariance E): ImmutableList<E>
9+
10+
override fun removeAll(elements: Collection<@UnsafeVariance E>): ImmutableList<E>
11+
12+
override fun removeAll(predicate: (E) -> Boolean): ImmutableList<E>
13+
14+
override fun clear(): ImmutableList<E>
15+
16+
17+
fun addAll(index: Int, c: Collection<@UnsafeVariance E>): ImmutableList<E> // = builder().apply { addAll(index, c.toList()) }.build()
18+
19+
fun set(index: Int, element: @UnsafeVariance E): ImmutableList<E>
20+
21+
/**
22+
* Inserts an element into the list at the specified [index].
23+
*/
24+
fun add(index: Int, element: @UnsafeVariance E): ImmutableList<E>
25+
26+
fun removeAt(index: Int): ImmutableList<E>
27+
28+
29+
override fun subList(fromIndex: Int, toIndex: Int): ImmutableList<E>
30+
31+
interface Builder<E>: MutableList<E>, ImmutableCollection.Builder<E> {
32+
override fun build(): ImmutableList<E>
33+
}
34+
35+
override fun builder(): Builder<@UnsafeVariance E>
36+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package kotlinx.collections.immutable
2+
3+
4+
public interface ImmutableMap<K, out V>: Map<K, V> {
5+
6+
override val keys: ImmutableSet<K>
7+
8+
override val values: ImmutableCollection<V>
9+
10+
override val entries: ImmutableSet<Map.Entry<K, V>>
11+
12+
fun put(key: K, value: @UnsafeVariance V): ImmutableMap<K, V>
13+
14+
fun remove(key: K): ImmutableMap<K, V>
15+
16+
fun remove(key: K, value: @UnsafeVariance V): ImmutableMap<K, V>
17+
18+
fun putAll(m: Map<out K, @UnsafeVariance V>): ImmutableMap<K, V> // m: Iterable<Map.Entry<K, V>> or Map<out K,V> or Iterable<Pair<K, V>>
19+
20+
fun clear(): ImmutableMap<K, V>
21+
22+
interface Builder<K, V>: MutableMap<K, V> {
23+
fun build(): ImmutableMap<K, V>
24+
}
25+
26+
fun builder(): Builder<K, @UnsafeVariance V>
27+
}
28+
29+
30+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package kotlinx.collections.immutable
2+
3+
public interface ImmutableSet<out E>: Set<E>, ImmutableCollection<E> {
4+
override fun add(element: @UnsafeVariance E): ImmutableSet<E>
5+
6+
override fun addAll(elements: Collection<@UnsafeVariance E>): ImmutableSet<E>
7+
8+
override fun remove(element: @UnsafeVariance E): ImmutableSet<E>
9+
10+
override fun removeAll(elements: Collection<@UnsafeVariance E>): ImmutableSet<E>
11+
12+
override fun removeAll(predicate: (E) -> Boolean): ImmutableSet<E>
13+
14+
override fun clear(): ImmutableSet<E>
15+
16+
interface Builder<E>: MutableSet<E>, ImmutableCollection.Builder<E> {
17+
override fun build(): ImmutableSet<E>
18+
}
19+
20+
override fun builder(): Builder<@UnsafeVariance E>
21+
}

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/interfaces.kt

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)