From cd0f52c90a704bf8bb3e5fb2ef731200abf65cb1 Mon Sep 17 00:00:00 2001
From: DBotThePony <dbotthepony@yandex.ru>
Date: Fri, 30 Aug 2024 16:56:30 +0700
Subject: [PATCH] Use ImmutableMap

---
 .../ru/dbotthepony/mc/otm/core/collect/SupplierMap.kt      | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/SupplierMap.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/SupplierMap.kt
index a53c6448f..90edaa86d 100644
--- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/SupplierMap.kt
+++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/SupplierMap.kt
@@ -1,5 +1,6 @@
 package ru.dbotthepony.mc.otm.core.collect
 
+import com.google.common.collect.ImmutableMap
 import com.google.common.collect.ImmutableSet
 import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap
 import ru.dbotthepony.mc.otm.core.stream
@@ -7,19 +8,15 @@ import java.util.function.Supplier
 import java.util.stream.Stream
 
 class SupplierMap<K, T>(values: Stream<Pair<K, Supplier<T>>>) : Map<K, T> {
-	private val backing = Object2ObjectLinkedOpenHashMap<K, Supplier<T>>()
 	override val entries: Set<Map.Entry<K, T>>
 	override val keys: Set<K>
 		get() = backing.keys
 	override val size: Int
 		get() = entries.size
 	override val values: Collection<T>
+	private val backing = values.collect(ImmutableMap.toImmutableMap({ it.first }, { it.second }))
 
 	init {
-		values.forEach {
-			backing[it.first] = it.second
-		}
-
 		entries = ImmutableSet.copyOf(backing.entries.map { Entry(it.key, it.value) })
 		this.values = SupplierList(backing.values)
 	}