Fixed issue when replacing values via map.entry

master
Robinson 2023-08-02 22:22:25 -06:00
parent fb1c30b035
commit 32a0208f51
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
9 changed files with 35 additions and 35 deletions

View File

@ -695,8 +695,8 @@ class ArrayMap<K: Any, V> : MutableMap<K, V?>{
}
if (entries1 == null) {
entries1 = Entries(this)
entries2 = Entries(this)
entries1 = Entries(this as ArrayMap<K, V?>)
entries2 = Entries(this as ArrayMap<K, V?>)
}
if (!entries1!!.valid) {
entries1!!.index = 0
@ -774,9 +774,9 @@ class ArrayMap<K: Any, V> : MutableMap<K, V?>{
return keys2!!
}
class Entries<K: Any, V>(private val map: ArrayMap<K, V>) : MutableSet<Entry<K, V?>>,Iterable<Entry<K, V?>>, MutableIterator<Entry<K, V?>> {
class Entries<K: Any, V>(private val map: ArrayMap<K, V?>) : MutableSet<Entry<K, V?>>,Iterable<Entry<K, V?>>, MutableIterator<Entry<K, V?>> {
var entry: Entry<K, V?> = Entry()
var entry: Entry<K, V?> = Entry(map)
var index = 0
var valid = true

View File

@ -583,12 +583,14 @@ class IntFloatMap : MutableMap<Int, Float> {
return keys2!!
}
class Entry: MutableMap.MutableEntry<Int, Float> {
override var key = 0
class Entry(val map: IntFloatMap): MutableMap.MutableEntry<Int, Float> {
override var key = 0
override var value = 0F
override fun setValue(newValue: Float): Float {
val oldValue = value
map[key] = newValue
value = newValue
return oldValue
}
@ -598,15 +600,13 @@ class IntFloatMap : MutableMap<Int, Float> {
}
}
abstract class MapIterator<V, I>(map: IntFloatMap): Iterable<I>, MutableIterator<I> {
abstract class MapIterator<V, I>(val map: IntFloatMap): Iterable<I>, MutableIterator<I> {
var hasNext = false
val map: IntFloatMap
var nextIndex = 0
var currentIndex = 0
var valid = true
init {
this.map = map
reset()
}
@ -667,7 +667,7 @@ class IntFloatMap : MutableMap<Int, Float> {
}
class Entries(map: IntFloatMap) : MutableSet<Entry>, MapIterator<Int, Entry>(map) {
private val entry = Entry()
private val entry = Entry(map)
/** Note the same entry instance is returned each time this method is called. */
override fun next(): Entry {

View File

@ -583,12 +583,13 @@ class IntIntMap : MutableMap<Int, Int> {
return keys2!!
}
class Entry: MutableMap.MutableEntry<Int, Int> {
class Entry(val map: IntIntMap): MutableMap.MutableEntry<Int, Int> {
override var key = 0
override var value = 0
override fun setValue(newValue: Int): Int {
val oldValue = value
map[key] = newValue
value = newValue
return oldValue
}
@ -598,15 +599,13 @@ class IntIntMap : MutableMap<Int, Int> {
}
}
abstract class MapIterator<V, I>(map: IntIntMap): Iterable<I>, MutableIterator<I> {
abstract class MapIterator<V, I>(val map: IntIntMap): Iterable<I>, MutableIterator<I> {
var hasNext = false
val map: IntIntMap
var nextIndex = 0
var currentIndex = 0
var valid = true
init {
this.map = map
reset()
}
@ -667,7 +666,7 @@ class IntIntMap : MutableMap<Int, Int> {
}
class Entries(map: IntIntMap) : MutableSet<Entry>, MapIterator<Int, Entry>(map) {
private val entry = Entry()
private val entry = Entry(map)
/** Note the same entry instance is returned each time this method is called. */
override fun next(): Entry {

View File

@ -631,12 +631,13 @@ open class IntMap<V> : MutableMap<Int, V> {
return keys2!!
}
class Entry<V>: MutableMap.MutableEntry<Int, V?> {
class Entry<V>(val map: IntMap<V?>): MutableMap.MutableEntry<Int, V?> {
override var key = 0
override var value: V? = null
override fun setValue(newValue: V?): V? {
val oldValue = value
map[key] = newValue
value = newValue
return oldValue
}
@ -646,15 +647,13 @@ open class IntMap<V> : MutableMap<Int, V> {
}
}
abstract class MapIterator<V, I>(map: IntMap<V>): Iterable<I>, MutableIterator<I> {
abstract class MapIterator<V, I>(val map: IntMap<V>): Iterable<I>, MutableIterator<I> {
var hasNext = false
val map: IntMap<V>
var nextIndex = 0
var currentIndex = 0
var valid = true
init {
this.map = map
reset()
}
@ -715,7 +714,7 @@ open class IntMap<V> : MutableMap<Int, V> {
}
class Entries<V>(map: IntMap<V?>) : MutableSet<Entry<V?>>, MapIterator<V?, Entry<V?>>(map) {
private val entry = Entry<V?>()
private val entry = Entry<V?>(map)
/** Note the same entry instance is returned each time this method is called. */
override fun next(): Entry<V?> {

View File

@ -630,12 +630,13 @@ class LongMap<V> : MutableMap<Long, V> {
return keys2!!
}
class Entry<V>: MutableMap.MutableEntry<Long, V?> {
class Entry<V>(val map: LongMap<V?>): MutableMap.MutableEntry<Long, V?> {
override var key = 0L
override var value: V? = null
override fun setValue(newValue: V?): V? {
val oldValue = value
map[key] = newValue
value = newValue
return oldValue
}
@ -645,15 +646,13 @@ class LongMap<V> : MutableMap<Long, V> {
}
}
abstract class MapIterator<V, I>(map: LongMap<V>): Iterable<I>, MutableIterator<I> {
abstract class MapIterator<V, I>(val map: LongMap<V>): Iterable<I>, MutableIterator<I> {
var hasNext = false
val map: LongMap<V>
var nextIndex = 0
var currentIndex = 0
var valid = true
init {
this.map = map
reset()
}
@ -714,7 +713,7 @@ class LongMap<V> : MutableMap<Long, V> {
}
class Entries<V>(map: LongMap<V?>) : MutableSet<Entry<V?>>, MapIterator<V?, Entry<V?>>(map) {
private val entry = Entry<V?>()
private val entry = Entry<V?>(map)
/** Note the same entry instance is returned each time this method is called. */
override fun next(): Entry<V?> {

View File

@ -647,12 +647,13 @@ open class ObjectFloatMap<K: Any> : MutableMap<K, Float> {
return keys2 as Keys<K>
}
class Entry<K: Any>: MutableMap.MutableEntry<K, Float> {
class Entry<K: Any>(val map: ObjectFloatMap<K>) : MutableMap.MutableEntry<K, Float> {
override lateinit var key: K
override var value: Float = 0F
override fun setValue(newValue: Float): Float {
val oldValue = value
map[key] = newValue
value = newValue
return oldValue
}
@ -720,7 +721,7 @@ open class ObjectFloatMap<K: Any> : MutableMap<K, Float> {
}
open class Entries<K: Any>(map: ObjectFloatMap<K>) : MutableSet<Entry<K>>, MapIterator<K, Int, Entry<K>>(map) {
var entry = Entry<K>()
var entry = Entry<K>(map)
/** Note the same entry instance is returned each time this method is called. */
override fun next(): Entry<K> {

View File

@ -592,12 +592,13 @@ open class ObjectIntMap<K: Any> : MutableMap<K, Int> {
return keys2 as Keys<K>
}
class Entry<K: Any>: MutableMap.MutableEntry<K, Int> {
class Entry<K: Any>(val map: ObjectIntMap<K>) : MutableMap.MutableEntry<K, Int> {
override lateinit var key: K
override var value: Int = 0
override fun setValue(newValue: Int): Int {
val oldValue = value
map[key] = newValue
value = newValue
return oldValue
}
@ -665,7 +666,7 @@ open class ObjectIntMap<K: Any> : MutableMap<K, Int> {
}
open class Entries<K: Any>(map: ObjectIntMap<K>) : MutableSet<Entry<K>>, MapIterator<K, Int, Entry<K>>(map) {
var entry = Entry<K>()
var entry = Entry<K>(map)
/** Note the same entry instance is returned each time this method is called. */
override fun next(): Entry<K> {

View File

@ -609,12 +609,13 @@ open class ObjectMap<K: Any, V> : MutableMap<K, V> {
return keys2 as Keys<K>
}
class Entry<K: Any, V>: MutableMap.MutableEntry<K, V?> {
class Entry<K: Any, V>(val map: ObjectMap<K, V?>) : MutableMap.MutableEntry<K, V?> {
override lateinit var key: K
override var value: V? = null
override fun setValue(newValue: V?): V? {
val oldValue = value
map[key] = newValue
value = newValue
return oldValue
}
@ -682,7 +683,7 @@ open class ObjectMap<K: Any, V> : MutableMap<K, V> {
}
open class Entries<K: Any, V>(map: ObjectMap<K, V?>) : MutableSet<Entry<K, V?>>, MapIterator<K, V?, Entry<K, V?>>(map) {
var entry = Entry<K, V?>()
var entry = Entry<K, V?>(map)
/** Note the same entry instance is returned each time this method is called. */
override fun next(): Entry<K, V?> {

View File

@ -163,7 +163,7 @@ class ObjectTests {
assertTrue(map.size == 3)
val entries = map.entries()
val keepEntry = ObjectMap.Entry<String, Int?>()
val keepEntry = ObjectMap.Entry<String, Int?>(map)
keepEntry.key = "1"
keepEntry.value = 1