feature/d01-component-system #5

Merged
NotEvil merged 20 commits from feature/d01-component-system into develop 2026-04-14 00:54:17 +00:00
Showing only changes of commit dcc8493e5e - Show all commits

View File

@@ -1,6 +1,9 @@
package com.tiedup.remake.v2.bondage.component;
import com.google.gson.JsonObject;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import org.jetbrains.annotations.Nullable;
@@ -12,6 +15,16 @@ public enum ComponentType {
private final String jsonKey;
private final Function<JsonObject, IItemComponent> factory;
/** Pre-built lookup map for O(1) fromKey() instead of linear scan. */
private static final Map<String, ComponentType> BY_KEY;
static {
Map<String, ComponentType> map = new HashMap<>();
for (ComponentType type : values()) {
map.put(type.jsonKey, type);
}
BY_KEY = Collections.unmodifiableMap(map);
}
ComponentType(
String jsonKey,
Function<JsonObject, IItemComponent> factory
@@ -30,9 +43,6 @@ public enum ComponentType {
@Nullable
public static ComponentType fromKey(String key) {
for (ComponentType type : values()) {
if (type.jsonKey.equals(key)) return type;
}
return null;
return BY_KEY.get(key);
}
}