Reformat all code

Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
solonovamax
2021-08-30 17:34:44 -04:00
parent 1655381413
commit c445a0434d
753 changed files with 10461 additions and 8783 deletions

View File

@@ -3,124 +3,130 @@ import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.tectonic.config.Configuration;
import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.yaml.YamlConfiguration;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.config.preprocessor.MetaListLikePreprocessor;
import com.dfsek.terra.config.preprocessor.MetaMapPreprocessor;
import com.dfsek.terra.config.preprocessor.MetaNumberPreprocessor;
import com.dfsek.terra.config.preprocessor.MetaStringPreprocessor;
import com.dfsek.terra.config.preprocessor.MetaValuePreprocessor;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.config.preprocessor.MetaListLikePreprocessor;
import com.dfsek.terra.config.preprocessor.MetaMapPreprocessor;
import com.dfsek.terra.config.preprocessor.MetaNumberPreprocessor;
import com.dfsek.terra.config.preprocessor.MetaStringPreprocessor;
import com.dfsek.terra.config.preprocessor.MetaValuePreprocessor;
public class MetaTest {
@Test
public void testMetaList() {
Configuration meta = new YamlConfiguration(MetaTest.class.getResourceAsStream("/meta.yml"), "meta.yml");
Configuration metaTarget = new YamlConfiguration(MetaTest.class.getResourceAsStream("/metaTarget.yml"), "metaTarget.yml");
Map<String, Configuration> configurationMap = new HashMap<>();
configurationMap.put(meta.getName(), meta);
configurationMap.put(metaTarget.getName(), metaTarget);
ConfigLoader loader = new ConfigLoader();
loader.registerPreprocessor(Meta.class, new MetaStringPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaListLikePreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
loader.load(new MetaListConfig(), meta).list.forEach(System.out::println);
}
private static final class MetaListConfig implements ConfigTemplate {
@Value("list")
private @Meta List<@Meta String> list;
}
@Test
public void testMetaMap() {
Configuration meta = new YamlConfiguration(MetaTest.class.getResourceAsStream("/meta.yml"), "meta.yml");
Configuration metaTarget = new YamlConfiguration(MetaTest.class.getResourceAsStream("/metaTarget.yml"), "metaTarget.yml");
Map<String, Configuration> configurationMap = new HashMap<>();
configurationMap.put(meta.getName(), meta);
configurationMap.put(metaTarget.getName(), metaTarget);
ConfigLoader loader = new ConfigLoader();
loader.registerPreprocessor(Meta.class, new MetaStringPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaListLikePreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
loader.load(new MetaMapConfig(), meta).map.forEach((k, v) -> System.out.println(k + ": " + v));
}
private static final class MetaMapConfig implements ConfigTemplate {
@Value("map")
private @Meta Map<@Meta String, @Meta String> map;
}
@Test
public void testMetaString() {
Configuration meta = new YamlConfiguration(MetaTest.class.getResourceAsStream("/meta.yml"), "meta.yml");
Configuration metaTarget = new YamlConfiguration(MetaTest.class.getResourceAsStream("/metaTarget.yml"), "metaTarget.yml");
Map<String, Configuration> configurationMap = new HashMap<>();
configurationMap.put(meta.getName(), meta);
configurationMap.put(metaTarget.getName(), metaTarget);
ConfigLoader loader = new ConfigLoader();
loader.registerPreprocessor(Meta.class, new MetaStringPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaListLikePreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
System.out.println(loader.load(new MetaStringConfig(), meta).string);
}
private static final class MetaStringConfig implements ConfigTemplate {
@Value("string")
private @Meta String string;
}
@Test
public void testMetaNumber() {
Configuration meta = new YamlConfiguration(MetaTest.class.getResourceAsStream("/meta.yml"), "meta.yml");
Configuration metaTarget = new YamlConfiguration(MetaTest.class.getResourceAsStream("/metaTarget.yml"), "metaTarget.yml");
Map<String, Configuration> configurationMap = new HashMap<>();
configurationMap.put(meta.getName(), meta);
configurationMap.put(metaTarget.getName(), metaTarget);
ConfigLoader loader = new ConfigLoader();
loader.registerPreprocessor(Meta.class, new MetaStringPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaListLikePreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap));
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
System.out.println("int: " + loader.load(new MetaNumberConfig(), meta).integer);
System.out.println("double: " + loader.load(new MetaNumberConfig(), meta).aDouble);
}
private static final class MetaListConfig implements ConfigTemplate {
@Value("list")
private @Meta List<@Meta String> list;
}
private static final class MetaMapConfig implements ConfigTemplate {
@Value("map")
private @Meta Map<@Meta String, @Meta String> map;
}
private static final class MetaStringConfig implements ConfigTemplate {
@Value("string")
private @Meta String string;
}
private static final class MetaNumberConfig implements ConfigTemplate {
@Value("int")
private @Meta int integer;
@Value("double")
private @Meta double aDouble;
}

View File

@@ -1,5 +1,9 @@
package command;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import com.dfsek.terra.api.command.CommandManager;
import com.dfsek.terra.api.command.CommandTemplate;
import com.dfsek.terra.api.command.annotation.Argument;
@@ -15,18 +19,16 @@ import com.dfsek.terra.api.command.exception.InvalidArgumentsException;
import com.dfsek.terra.api.command.exception.MalformedCommandException;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.commands.TerraCommandManager;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.fail;
public class CommandTest {
@Test
public void subcommand() throws CommandException {
CommandManager manager = new TerraCommandManager(null);
manager.register("test", DemoParentCommand.class);
manager.execute("test", null, Arrays.asList("subcommand1", "first", "2"));
manager.execute("test", null, Arrays.asList("subcommand2", "first", "2"));
manager.execute("test", null, Arrays.asList("s1", "first", "2", "3.4"));
@@ -34,80 +36,80 @@ public class CommandTest {
manager.execute("test", null, Arrays.asList("sub1", "first", "2", "3.4"));
manager.execute("test", null, Arrays.asList("sub2", "first", "2"));
manager.execute("test", null, Arrays.asList("first", "2")); // Parent command args
System.out.println("ARGS: " + manager.getMaxArgumentDepth());
}
@Test
public void args() throws CommandException {
CommandManager manager = new TerraCommandManager(null);
manager.register("test", DemoCommand.class);
manager.execute("test", null, Arrays.asList("first", "2"));
manager.execute("test", null, Arrays.asList("first", "2", "3.4"));
}
@Test
public void argsBeforeFlags() throws CommandException {
CommandManager manager = new TerraCommandManager(null);
manager.register("test", DemoCommand.class);
try {
manager.execute("test", null, Arrays.asList("first", "-flag", "2"));
fail();
} catch(InvalidArgumentsException ignore) {
}
}
@Test
public void requiredArgsFirst() throws CommandException {
CommandManager manager = new TerraCommandManager(null);
manager.register("test", DemoInvalidCommand.class);
try {
manager.execute("test", null, Arrays.asList("first", "2"));
fail();
} catch(MalformedCommandException ignore) {
}
}
@Test
public void switches() throws CommandException {
CommandManager manager = new TerraCommandManager(null);
manager.register("test", DemoSwitchCommand.class);
manager.execute("test", null, Arrays.asList("first", "2"));
manager.execute("test", null, Arrays.asList("first", "2", "3.4"));
manager.execute("test", null, Arrays.asList("first", "2", "-a"));
manager.execute("test", null, Arrays.asList("first", "2", "3.4", "-b"));
manager.execute("test", null, Arrays.asList("first", "2", "-aSwitch"));
manager.execute("test", null, Arrays.asList("first", "2", "3.4", "-bSwitch"));
manager.execute("test", null, Arrays.asList("first", "2", "-aSwitch", "-b"));
manager.execute("test", null, Arrays.asList("first", "2", "3.4", "-bSwitch", "-a"));
}
@Command(
arguments = {
@Argument(value = "arg0"),
@Argument("arg0"),
@Argument(value = "arg1", argumentParser = IntegerArgumentParser.class),
@Argument(value = "arg2", required = false, argumentParser = DoubleArgumentParser.class, defaultValue = "0")
}
)
public static final class DemoCommand implements CommandTemplate {
@ArgumentTarget("arg0")
private String arg0;
@ArgumentTarget("arg1")
private Integer arg1;
@ArgumentTarget("arg2")
private Double arg2;
@Override
public void execute(CommandSender sender) {
System.out.println(arg0);
@@ -115,91 +117,94 @@ public class CommandTest {
System.out.println(arg2);
}
}
@Command(
arguments = {
@Argument(value = "arg0"),
@Argument(value = "arg1"),
@Argument("arg0"),
@Argument("arg1"),
@Argument(value = "arg2", required = false)
},
switches = {
@Switch(value = "a", aliases = {"aSwitch"}),
@Switch(value = "b", aliases = {"bSwitch"})
@Switch(value = "a", aliases = "aSwitch"),
@Switch(value = "b", aliases = "bSwitch")
}
)
public static final class DemoSwitchCommand implements CommandTemplate {
@ArgumentTarget("arg0")
private String arg0;
@ArgumentTarget("arg1")
private String arg1;
@ArgumentTarget("arg2")
private String arg2;
@SwitchTarget("a")
private boolean a;
@SwitchTarget("b")
private boolean b;
@Override
public void execute(CommandSender sender) {
System.out.println(arg0);
System.out.println(arg1);
System.out.println(arg2);
System.out.println("A: " + a);
System.out.println("B: " + b);
}
}
@Command(
arguments = {
@Argument(value = "arg0"),
@Argument("arg0"),
@Argument(value = "arg2", required = false), // optional arguments must be last. this command is invalid.
@Argument(value = "arg1")
@Argument("arg1")
}
)
public static final class DemoInvalidCommand implements CommandTemplate {
@Override
public void execute(CommandSender sender) {
throw new Error("this should never be reached");
}
}
@Command(
arguments = {
@Argument(value = "arg0"),
@Argument(value = "arg1"),
@Argument("arg0"),
@Argument("arg1"),
@Argument(value = "arg2", required = false),
},
subcommands = {
@Subcommand(
value = "subcommand1",
aliases = {"s1", "sub1"},
aliases = { "s1", "sub1" },
clazz = DemoChildCommand.class
),
@Subcommand(
value = "subcommand2",
aliases = {"s2", "sub2"},
aliases = { "s2", "sub2" },
clazz = DemoChildCommand.class // Duplicate command intentional.
)
)
}
)
public static final class DemoParentCommand implements CommandTemplate {
@ArgumentTarget("arg0")
private String arg0;
@ArgumentTarget("arg1")
private String arg1;
@ArgumentTarget("arg2")
private String arg2;
@Override
public void execute(CommandSender sender) {
System.out.println(arg0);
@@ -207,25 +212,26 @@ public class CommandTest {
System.out.println(arg2);
}
}
@Command(
arguments = {
@Argument(value = "arg0"),
@Argument(value = "arg1"),
@Argument("arg0"),
@Argument("arg1"),
@Argument(value = "arg2", required = false),
}
)
public static final class DemoChildCommand implements CommandTemplate {
@ArgumentTarget("arg0")
private String arg0;
@ArgumentTarget("arg1")
private String arg1;
@ArgumentTarget("arg2")
private String arg2;
@Override
public void execute(CommandSender sender) {
System.out.println(arg0);

View File

@@ -3,21 +3,23 @@ package noise;
import com.dfsek.tectonic.annotations.Default;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
public class ColorConfigTemplate implements ConfigTemplate {
@Value("colors")
private @Meta ProbabilityCollection<@Meta Integer> colors;
public class ColorConfigTemplate implements ConfigTemplate {
@Value("enable")
@Default
private @Meta boolean enable = false;
private @Meta
final boolean enable = false;
@Value("colors")
private @Meta ProbabilityCollection<@Meta Integer> colors;
public boolean enable() {
return enable;
}
public ProbabilityCollection<Integer> getColors() {
return colors;
}

View File

@@ -2,6 +2,7 @@ package noise;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.terra.api.noise.NoiseSampler;
@@ -9,7 +10,7 @@ import com.dfsek.terra.api.noise.NoiseSampler;
public class NoiseConfigTemplate implements ConfigTemplate {
@Value(".")
private NoiseSampler builder;
public NoiseSampler getBuilder() {
return builder;
}

View File

@@ -3,20 +3,21 @@ package profiler;
import com.dfsek.terra.api.profiler.Profiler;
import com.dfsek.terra.profiler.ProfilerImpl;
public class ProfilerTest {
private static final Profiler PROFILER = new ProfilerImpl();
//@Test
public static void main(String... a) throws InterruptedException {
//PROFILER.start();
for(int i = 0; i < 1000; i++) {
doThing();
}
for(int i = 0; i < 100; i++) {
doThirdOtherThing();
}
for(int i = 0; i < 100; i++) {
doOtherThing();
}
@@ -28,12 +29,12 @@ public class ProfilerTest {
PROFILER.pop("thing");
PROFILER.push("thing4");
PROFILER.pop("thing4");
PROFILER.getTimings().forEach((id, timings) -> {
System.out.println(id + ": " + timings.toString());
});
}
private static void doThing() throws InterruptedException {
PROFILER.push("thing");
Thread.sleep(1);
@@ -41,7 +42,7 @@ public class ProfilerTest {
thing4();
PROFILER.pop("thing");
}
private static void doOtherThing() throws InterruptedException {
PROFILER.push("thing2");
Thread.sleep(2);
@@ -49,13 +50,13 @@ public class ProfilerTest {
thing4();
PROFILER.pop("thing2");
}
private static void doThirdOtherThing() throws InterruptedException {
PROFILER.push("thing3");
Thread.sleep(2);
PROFILER.pop("thing3");
}
private static void thing4() throws InterruptedException {
PROFILER.push("thing4");
Thread.sleep(2);