io.contek.tinker.rearm.RearmMapStore Maven / Gradle / Ivy
The newest version!
package io.contek.tinker.rearm;
import com.google.common.collect.ImmutableMap;
import java.nio.file.Path;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe
public abstract class RearmMapStore extends RearmStore> {
protected RearmMapStore(Path configPath, IParser parser) {
super(configPath, parser);
}
public final Value get(Key key) throws NoSuchElementException {
return getOrThrow(key, NoSuchElementException::new);
}
public final Value getOrThrow(Key key, Supplier t) throws E {
Value value = getNullable(key);
if (value == null) {
throw t.get();
}
return value;
}
@Nullable
public final Value getNullable(Key key) {
Map map = getMap();
return map.get(key);
}
public final ImmutableMap getMap() {
ImmutableMap item = getParsedConfig();
return item == null ? ImmutableMap.of() : item;
}
/** Parser to read and parse {@link ImmutableMap} from a file. */
@ThreadSafe
public interface IParser extends RearmStore.IParser> {}
/** Listener which gets called when {@link RearmMapStore} has update. */
@ThreadSafe
public interface IListener extends RearmStore.IListener> {}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy