Added support for .toMap() and .toList(), etc.
This commit is contained in:
parent
e9e377f27d
commit
f0f5c62951
|
@ -21,7 +21,7 @@ object Collections {
|
|||
/**
|
||||
* Gets the version number.
|
||||
*/
|
||||
const val version = "2.5"
|
||||
const val version = "2.6"
|
||||
|
||||
init {
|
||||
// Add this project to the updates system, which verifies this class + UUID + version information
|
||||
|
|
|
@ -17,7 +17,6 @@ package dorkbox.collections
|
|||
|
||||
import java.io.Serializable
|
||||
import java.util.concurrent.atomic.*
|
||||
import kotlin.Array
|
||||
|
||||
/**
|
||||
* This class uses the "single-writer-principle" for lock-free publication.
|
||||
|
@ -202,6 +201,13 @@ class LockFreeArrayList<E> : MutableList<E>, RandomAccess, Cloneable, Serializab
|
|||
return listRef[this] as ArrayList<E>
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing array
|
||||
*/
|
||||
fun toList(): ArrayList<E> {
|
||||
return ArrayList(listRef[this] as ArrayList<E>)
|
||||
}
|
||||
|
||||
// this must be at the end of the file!
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
|
|
@ -411,6 +411,20 @@ class LockFreeBiMap<K: Any, V: Any> : MutableMap<K, V>, Cloneable, Serializable
|
|||
@Suppress("UNCHECKED_CAST")
|
||||
get() = reverseREF[this].values as MutableCollection<K>
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toMap(): MutableMap<K, V> {
|
||||
return HashMap(forwardREF[this] as MutableMap<K, V>)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toReverseMap(): MutableMap<V, K> {
|
||||
return HashMap(reverseREF[this] as MutableMap<V, K>)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
||||
|
|
|
@ -193,6 +193,13 @@ class LockFreeHashMap<K: Any, V> : MutableMap<K, V>, Cloneable, Serializable {
|
|||
return mapREF[this].toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toMap(): HashMap<K, V> {
|
||||
return HashMap(mapREF[this] as HashMap<K, V>)
|
||||
}
|
||||
|
||||
// this must be at the end of the file!
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
|
|
@ -17,7 +17,6 @@ package dorkbox.collections
|
|||
|
||||
import java.io.Serializable
|
||||
import java.util.concurrent.atomic.*
|
||||
import kotlin.Array
|
||||
|
||||
/**
|
||||
* This class uses the "single-writer-principle" for lock-free publication.
|
||||
|
@ -126,6 +125,13 @@ class LockFreeHashSet<E> : MutableSet<E>, Cloneable, Serializable {
|
|||
return setREF[this].toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing set
|
||||
*/
|
||||
fun toSet(): HashSet<E> {
|
||||
return HashSet(setREF[this] as HashSet<E>)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
||||
|
|
|
@ -349,7 +349,7 @@ class LockFreeIntBiMap<V: Any> : MutableMap<Int, V>, Cloneable, Serializable {
|
|||
override val entries: MutableSet<MutableMap.MutableEntry<Int, V>>
|
||||
// use the SWP to get a lock-free get of the value
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
get() = forwardREF[this].keys as MutableSet<MutableMap.MutableEntry<Int, V>>
|
||||
get() = forwardREF[this].entries as MutableSet<MutableMap.MutableEntry<Int, V>>
|
||||
|
||||
|
||||
|
||||
|
@ -421,6 +421,21 @@ class LockFreeIntBiMap<V: Any> : MutableMap<Int, V>, Cloneable, Serializable {
|
|||
// use the SWP to get a lock-free get of the value
|
||||
get() = reverseREF[this].values
|
||||
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toMap(): IntMap<V> {
|
||||
return IntMap(forwardREF[this] as IntMap<V>)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing reverse-map
|
||||
*/
|
||||
fun toReverseMap(): ObjectIntMap<V> {
|
||||
return ObjectIntMap(reverseREF[this] as ObjectIntMap<V>)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
||||
|
|
|
@ -213,6 +213,13 @@ class LockFreeIntMap<V> : MutableMap<Int, V>, Cloneable, Serializable {
|
|||
mapREF[this].shrink(maximumCapacity)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toMap(): IntMap<V> {
|
||||
return IntMap(mapREF[this] as IntMap<V>)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
||||
|
|
|
@ -197,6 +197,14 @@ class LockFreeIntStringMap : MutableMap<Int, String?>, Cloneable, Serializable {
|
|||
return mapREF[this].toString()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toMap(): IntMap<String?> {
|
||||
return IntMap(mapREF[this] as IntMap<String?>)
|
||||
}
|
||||
|
||||
// this must be at the end of the file!
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
|
|
@ -213,6 +213,14 @@ class LockFreeLongMap<V> : MutableMap<Long, V>, Cloneable, Serializable {
|
|||
mapREF[this].shrink(maximumCapacity)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toMap(): LongMap<V> {
|
||||
return LongMap(mapREF[this] as LongMap<V>)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
||||
|
|
|
@ -418,6 +418,20 @@ class LockFreeObjectBiMap<K: Any, V: Any> : MutableMap<K, V>, Cloneable, Seriali
|
|||
@Suppress("UNCHECKED_CAST")
|
||||
get() = reverseREF[this].values as MutableCollection<K>
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toMap(): ObjectMap<K, V> {
|
||||
return ObjectMap(forwardREF[this] as ObjectMap<K, V>)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing reverse-map
|
||||
*/
|
||||
fun toReverseMap(): ObjectMap<V, K> {
|
||||
return ObjectMap(reverseREF[this] as ObjectMap<V, K>)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
||||
|
|
|
@ -428,6 +428,21 @@ class LockFreeObjectIntBiMap<K: Any> : MutableMap<K, Int>, Cloneable, Serializab
|
|||
@Suppress("UNCHECKED_CAST")
|
||||
get() = reverseREF[this].values as MutableCollection<K>
|
||||
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toMap(): ObjectIntMap<K> {
|
||||
return ObjectIntMap(forwardREF[this] as ObjectIntMap<K>)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing reverse-map
|
||||
*/
|
||||
fun toReverseMap(): IntMap<K> {
|
||||
return IntMap(reverseREF[this] as IntMap<K>)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
||||
|
|
|
@ -210,6 +210,13 @@ class LockFreeObjectIntMap<K: Any> : MutableMap<K, Int>, Cloneable, Serializable
|
|||
mapREF[this].shrink(maximumCapacity)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toMap(): ObjectIntMap<K> {
|
||||
return ObjectIntMap(mapREF[this] as ObjectIntMap<K>)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
||||
|
|
|
@ -217,6 +217,13 @@ class LockFreeObjectMap<K: Any, V> : MutableMap<K, V>, Cloneable, Serializable {
|
|||
mapREF[this].shrink(maximumCapacity)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a non-thread-safe copy of the backing map
|
||||
*/
|
||||
fun toMap(): ObjectMap<K, V> {
|
||||
return ObjectMap(mapREF[this] as ObjectMap<K, V>)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val version = Collections.version
|
||||
|
||||
|
|
Loading…
Reference in New Issue