commonMain.adapters.ReadOnlyCollectionAdapters.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-collections-immutable Show documentation
Show all versions of kotlinx-collections-immutable Show documentation
Kotlin Immutable Collections multiplatform library
/*
* Copyright 2016-2019 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/
package kotlinx.collections.immutable.adapters
import kotlinx.collections.immutable.*
/*
These classes allow to expose read-only collection as immutable, if it's actually immutable one
Use with caution: wrapping mutable collection as immutable is a contract violation of the latter.
*/
public open class ImmutableCollectionAdapter(private val impl: Collection) : ImmutableCollection, Collection by impl {
override fun equals(other: Any?): Boolean = impl.equals(other)
override fun hashCode(): Int = impl.hashCode()
override fun toString(): String = impl.toString()
}
public class ImmutableListAdapter(private val impl: List) : ImmutableList, List by impl {
override fun subList(fromIndex: Int, toIndex: Int): ImmutableList = ImmutableListAdapter(impl.subList(fromIndex, toIndex))
override fun equals(other: Any?): Boolean = impl.equals(other)
override fun hashCode(): Int = impl.hashCode()
override fun toString(): String = impl.toString()
}
public class ImmutableSetAdapter(impl: Set) : ImmutableSet, ImmutableCollectionAdapter(impl)
public class ImmutableMapAdapter(private val impl: Map) : ImmutableMap, Map by impl {
// TODO: Lazy initialize these properties?
override val keys: ImmutableSet = ImmutableSetAdapter(impl.keys)
override val values: ImmutableCollection = ImmutableCollectionAdapter(impl.values)
override val entries: ImmutableSet> = ImmutableSetAdapter(impl.entries)
override fun equals(other: Any?): Boolean = impl.equals(other)
override fun hashCode(): Int = impl.hashCode()
override fun toString(): String = impl.toString()
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy