main.io.github.moonlightsuite.moonlight.script.MoonLightEnumerationRepository Maven / Gradle / Ivy
package io.github.moonlightsuite.moonlight.script;
import io.github.moonlightsuite.moonlight.offline.signal.EnumerationHandler;
import java.util.HashMap;
import java.util.Map;
public class MoonLightEnumerationRepository {
private final Map> archive;
private final Map indexesOfElements;
public MoonLightEnumerationRepository(Map> archive, Map indexesOfElements) {
this.archive = archive;
this.indexesOfElements = indexesOfElements;
}
public MoonLightEnumerationRepository() {
this(new HashMap<>(), new HashMap<>());
}
public void add(String name, String[] elements) {
EnumerationHandler handler = new EnumerationHandler<>(String.class, elements);
archive.put(name, handler);
for (String e: elements) {
indexesOfElements.put(e, handler.indexOf(e));
}
}
public EnumerationHandler getHandler(String name) {
return archive.get(name);
}
public int valueOf(String element) {
return indexesOfElements.getOrDefault(element, -1);
}
}