From 8f8d4b4ac77333e5b6f568598105a8bdeedacc5c Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 25 Sep 2022 21:07:30 +0700 Subject: [PATCH] Rename observed map to proxied map --- .../core/{ObservedMap.kt => ProxiedMap.kt} | 24 +++++++++---------- .../mc/otm/network/FieldSynchronizer.kt | 2 +- .../mc/otm/saveddata/SavedCountingMap.kt | 8 +++---- 3 files changed, 17 insertions(+), 17 deletions(-) rename src/main/kotlin/ru/dbotthepony/mc/otm/core/{ObservedMap.kt => ProxiedMap.kt} (90%) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/ObservedMap.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/ProxiedMap.kt similarity index 90% rename from src/main/kotlin/ru/dbotthepony/mc/otm/core/ObservedMap.kt rename to src/main/kotlin/ru/dbotthepony/mc/otm/core/ProxiedMap.kt index 9276a08d9..2c4840fd7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/ObservedMap.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/ProxiedMap.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.mc.otm.core -abstract class ObservedMap(protected val backingMap: MutableMap = HashMap()) : MutableMap { +abstract class ProxiedMap(protected val backingMap: MutableMap = HashMap()) : MutableMap { protected abstract fun onClear() protected abstract fun onValueAdded(key: K, value: V) protected abstract fun onValueRemoved(key: K, value: V) @@ -27,7 +27,7 @@ abstract class ObservedMap(protected val backingMap: MutableMap = Ha final override val entries: MutableSet> by lazy { object : MutableSet> { override fun add(element: MutableMap.MutableEntry): Boolean { - this@ObservedMap[element.key] = element.value + this@ProxiedMap[element.key] = element.value return true } @@ -40,10 +40,10 @@ abstract class ObservedMap(protected val backingMap: MutableMap = Ha } override fun clear() { - this@ObservedMap.clear() + this@ProxiedMap.clear() } - private val setParent = this@ObservedMap.backingMap.entries + private val setParent = this@ProxiedMap.backingMap.entries override fun iterator(): MutableIterator> { return object : MutableIterator> { @@ -118,7 +118,7 @@ abstract class ObservedMap(protected val backingMap: MutableMap = Ha final override val keys: MutableSet by lazy { object : MutableSet { - val parent = this@ObservedMap.backingMap.keys + val parent = this@ProxiedMap.backingMap.keys override fun add(element: K): Boolean { throw UnsupportedOperationException() @@ -129,7 +129,7 @@ abstract class ObservedMap(protected val backingMap: MutableMap = Ha } override fun clear() { - this@ObservedMap.clear() + this@ProxiedMap.clear() } override fun iterator(): MutableIterator { @@ -147,7 +147,7 @@ abstract class ObservedMap(protected val backingMap: MutableMap = Ha override fun remove() { val last = last ?: throw IllegalStateException("Never called next()") - val value = this@ObservedMap[last] ?: throw ConcurrentModificationException() + val value = this@ProxiedMap[last] ?: throw ConcurrentModificationException() parentIterator.remove() onValueRemoved(last, value) } @@ -155,7 +155,7 @@ abstract class ObservedMap(protected val backingMap: MutableMap = Ha } override fun remove(element: K): Boolean { - return this@ObservedMap.remove(element) != null + return this@ProxiedMap.remove(element) != null } override fun removeAll(elements: Collection): Boolean { @@ -201,7 +201,7 @@ abstract class ObservedMap(protected val backingMap: MutableMap = Ha final override val values: MutableCollection by lazy { object : MutableCollection { - private val parent = this@ObservedMap.backingMap.values + private val parent = this@ProxiedMap.backingMap.values override val size: Int get() = parent.size @@ -227,7 +227,7 @@ abstract class ObservedMap(protected val backingMap: MutableMap = Ha } override fun clear() { - this@ObservedMap.clear() + this@ProxiedMap.clear() } override fun iterator(): MutableIterator { @@ -249,8 +249,8 @@ abstract class ObservedMap(protected val backingMap: MutableMap = Ha } override fun remove(element: V): Boolean { - val indexOf = this@ObservedMap.backingMap.firstNotNullOfOrNull { if (it.value == element) it.key else null } ?: return false - this@ObservedMap.remove(indexOf) + val indexOf = this@ProxiedMap.backingMap.firstNotNullOfOrNull { if (it.value == element) it.key else null } ?: return false + this@ProxiedMap.remove(indexOf) return true } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/network/FieldSynchronizer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/network/FieldSynchronizer.kt index 6b9542a71..ab899224f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/network/FieldSynchronizer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/network/FieldSynchronizer.kt @@ -452,7 +452,7 @@ class FieldSynchronizer { } } - override val value: MutableMap = object : ObservedMap(backingMap) { + override val value: MutableMap = object : ProxiedMap(backingMap) { override fun onClear() { if (isRemote) { return diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/saveddata/SavedCountingMap.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/saveddata/SavedCountingMap.kt index 8dd1ab17f..f9757eea0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/saveddata/SavedCountingMap.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/saveddata/SavedCountingMap.kt @@ -8,7 +8,7 @@ import net.minecraft.nbt.ListTag import net.minecraft.nbt.Tag import net.minecraft.world.level.saveddata.SavedData import org.apache.logging.log4j.LogManager -import ru.dbotthepony.mc.otm.core.ObservedMap +import ru.dbotthepony.mc.otm.core.ProxiedMap import ru.dbotthepony.mc.otm.core.set import ru.dbotthepony.mc.otm.registry.WriteOnce @@ -38,7 +38,7 @@ class SavedMapDelegate(val parent: SavedCountingMap>?, va } } -private class ObservedCountingMap : ObservedMap(Int2ObjectAVLTreeMap()) { +private class ProxiedCountingMap : ProxiedMap(Int2ObjectAVLTreeMap()) { var parent: SavedCountingMap by WriteOnce() override fun onClear() { @@ -58,13 +58,13 @@ class SavedCountingMap private constructor( val serializer: (map: SavedCountingMap, value: T, index: Int) -> Tag, val deserializer: (map: SavedCountingMap, nbt: Tag, index: Int) -> T, val factory: (map: SavedCountingMap, index: Int) -> T, - private val map: ObservedCountingMap + private val map: ProxiedCountingMap ) : SavedData(), MutableMap by map { constructor( serializer: (map: SavedCountingMap, value: T, index: Int) -> Tag, deserializer: (map: SavedCountingMap, nbt: Tag, index: Int) -> T, factory: (map: SavedCountingMap, index: Int) -> T, - ) : this(serializer, deserializer, factory, ObservedCountingMap()) + ) : this(serializer, deserializer, factory, ProxiedCountingMap()) init { map.parent = this