diff --git a/src/dorkbox/collections/Collections.kt b/src/dorkbox/collections/Collections.kt index c7a94e9..a5a8f0d 100644 --- a/src/dorkbox/collections/Collections.kt +++ b/src/dorkbox/collections/Collections.kt @@ -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 diff --git a/src/dorkbox/collections/LockFreeArrayList.kt b/src/dorkbox/collections/LockFreeArrayList.kt index 3df6858..7405367 100644 --- a/src/dorkbox/collections/LockFreeArrayList.kt +++ b/src/dorkbox/collections/LockFreeArrayList.kt @@ -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 : MutableList, RandomAccess, Cloneable, Serializab return listRef[this] as ArrayList } + /** + * Return a non-thread-safe copy of the backing array + */ + fun toList(): ArrayList { + return ArrayList(listRef[this] as ArrayList) + } + // this must be at the end of the file! companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeBiMap.kt b/src/dorkbox/collections/LockFreeBiMap.kt index b54138c..a5d9c02 100644 --- a/src/dorkbox/collections/LockFreeBiMap.kt +++ b/src/dorkbox/collections/LockFreeBiMap.kt @@ -411,6 +411,20 @@ class LockFreeBiMap : MutableMap, Cloneable, Serializable @Suppress("UNCHECKED_CAST") get() = reverseREF[this].values as MutableCollection + /** + * Return a non-thread-safe copy of the backing map + */ + fun toMap(): MutableMap { + return HashMap(forwardREF[this] as MutableMap) + } + + /** + * Return a non-thread-safe copy of the backing map + */ + fun toReverseMap(): MutableMap { + return HashMap(reverseREF[this] as MutableMap) + } + companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeHashMap.kt b/src/dorkbox/collections/LockFreeHashMap.kt index d256115..a5b8fd5 100644 --- a/src/dorkbox/collections/LockFreeHashMap.kt +++ b/src/dorkbox/collections/LockFreeHashMap.kt @@ -193,6 +193,13 @@ class LockFreeHashMap : MutableMap, Cloneable, Serializable { return mapREF[this].toString() } + /** + * Return a non-thread-safe copy of the backing map + */ + fun toMap(): HashMap { + return HashMap(mapREF[this] as HashMap) + } + // this must be at the end of the file! companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeHashSet.kt b/src/dorkbox/collections/LockFreeHashSet.kt index a60e145..df42f4d 100644 --- a/src/dorkbox/collections/LockFreeHashSet.kt +++ b/src/dorkbox/collections/LockFreeHashSet.kt @@ -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 : MutableSet, Cloneable, Serializable { return setREF[this].toString() } + /** + * Return a non-thread-safe copy of the backing set + */ + fun toSet(): HashSet { + return HashSet(setREF[this] as HashSet) + } + companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeIntBiMap.kt b/src/dorkbox/collections/LockFreeIntBiMap.kt index 4011d9a..24260b0 100644 --- a/src/dorkbox/collections/LockFreeIntBiMap.kt +++ b/src/dorkbox/collections/LockFreeIntBiMap.kt @@ -349,7 +349,7 @@ class LockFreeIntBiMap : MutableMap, Cloneable, Serializable { override val entries: MutableSet> // use the SWP to get a lock-free get of the value @Suppress("UNCHECKED_CAST") - get() = forwardREF[this].keys as MutableSet> + get() = forwardREF[this].entries as MutableSet> @@ -421,6 +421,21 @@ class LockFreeIntBiMap : MutableMap, 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 { + return IntMap(forwardREF[this] as IntMap) + } + + /** + * Return a non-thread-safe copy of the backing reverse-map + */ + fun toReverseMap(): ObjectIntMap { + return ObjectIntMap(reverseREF[this] as ObjectIntMap) + } + companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeIntMap.kt b/src/dorkbox/collections/LockFreeIntMap.kt index b448bc1..f5cec15 100644 --- a/src/dorkbox/collections/LockFreeIntMap.kt +++ b/src/dorkbox/collections/LockFreeIntMap.kt @@ -213,6 +213,13 @@ class LockFreeIntMap : MutableMap, Cloneable, Serializable { mapREF[this].shrink(maximumCapacity) } + /** + * Return a non-thread-safe copy of the backing map + */ + fun toMap(): IntMap { + return IntMap(mapREF[this] as IntMap) + } + companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeIntStringMap.kt b/src/dorkbox/collections/LockFreeIntStringMap.kt index b7a9317..e70afaf 100644 --- a/src/dorkbox/collections/LockFreeIntStringMap.kt +++ b/src/dorkbox/collections/LockFreeIntStringMap.kt @@ -197,6 +197,14 @@ class LockFreeIntStringMap : MutableMap, Cloneable, Serializable { return mapREF[this].toString() } + + /** + * Return a non-thread-safe copy of the backing map + */ + fun toMap(): IntMap { + return IntMap(mapREF[this] as IntMap) + } + // this must be at the end of the file! companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeLongMap.kt b/src/dorkbox/collections/LockFreeLongMap.kt index f845de9..9c8acce 100644 --- a/src/dorkbox/collections/LockFreeLongMap.kt +++ b/src/dorkbox/collections/LockFreeLongMap.kt @@ -213,6 +213,14 @@ class LockFreeLongMap : MutableMap, Cloneable, Serializable { mapREF[this].shrink(maximumCapacity) } + + /** + * Return a non-thread-safe copy of the backing map + */ + fun toMap(): LongMap { + return LongMap(mapREF[this] as LongMap) + } + companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeObjectBiMap.kt b/src/dorkbox/collections/LockFreeObjectBiMap.kt index 6ca1f6c..a060cae 100644 --- a/src/dorkbox/collections/LockFreeObjectBiMap.kt +++ b/src/dorkbox/collections/LockFreeObjectBiMap.kt @@ -418,6 +418,20 @@ class LockFreeObjectBiMap : MutableMap, Cloneable, Seriali @Suppress("UNCHECKED_CAST") get() = reverseREF[this].values as MutableCollection + /** + * Return a non-thread-safe copy of the backing map + */ + fun toMap(): ObjectMap { + return ObjectMap(forwardREF[this] as ObjectMap) + } + + /** + * Return a non-thread-safe copy of the backing reverse-map + */ + fun toReverseMap(): ObjectMap { + return ObjectMap(reverseREF[this] as ObjectMap) + } + companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeObjectIntBiMap.kt b/src/dorkbox/collections/LockFreeObjectIntBiMap.kt index b567414..3ee2f2c 100644 --- a/src/dorkbox/collections/LockFreeObjectIntBiMap.kt +++ b/src/dorkbox/collections/LockFreeObjectIntBiMap.kt @@ -428,6 +428,21 @@ class LockFreeObjectIntBiMap : MutableMap, Cloneable, Serializab @Suppress("UNCHECKED_CAST") get() = reverseREF[this].values as MutableCollection + + /** + * Return a non-thread-safe copy of the backing map + */ + fun toMap(): ObjectIntMap { + return ObjectIntMap(forwardREF[this] as ObjectIntMap) + } + + /** + * Return a non-thread-safe copy of the backing reverse-map + */ + fun toReverseMap(): IntMap { + return IntMap(reverseREF[this] as IntMap) + } + companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeObjectIntMap.kt b/src/dorkbox/collections/LockFreeObjectIntMap.kt index fe62790..ddd54ec 100644 --- a/src/dorkbox/collections/LockFreeObjectIntMap.kt +++ b/src/dorkbox/collections/LockFreeObjectIntMap.kt @@ -210,6 +210,13 @@ class LockFreeObjectIntMap : MutableMap, Cloneable, Serializable mapREF[this].shrink(maximumCapacity) } + /** + * Return a non-thread-safe copy of the backing map + */ + fun toMap(): ObjectIntMap { + return ObjectIntMap(mapREF[this] as ObjectIntMap) + } + companion object { const val version = Collections.version diff --git a/src/dorkbox/collections/LockFreeObjectMap.kt b/src/dorkbox/collections/LockFreeObjectMap.kt index 493ec1d..8a2c972 100644 --- a/src/dorkbox/collections/LockFreeObjectMap.kt +++ b/src/dorkbox/collections/LockFreeObjectMap.kt @@ -217,6 +217,13 @@ class LockFreeObjectMap : MutableMap, Cloneable, Serializable { mapREF[this].shrink(maximumCapacity) } + /** + * Return a non-thread-safe copy of the backing map + */ + fun toMap(): ObjectMap { + return ObjectMap(mapREF[this] as ObjectMap) + } + companion object { const val version = Collections.version