mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 16:35:50 +00:00
cache value of ModDependentConfigSection
This commit is contained in:
parent
788a3c2d48
commit
ed2fa85d81
@ -9,9 +9,12 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ModDependentConfigSection<T> {
|
public class ModDependentConfigSection<T> {
|
||||||
|
private static final Object NULL = new Object(); // Null object
|
||||||
private final TerraPlugin main;
|
private final TerraPlugin main;
|
||||||
private final Map<String, T> results = new HashMap<>();
|
private final Map<String, T> results = new HashMap<>();
|
||||||
private final T defaultValue;
|
private final T defaultValue;
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private T value = (T) NULL;
|
||||||
|
|
||||||
protected ModDependentConfigSection(TerraPlugin main, T defaultValue) {
|
protected ModDependentConfigSection(TerraPlugin main, T defaultValue) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
@ -27,6 +30,11 @@ public class ModDependentConfigSection<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public T get() {
|
public T get() {
|
||||||
|
if(value == NULL) value = compute(); // Cache the value.
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private T compute() {
|
||||||
if(main != null) {
|
if(main != null) {
|
||||||
Set<String> mods = main.getMods().stream().map(Mod::getID).collect(Collectors.toSet());
|
Set<String> mods = main.getMods().stream().map(Mod::getID).collect(Collectors.toSet());
|
||||||
for(Map.Entry<String, T> entry : results.entrySet()) {
|
for(Map.Entry<String, T> entry : results.entrySet()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user