mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-24 00:56:38 +00:00
use expression switches
This commit is contained in:
@@ -43,7 +43,7 @@ public class BiomePipeline {
|
||||
|
||||
public static final class BiomePipelineBuilder {
|
||||
private final int init;
|
||||
List<Stage> stages = new ArrayList<>();
|
||||
private final List<Stage> stages = new ArrayList<>();
|
||||
private int expand;
|
||||
|
||||
public BiomePipelineBuilder(int init) {
|
||||
|
||||
@@ -27,7 +27,7 @@ public class BiomePipelineProvider implements BiomeProvider {
|
||||
holderCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(main == null ? 32 : main.getTerraConfig().getProviderCache())
|
||||
.build(
|
||||
new CacheLoader<SeededVector, BiomeHolder>() {
|
||||
new CacheLoader<>() {
|
||||
@Override
|
||||
public BiomeHolder load(@NotNull SeededVector key) {
|
||||
return pipeline.getBiomes(key.x, key.z, key.seed);
|
||||
|
||||
@@ -333,37 +333,22 @@ public class CellularSampler extends NoiseFunction {
|
||||
distance1 = fastSqrt(distance1);
|
||||
}
|
||||
}
|
||||
|
||||
switch(returnType) {
|
||||
case CellValue:
|
||||
return closestHash * (1 / 2147483648.0);
|
||||
case Distance:
|
||||
return distance0 - 1;
|
||||
case Distance2:
|
||||
return distance1 - 1;
|
||||
case Distance2Add:
|
||||
return (distance1 + distance0) * 0.5 - 1;
|
||||
case Distance2Sub:
|
||||
return distance1 - distance0 - 1;
|
||||
case Distance2Mul:
|
||||
return distance1 * distance0 * 0.5 - 1;
|
||||
case Distance2Div:
|
||||
return distance0 / distance1 - 1;
|
||||
case NoiseLookup:
|
||||
return noiseLookup.getNoiseSeeded(sl, center.getX(), center.getZ());
|
||||
case Distance3:
|
||||
return distance2 - 1;
|
||||
case Distance3Add:
|
||||
return (distance2 + distance0) * 0.5 - 1;
|
||||
case Distance3Sub:
|
||||
return distance2 - distance0 - 1;
|
||||
case Distance3Mul:
|
||||
return distance2 * distance0 - 1;
|
||||
case Distance3Div:
|
||||
return distance0 / distance2 - 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return switch(returnType) {
|
||||
case CellValue -> closestHash * (1 / 2147483648.0);
|
||||
case Distance -> distance0 - 1;
|
||||
case Distance2 -> distance1 - 1;
|
||||
case Distance2Add -> (distance1 + distance0) * 0.5 - 1;
|
||||
case Distance2Sub -> distance1 - distance0 - 1;
|
||||
case Distance2Mul -> distance1 * distance0 * 0.5 - 1;
|
||||
case Distance2Div -> distance0 / distance1 - 1;
|
||||
case NoiseLookup -> noiseLookup.getNoiseSeeded(sl, center.getX(), center.getZ());
|
||||
case Distance3 -> distance2 - 1;
|
||||
case Distance3Add -> (distance2 + distance0) * 0.5 - 1;
|
||||
case Distance3Sub -> distance2 - distance0 - 1;
|
||||
case Distance3Mul -> distance2 * distance0 - 1;
|
||||
case Distance3Div -> distance0 / distance2 - 1;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -508,37 +493,22 @@ public class CellularSampler extends NoiseFunction {
|
||||
distance1 = fastSqrt(distance1);
|
||||
}
|
||||
}
|
||||
|
||||
switch(returnType) {
|
||||
case CellValue:
|
||||
return closestHash * (1 / 2147483648.0);
|
||||
case Distance:
|
||||
return distance0 - 1;
|
||||
case Distance2:
|
||||
return distance1 - 1;
|
||||
case Distance2Add:
|
||||
return (distance1 + distance0) * 0.5 - 1;
|
||||
case Distance2Sub:
|
||||
return distance1 - distance0 - 1;
|
||||
case Distance2Mul:
|
||||
return distance1 * distance0 * 0.5 - 1;
|
||||
case Distance2Div:
|
||||
return distance0 / distance1 - 1;
|
||||
case NoiseLookup:
|
||||
return noiseLookup.getNoiseSeeded(sl, center.getX(), center.getY(), center.getZ());
|
||||
case Distance3:
|
||||
return distance2 - 1;
|
||||
case Distance3Add:
|
||||
return (distance2 + distance0) * 0.5 - 1;
|
||||
case Distance3Sub:
|
||||
return distance2 - distance0 - 1;
|
||||
case Distance3Mul:
|
||||
return distance2 * distance0 - 1;
|
||||
case Distance3Div:
|
||||
return distance0 / distance2 - 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return switch(returnType) {
|
||||
case CellValue -> closestHash * (1 / 2147483648.0);
|
||||
case Distance -> distance0 - 1;
|
||||
case Distance2 -> distance1 - 1;
|
||||
case Distance2Add -> (distance1 + distance0) * 0.5 - 1;
|
||||
case Distance2Sub -> distance1 - distance0 - 1;
|
||||
case Distance2Mul -> distance1 * distance0 * 0.5 - 1;
|
||||
case Distance2Div -> distance0 / distance1 - 1;
|
||||
case NoiseLookup -> noiseLookup.getNoiseSeeded(sl, center.getX(), center.getY(), center.getZ());
|
||||
case Distance3 -> distance2 - 1;
|
||||
case Distance3Add -> (distance2 + distance0) * 0.5 - 1;
|
||||
case Distance3Sub -> distance2 - distance0 - 1;
|
||||
case Distance3Mul -> distance2 * distance0 - 1;
|
||||
case Distance3Div -> distance0 / distance2 - 1;
|
||||
};
|
||||
}
|
||||
|
||||
public enum DistanceFunction {
|
||||
|
||||
@@ -67,8 +67,8 @@ public class HashMapDoubleDouble extends HashIntrinsic {
|
||||
}
|
||||
|
||||
public boolean containsValue(double value) {
|
||||
for(int i = 0; i < this.table.length; ++i) {
|
||||
for(HashMapDoubleDouble.Entry e = this.table[i]; e != null; e = e.next) {
|
||||
for(Entry entry : this.table) {
|
||||
for(Entry e = entry; e != null; e = e.next) {
|
||||
if(value == e.value) {
|
||||
return true;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class HashMapDoubleDouble extends HashIntrinsic {
|
||||
}
|
||||
|
||||
public long memoryEstimate(int ptrsize) {
|
||||
return (long) ptrsize * (long) (this.capMinus1 + this.size + 1) + (long) (this.size * 64 / 4);
|
||||
return (long) ptrsize * (long) (this.capMinus1 + this.size + 1) + (this.size * 64L / 4);
|
||||
}
|
||||
|
||||
public HashMapDoubleDouble.Iterator iterator() {
|
||||
|
||||
@@ -45,8 +45,7 @@ public class Entry {
|
||||
if(entry.containsKey("functions")) {
|
||||
for(Object function : (JSONArray) entry.get("functions")) {
|
||||
switch(((String) ((JSONObject) function).get("function"))) {
|
||||
case "minecraft:set_count":
|
||||
case "set_count":
|
||||
case "minecraft:set_count", "set_count" -> {
|
||||
Object loot = ((JSONObject) function).get("count");
|
||||
long max, min;
|
||||
if(loot instanceof Long) {
|
||||
@@ -57,15 +56,13 @@ public class Entry {
|
||||
min = (long) ((JSONObject) loot).get("min");
|
||||
}
|
||||
functions.add(new AmountFunction(FastMath.toIntExact(min), FastMath.toIntExact(max)));
|
||||
break;
|
||||
case "minecraft:set_damage":
|
||||
case "set_damage":
|
||||
}
|
||||
case "minecraft:set_damage", "set_damage" -> {
|
||||
long maxDamage = (long) ((JSONObject) ((JSONObject) function).get("damage")).get("max");
|
||||
long minDamage = (long) ((JSONObject) ((JSONObject) function).get("damage")).get("min");
|
||||
functions.add(new DamageFunction(FastMath.toIntExact(minDamage), FastMath.toIntExact(maxDamage)));
|
||||
break;
|
||||
case "minecraft:enchant_with_levels":
|
||||
case "enchant_with_levels":
|
||||
}
|
||||
case "minecraft:enchant_with_levels", "enchant_with_levels" -> {
|
||||
long maxEnchant = (long) ((JSONObject) ((JSONObject) function).get("levels")).get("max");
|
||||
long minEnchant = (long) ((JSONObject) ((JSONObject) function).get("levels")).get("min");
|
||||
JSONArray disabled = null;
|
||||
@@ -73,7 +70,7 @@ public class Entry {
|
||||
disabled = (JSONArray) ((JSONObject) function).get("disabled_enchants");
|
||||
functions.add(
|
||||
new EnchantFunction(FastMath.toIntExact(minEnchant), FastMath.toIntExact(maxEnchant), disabled, main));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,17 +98,14 @@ public class Parser {
|
||||
ParserUtil.checkType(identifier, Token.Type.IF_STATEMENT, Token.Type.WHILE_LOOP, Token.Type.FOR_LOOP);
|
||||
|
||||
ParserUtil.checkType(tokens.consume(), Token.Type.GROUP_BEGIN);
|
||||
|
||||
switch(identifier.getType()) {
|
||||
case FOR_LOOP:
|
||||
return parseForLoop(tokens, variableMap, identifier.getPosition());
|
||||
case IF_STATEMENT:
|
||||
return parseIfStatement(tokens, variableMap, identifier.getPosition(), loop);
|
||||
case WHILE_LOOP:
|
||||
return parseWhileLoop(tokens, variableMap, identifier.getPosition());
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown keyword " + identifier.getContent() + ": " + identifier.getPosition());
|
||||
}
|
||||
|
||||
return switch(identifier.getType()) {
|
||||
case FOR_LOOP -> parseForLoop(tokens, variableMap, identifier.getPosition());
|
||||
case IF_STATEMENT -> parseIfStatement(tokens, variableMap, identifier.getPosition(), loop);
|
||||
case WHILE_LOOP -> parseWhileLoop(tokens, variableMap, identifier.getPosition());
|
||||
default -> throw new UnsupportedOperationException(
|
||||
"Unknown keyword " + identifier.getContent() + ": " + identifier.getPosition());
|
||||
};
|
||||
}
|
||||
|
||||
private WhileKeyword parseWhileLoop(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap, Position start)
|
||||
|
||||
@@ -90,17 +90,13 @@ public class ParserUtil {
|
||||
}
|
||||
|
||||
public static Returnable.ReturnType getVariableReturnType(Token varToken) throws ParseException {
|
||||
switch(varToken.getType()) {
|
||||
case NUMBER_VARIABLE:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case STRING_VARIABLE:
|
||||
return Returnable.ReturnType.STRING;
|
||||
case BOOLEAN_VARIABLE:
|
||||
return Returnable.ReturnType.BOOLEAN;
|
||||
default:
|
||||
throw new ParseException("Unexpected token " + varToken.getType() + "; expected variable declaration",
|
||||
varToken.getPosition());
|
||||
}
|
||||
return switch(varToken.getType()) {
|
||||
case NUMBER_VARIABLE -> Returnable.ReturnType.NUMBER;
|
||||
case STRING_VARIABLE -> Returnable.ReturnType.STRING;
|
||||
case BOOLEAN_VARIABLE -> Returnable.ReturnType.BOOLEAN;
|
||||
default -> throw new ParseException("Unexpected token " + varToken.getType() + "; expected variable declaration",
|
||||
varToken.getPosition());
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean hasPrecedence(Token.Type first, Token.Type second) {
|
||||
|
||||
@@ -9,17 +9,17 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
public interface Function<T> extends Returnable<T> {
|
||||
Function<?> NULL = new Function<Object>() {
|
||||
Function<?> NULL = new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return null;
|
||||
|
||||
@@ -33,15 +33,9 @@ public class Declaration<T> implements Item<T> {
|
||||
public T apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||
T result = value.apply(implementationArguments, variableMap);
|
||||
switch(type) {
|
||||
case NUMBER:
|
||||
variableMap.put(identifier, new NumberVariable((Number) result, position));
|
||||
break;
|
||||
case BOOLEAN:
|
||||
variableMap.put(identifier, new BooleanVariable((Boolean) result, position));
|
||||
break;
|
||||
case STRING:
|
||||
variableMap.put(identifier, new StringVariable((String) result, position));
|
||||
break;
|
||||
case NUMBER -> variableMap.put(identifier, new NumberVariable((Number) result, position));
|
||||
case BOOLEAN -> variableMap.put(identifier, new BooleanVariable((Boolean) result, position));
|
||||
case STRING -> variableMap.put(identifier, new StringVariable((String) result, position));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -22,19 +22,19 @@ public class BinaryNumberFunctionBuilder implements FunctionBuilder<Function<Num
|
||||
|
||||
@Override
|
||||
public Function<Number> build(List<Returnable<?>> argumentList, Position position) {
|
||||
return new Function<Number>() {
|
||||
return new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Number apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||
return function.apply(((Returnable<Number>) argumentList.get(0)).apply(implementationArguments, variableMap),
|
||||
((Returnable<Number>) argumentList.get(1)).apply(implementationArguments, variableMap));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
|
||||
@@ -30,13 +30,9 @@ public class BiomeFunctionBuilder implements FunctionBuilder<BiomeFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,17 +42,11 @@ public class BlockFunctionBuilder implements FunctionBuilder<BlockFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
case 4:
|
||||
return Returnable.ReturnType.BOOLEAN;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
case 4 -> Returnable.ReturnType.BOOLEAN;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,9 @@ public class CheckBlockFunctionBuilder implements FunctionBuilder<CheckBlockFunc
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,13 +31,9 @@ public class CheckFunctionBuilder implements FunctionBuilder<CheckFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,15 +31,10 @@ public class EntityFunctionBuilder implements FunctionBuilder<EntityFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +27,9 @@ public class GetMarkFunctionBuilder implements FunctionBuilder<GetMarkFunction>
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,15 +37,10 @@ public class LootFunctionBuilder implements FunctionBuilder<LootFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,15 +31,10 @@ public class PullFunctionBuilder implements FunctionBuilder<PullFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,15 +28,10 @@ public class SetMarkFunctionBuilder implements FunctionBuilder<SetMarkFunction>
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,15 +32,10 @@ public class StateFunctionBuilder implements FunctionBuilder<StateFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,13 +40,9 @@ public class StructureFunctionBuilder implements FunctionBuilder<StructureFuncti
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return Returnable.ReturnType.STRING;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
default -> Returnable.ReturnType.STRING;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ public class UnaryBooleanFunctionBuilder implements FunctionBuilder<Function<Voi
|
||||
|
||||
@Override
|
||||
public Function<Void> build(List<Returnable<?>> argumentList, Position position) {
|
||||
return new Function<Void>() {
|
||||
return new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Void apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||
@@ -36,7 +36,7 @@ public class UnaryBooleanFunctionBuilder implements FunctionBuilder<Function<Voi
|
||||
(TerraImplementationArguments) implementationArguments);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
|
||||
@@ -21,18 +21,18 @@ public class UnaryNumberFunctionBuilder implements FunctionBuilder<Function<Numb
|
||||
|
||||
@Override
|
||||
public Function<Number> build(List<Returnable<?>> argumentList, Position position) {
|
||||
return new Function<Number>() {
|
||||
return new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Number apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||
return function.apply(((Returnable<Number>) argumentList.get(0)).apply(implementationArguments, variableMap));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
|
||||
@@ -21,19 +21,19 @@ public class UnaryStringFunctionBuilder implements FunctionBuilder<Function<Void
|
||||
|
||||
@Override
|
||||
public Function<Void> build(List<Returnable<?>> argumentList, Position position) {
|
||||
return new Function<Void>() {
|
||||
return new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Void apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||
function.accept(((Returnable<String>) argumentList.get(0)).apply(implementationArguments, variableMap));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
|
||||
@@ -23,17 +23,17 @@ public class ZeroArgFunctionBuilder<T> implements FunctionBuilder<Function<T>> {
|
||||
|
||||
@Override
|
||||
public Function<T> build(List<Returnable<?>> argumentList, Position position) {
|
||||
return new Function<T>() {
|
||||
return new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public T apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||
return function.apply((TerraImplementationArguments) implementationArguments);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
|
||||
@@ -39,14 +39,11 @@ public class ParserTest {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
return Returnable.ReturnType.STRING;
|
||||
case 1:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0 -> Returnable.ReturnType.STRING;
|
||||
case 1 -> Returnable.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user