mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
Make Pair a record
This commit is contained in:
@@ -121,11 +121,11 @@ public class Scope {
|
||||
}
|
||||
|
||||
public int getIndex(String id) {
|
||||
return indices.get(id).getLeft();
|
||||
return indices.get(id).left();
|
||||
}
|
||||
|
||||
public ReturnType getType(String id) {
|
||||
return indices.get(id).getRight();
|
||||
return indices.get(id).right();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ public class IfKeyword implements Keyword<Block.ReturnInfo<?>> {
|
||||
if(statement.apply(implementationArguments, scope)) return conditional.apply(implementationArguments, scope);
|
||||
else {
|
||||
for(Pair<Returnable<Boolean>, Block> pair : elseIf) {
|
||||
if(pair.getLeft().apply(implementationArguments, scope)) {
|
||||
return pair.getRight().apply(implementationArguments, scope);
|
||||
if(pair.left().apply(implementationArguments, scope)) {
|
||||
return pair.right().apply(implementationArguments, scope);
|
||||
}
|
||||
}
|
||||
if(elseBlock != null) return elseBlock.apply(implementationArguments, scope);
|
||||
|
||||
@@ -17,15 +17,8 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
|
||||
public final class Pair<L, R> {
|
||||
public record Pair<L, R>(L left, R right) implements Bifunctor{
|
||||
private static final Pair<?, ?> NULL = new Pair<>(null, null);
|
||||
private final L left;
|
||||
private final R right;
|
||||
|
||||
private Pair(L left, R right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public static <L, R, T> Function<Pair<L, R>, Pair<T, R>> mapLeft(Function<L, T> function) {
|
||||
return pair -> of(function.apply(pair.left), pair.right);
|
||||
@@ -76,19 +69,6 @@ public final class Pair<L, R> {
|
||||
return Mutable.of(left, right);
|
||||
}
|
||||
|
||||
public R getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
public L getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(left, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Pair<?, ?> that)) return false;
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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 + "\"");
|
||||
}
|
||||
|
||||
@@ -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 -> {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -62,12 +62,12 @@ public final class TerraCLI implements Callable<Integer> {
|
||||
|
||||
if(!noSave) {
|
||||
world.serialize().parallel().forEach(mcaFile -> {
|
||||
Vector2Int pos = mcaFile.getLeft();
|
||||
Vector2Int pos = mcaFile.left();
|
||||
String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ());
|
||||
LOGGER.info("Writing region ({}, {}) to {}", pos.getX(), pos.getZ(), name);
|
||||
|
||||
try {
|
||||
MCAUtil.write(mcaFile.getRight(), name);
|
||||
MCAUtil.write(mcaFile.right(), name);
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -37,15 +37,15 @@ public final class TagUtil {
|
||||
PresetUtil
|
||||
.getPresets()
|
||||
.forEach(pair -> MinecraftUtil
|
||||
.getEntry(registry, pair.getLeft())
|
||||
.getEntry(registry, pair.left())
|
||||
.ifPresentOrElse(
|
||||
preset -> {
|
||||
boolean useExtendedTag = pair.getRight(); // Get the boolean value from the pair
|
||||
boolean useExtendedTag = pair.right(); // Get the boolean value from the pair
|
||||
collect
|
||||
.computeIfAbsent(useExtendedTag ? WorldPresetTags.EXTENDED : WorldPresetTags.NORMAL, tag -> new ArrayList<>())
|
||||
.add(preset);
|
||||
},
|
||||
() -> logger.error("Preset {} does not exist!", pair.getLeft())));
|
||||
() -> logger.error("Preset {} does not exist!", pair.left())));
|
||||
|
||||
registry.startTagReload(new RegistryTags<>(registry.getKey(), collect)).apply();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user