Make Pair a record

This commit is contained in:
dfsek
2026-01-01 20:09:52 -07:00
parent eb6b3704d0
commit 47bdd66fe7
11 changed files with 24 additions and 49 deletions

View File

@@ -29,8 +29,6 @@ import com.dfsek.tectonic.api.loader.type.TypeLoader;
import com.dfsek.tectonic.impl.loading.object.ObjectTemplateLoader;
import com.dfsek.tectonic.yaml.YamlConfiguration;
import com.dfsek.terra.api.tectonic.ConfigLoadingDelegate;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
import org.jetbrains.annotations.NotNull;
@@ -51,11 +49,9 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader.Provider;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.dfsek.terra.api.Platform;
@@ -186,7 +182,7 @@ public class ConfigPackImpl implements ConfigPack {
logger.info("Loading config pack \"{}:{}\"", id, namespace);
configTypes.values().forEach(list -> list.forEach(pair -> configTypeRegistry.register(pair.getLeft(), pair.getRight())));
configTypes.values().forEach(list -> list.forEach(pair -> configTypeRegistry.register(pair.left(), pair.right())));
ListMultimap<ConfigType<?, ?>, Configuration> multimap = configurations.values().parallelStream().collect(
() -> Multimaps.newListMultimap(new ConcurrentHashMap<>(), ArrayList::new), (configs, configuration) -> {
@@ -216,7 +212,7 @@ public class ConfigPackImpl implements ConfigPack {
return Pair.of(configuration.getID(), loaded);
})
.toList()
.forEach(pair -> registry.register(key(pair.getLeft()), pair.getRight()));
.forEach(pair -> registry.register(key(pair.left()), pair.right()));
platform.getEventManager().callEvent(new ConfigTypePostLoadEvent(configType, registry, this));
});
@@ -289,7 +285,7 @@ public class ConfigPackImpl implements ConfigPack {
public ConfigPack registerConfigType(ConfigType<?, ?> type, RegistryKey key, int priority) {
Set<RegistryKey> contained = new HashSet<>();
configTypes.forEach((p, configs) -> configs.forEach(pair -> {
if(contained.contains(pair.getLeft())) throw new IllegalArgumentException("Duplicate config key: " + key);
if(contained.contains(pair.left())) throw new IllegalArgumentException("Duplicate config key: " + key);
contained.add(key);
}));
configTypes.computeIfAbsent(priority, p -> new ArrayList<>()).add(Pair.of(key, type));

View File

@@ -64,7 +64,7 @@ public class MetaListLikePreprocessor extends MetaPreprocessor<Meta> {
Pair<Configuration, Object> pair = getMetaValue(meta, depthTracker);
Object metaValue = pair.getRight();
Object metaValue = pair.right();
if(!(metaValue instanceof List)) {
throw new LoadException(
@@ -86,10 +86,10 @@ public class MetaListLikePreprocessor extends MetaPreprocessor<Meta> {
indexLevel.getIndex() >= begin &&
indexLevel.getIndex() <= end) {
String configName;
if(pair.getLeft().getName() == null) {
if(pair.left().getName() == null) {
configName = "Anonymous Configuration";
} else {
configName = pair.getLeft().getName();
configName = pair.left().getName();
}
return Optional.of("From configuration \"" + configName + "\"");
}

View File

@@ -60,7 +60,7 @@ public class MetaMapPreprocessor extends MetaPreprocessor<Meta> {
List<String> keys = (List<String>) loader.loadType(STRING_LIST.getAnnotatedType(), map.get("<<"), depthTracker);
keys.forEach(key -> {
Pair<Configuration, Object> pair = getMetaValue(key, depthTracker);
Object meta = pair.getRight();
Object meta = pair.right();
if(!(meta instanceof Map)) {
throw new LoadException(
"MetaMap injection candidate must be list, is type " + meta.getClass().getCanonicalName(),
@@ -69,10 +69,10 @@ public class MetaMapPreprocessor extends MetaPreprocessor<Meta> {
newMap.putAll((Map<?, ?>) meta);
String configName;
if(pair.getLeft().getName() == null) {
if(pair.left().getName() == null) {
configName = "Anonymous Configuration";
} else {
configName = pair.getLeft().getName();
configName = pair.left().getName();
}
depthTracker.addIntrinsicLevel(level -> {

View File

@@ -41,7 +41,7 @@ public class MetaStringPreprocessor extends MetaPreprocessor<Meta> {
public @NotNull <T> Result<T> process(AnnotatedType t, T c, ConfigLoader loader, Meta annotation, DepthTracker depthTracker) {
if(String.class.equals(t.getType()) && c instanceof String candidate) { // String is final so we use #equals
StringSubstitutor substitutor = new StringSubstitutor(key -> {
Object meta = getMetaValue(key, depthTracker).getRight();
Object meta = getMetaValue(key, depthTracker).right();
if(!(meta instanceof String) && !(meta instanceof Number) && !(meta instanceof Character) && !(meta instanceof Boolean)) {
throw new LoadException("MetaString template injection candidate must be string or primitive, is type " +
meta.getClass().getCanonicalName(), depthTracker);

View File

@@ -46,13 +46,13 @@ public class MetaValuePreprocessor extends MetaPreprocessor<Meta> {
Pair<Configuration, Object> pair = getMetaValue(value.substring(1), depthTracker);
String configName;
if(pair.getLeft().getName() == null) {
if(pair.left().getName() == null) {
configName = "Anonymous Configuration";
} else {
configName = pair.getLeft().getName();
configName = pair.left().getName();
}
return (Result<T>) Result.overwrite(pair.getRight(), depthTracker.intrinsic("From configuration \"" + configName + "\""));
return (Result<T>) Result.overwrite(pair.right(), depthTracker.intrinsic("From configuration \"" + configName + "\""));
}
}
return Result.noOp();

View File

@@ -33,7 +33,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@@ -158,7 +157,7 @@ public class OpenRegistryImpl<T> implements OpenRegistry<T> {
return objectIDs
.get(id)
.stream()
.collect(HashMap::new, (map, pair) -> map.put(pair.getLeft(), pair.getRight().getValue()), Map::putAll);
.collect(HashMap::new, (map, pair) -> map.put(pair.left(), pair.right().getValue()), Map::putAll);
}
public Map<RegistryKey, T> getDeadEntries() {