From 7903343ac0d3a55880369778952e679b2a44a4e5 Mon Sep 17 00:00:00 2001 From: Speiger Date: Wed, 11 Nov 2020 21:33:59 +0100 Subject: [PATCH] Removed the double foldering and started some seriouse work. --- .../.classpath => .classpath | 0 .../.gitattributes => .gitattributes | 0 Primitive-Collections/.project => .project | 0 Primitive-Collections/.gitignore | 5 -- .../speiger/assets/collections/cache.bin | 1 - .../collections/templates/List.template | 11 --- .../build.gradle => build.gradle | 0 .../wrapper/gradle-wrapper.properties | 0 Primitive-Collections/gradlew => gradlew | 0 .../gradlew.bat => gradlew.bat | 0 .../settings.gradle => settings.gradle | 0 .../src/builder/base/ConditionedSegment.java | 0 .../speiger/src/builder/base/Segment.java | 0 .../speiger/src/builder/base/Template.java | 24 ------ .../src/builder/conditions/AndCondition.java | 0 .../src/builder/conditions/FlagCondition.java | 0 .../src/builder/conditions/ICondition.java | 0 .../src/builder/conditions/OrCondition.java | 0 .../src/builder/example/GlobalVariables.java | 44 +++++++++++ .../src/builder/example/TestBuilder.java | 73 +++++++++++-------- .../src/builder/mappers/InjectMapper.java | 0 .../src/builder/mappers/SimpleMapper.java | 0 .../speiger/src/builder/misc/FileUtils.java | 0 .../java/speiger/src/builder/misc/Tuple.java | 0 .../src/builder/processor/BuildTask.java | 8 +- .../builder/processor/TemplateProcess.java | 6 +- .../builder/processor/TemplateProcessor.java | 13 +++- .../java/speiger/src/collections/.gitignore | 0 .../speiger/assets/collections/cache.bin | 2 + .../templates/functions/Consumer.template | 22 ++++++ 30 files changed, 132 insertions(+), 77 deletions(-) rename Primitive-Collections/.classpath => .classpath (100%) rename Primitive-Collections/.gitattributes => .gitattributes (100%) rename Primitive-Collections/.project => .project (100%) delete mode 100644 Primitive-Collections/.gitignore delete mode 100644 Primitive-Collections/src/main/resources/speiger/assets/collections/cache.bin delete mode 100644 Primitive-Collections/src/main/resources/speiger/assets/collections/templates/List.template rename Primitive-Collections/build.gradle => build.gradle (100%) rename {Primitive-Collections/gradle => gradle}/wrapper/gradle-wrapper.properties (100%) rename Primitive-Collections/gradlew => gradlew (100%) rename Primitive-Collections/gradlew.bat => gradlew.bat (100%) rename Primitive-Collections/settings.gradle => settings.gradle (100%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/base/ConditionedSegment.java (100%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/base/Segment.java (100%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/base/Template.java (74%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/conditions/AndCondition.java (100%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/conditions/FlagCondition.java (100%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/conditions/ICondition.java (100%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/conditions/OrCondition.java (100%) create mode 100644 src/main/java/speiger/src/builder/example/GlobalVariables.java rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/example/TestBuilder.java (50%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/mappers/InjectMapper.java (100%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/mappers/SimpleMapper.java (100%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/misc/FileUtils.java (100%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/misc/Tuple.java (100%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/processor/BuildTask.java (91%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/processor/TemplateProcess.java (86%) rename {Primitive-Collections/src => src}/main/java/speiger/src/builder/processor/TemplateProcessor.java (89%) rename {Primitive-Collections/src => src}/main/java/speiger/src/collections/.gitignore (100%) create mode 100644 src/main/resources/speiger/assets/collections/cache.bin create mode 100644 src/main/resources/speiger/assets/collections/templates/functions/Consumer.template diff --git a/Primitive-Collections/.classpath b/.classpath similarity index 100% rename from Primitive-Collections/.classpath rename to .classpath diff --git a/Primitive-Collections/.gitattributes b/.gitattributes similarity index 100% rename from Primitive-Collections/.gitattributes rename to .gitattributes diff --git a/Primitive-Collections/.project b/.project similarity index 100% rename from Primitive-Collections/.project rename to .project diff --git a/Primitive-Collections/.gitignore b/Primitive-Collections/.gitignore deleted file mode 100644 index 1b6985c..0000000 --- a/Primitive-Collections/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Ignore Gradle project-specific cache directory -.gradle - -# Ignore Gradle build output directory -build diff --git a/Primitive-Collections/src/main/resources/speiger/assets/collections/cache.bin b/Primitive-Collections/src/main/resources/speiger/assets/collections/cache.bin deleted file mode 100644 index bda9a21..0000000 --- a/Primitive-Collections/src/main/resources/speiger/assets/collections/cache.bin +++ /dev/null @@ -1 +0,0 @@ -List=81eefe88c5fd5080b139b1b85e11f85d diff --git a/Primitive-Collections/src/main/resources/speiger/assets/collections/templates/List.template b/Primitive-Collections/src/main/resources/speiger/assets/collections/templates/List.template deleted file mode 100644 index cbb4069..0000000 --- a/Primitive-Collections/src/main/resources/speiger/assets/collections/templates/List.template +++ /dev/null @@ -1,11 +0,0 @@ -package speiger.src.collections.example; - -import java.util.List; - -public interface LISTKEY_GENERIC_TYPE extends List -{ -#if !OBJECT - public void add(KEY_TYPE e); -#endif - public default boolean add(CLASS_TYPE e) {return true;} -} \ No newline at end of file diff --git a/Primitive-Collections/build.gradle b/build.gradle similarity index 100% rename from Primitive-Collections/build.gradle rename to build.gradle diff --git a/Primitive-Collections/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from Primitive-Collections/gradle/wrapper/gradle-wrapper.properties rename to gradle/wrapper/gradle-wrapper.properties diff --git a/Primitive-Collections/gradlew b/gradlew similarity index 100% rename from Primitive-Collections/gradlew rename to gradlew diff --git a/Primitive-Collections/gradlew.bat b/gradlew.bat similarity index 100% rename from Primitive-Collections/gradlew.bat rename to gradlew.bat diff --git a/Primitive-Collections/settings.gradle b/settings.gradle similarity index 100% rename from Primitive-Collections/settings.gradle rename to settings.gradle diff --git a/Primitive-Collections/src/main/java/speiger/src/builder/base/ConditionedSegment.java b/src/main/java/speiger/src/builder/base/ConditionedSegment.java similarity index 100% rename from Primitive-Collections/src/main/java/speiger/src/builder/base/ConditionedSegment.java rename to src/main/java/speiger/src/builder/base/ConditionedSegment.java diff --git a/Primitive-Collections/src/main/java/speiger/src/builder/base/Segment.java b/src/main/java/speiger/src/builder/base/Segment.java similarity index 100% rename from Primitive-Collections/src/main/java/speiger/src/builder/base/Segment.java rename to src/main/java/speiger/src/builder/base/Segment.java diff --git a/Primitive-Collections/src/main/java/speiger/src/builder/base/Template.java b/src/main/java/speiger/src/builder/base/Template.java similarity index 74% rename from Primitive-Collections/src/main/java/speiger/src/builder/base/Template.java rename to src/main/java/speiger/src/builder/base/Template.java index 7ff7a7b..8c86243 100644 --- a/Primitive-Collections/src/main/java/speiger/src/builder/base/Template.java +++ b/src/main/java/speiger/src/builder/base/Template.java @@ -1,12 +1,9 @@ package speiger.src.builder.base; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.StringJoiner; @@ -48,27 +45,6 @@ public class Template return result; } - public static void main(String...args) - { - try - { - Path path = new File("./src/main/resources/speiger/assets/collections/templates/List.template").toPath(); - Template template = parse(path); - Set parsePool = new HashSet<>(); - parsePool.add("DEPEND"); - parsePool.add("SUB_TEST"); - parsePool.add("TEST_0"); - parsePool.add("TEST_1"); - parsePool.add("TEST_2"); - System.out.println(path.getFileName().toString()); - System.out.println(template.build(parsePool, Collections.emptyList())); - } - catch(IOException e) - { - e.printStackTrace(); - } - } - public static Template parse(Path file) throws IOException { List segments = new ArrayList(); diff --git a/Primitive-Collections/src/main/java/speiger/src/builder/conditions/AndCondition.java b/src/main/java/speiger/src/builder/conditions/AndCondition.java similarity index 100% rename from Primitive-Collections/src/main/java/speiger/src/builder/conditions/AndCondition.java rename to src/main/java/speiger/src/builder/conditions/AndCondition.java diff --git a/Primitive-Collections/src/main/java/speiger/src/builder/conditions/FlagCondition.java b/src/main/java/speiger/src/builder/conditions/FlagCondition.java similarity index 100% rename from Primitive-Collections/src/main/java/speiger/src/builder/conditions/FlagCondition.java rename to src/main/java/speiger/src/builder/conditions/FlagCondition.java diff --git a/Primitive-Collections/src/main/java/speiger/src/builder/conditions/ICondition.java b/src/main/java/speiger/src/builder/conditions/ICondition.java similarity index 100% rename from Primitive-Collections/src/main/java/speiger/src/builder/conditions/ICondition.java rename to src/main/java/speiger/src/builder/conditions/ICondition.java diff --git a/Primitive-Collections/src/main/java/speiger/src/builder/conditions/OrCondition.java b/src/main/java/speiger/src/builder/conditions/OrCondition.java similarity index 100% rename from Primitive-Collections/src/main/java/speiger/src/builder/conditions/OrCondition.java rename to src/main/java/speiger/src/builder/conditions/OrCondition.java diff --git a/src/main/java/speiger/src/builder/example/GlobalVariables.java b/src/main/java/speiger/src/builder/example/GlobalVariables.java new file mode 100644 index 0000000..99df5bb --- /dev/null +++ b/src/main/java/speiger/src/builder/example/GlobalVariables.java @@ -0,0 +1,44 @@ +package speiger.src.builder.example; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.function.UnaryOperator; + +import speiger.src.builder.mappers.SimpleMapper; +import speiger.src.builder.processor.TemplateProcess; + +public class GlobalVariables +{ + String fileName; + String folderName; + List> operators = new ArrayList<>(); + Set flags = new LinkedHashSet<>(); + + public GlobalVariables(String fileName, String folderName) + { + this.fileName = fileName; + this.folderName = folderName; + } + + public GlobalVariables createInitials(String classType, String keyType) + { + operators.add(new SimpleMapper("CLASS_TYPE", classType)); + operators.add(new SimpleMapper("KEY_TYPE", keyType)); + return this; + } + + public GlobalVariables createClassTypes(String fileType) + { + operators.add(new SimpleMapper("CONSUMER", fileType+"Consumer")); + return this; + } + + public TemplateProcess create(String fileName) + { + +// TemplateProcess process = new TemplateProcess(entry.getKey()+name+".java", Paths.get("")); + return null; + } +} diff --git a/Primitive-Collections/src/main/java/speiger/src/builder/example/TestBuilder.java b/src/main/java/speiger/src/builder/example/TestBuilder.java similarity index 50% rename from Primitive-Collections/src/main/java/speiger/src/builder/example/TestBuilder.java rename to src/main/java/speiger/src/builder/example/TestBuilder.java index b63e982..a380ce7 100644 --- a/Primitive-Collections/src/main/java/speiger/src/builder/example/TestBuilder.java +++ b/src/main/java/speiger/src/builder/example/TestBuilder.java @@ -4,20 +4,23 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.Map.Entry; import java.util.function.Consumer; import java.util.function.UnaryOperator; +import speiger.src.builder.mappers.InjectMapper; import speiger.src.builder.mappers.SimpleMapper; import speiger.src.builder.processor.TemplateProcess; import speiger.src.builder.processor.TemplateProcessor; public class TestBuilder extends TemplateProcessor { - Map>> data; + public static final String[] KEY_TYPE = new String[]{"byte", "short", "int", "long", "float", "double", "T"}; + public static final String[] CLASS_TYPE = new String[]{"Byte", "Short", "Integer", "Long", "Float", "Double", "Object"}; + public static final String[] FILE_TYPE = new String[]{"Byte", "Short", "Int", "Long", "Float", "Double", "Object"}; + + List varibles = new ArrayList(); public TestBuilder() { @@ -31,25 +34,33 @@ public class TestBuilder extends TemplateProcessor } @Override - protected void init() + protected boolean relativePackages() { - data = new LinkedHashMap<>(); - data.put("Byte", createForType("byte", "Byte", "Byte")); - data.put("Short", createForType("short", "Short", "Short")); - data.put("Int", createForType("int", "Integer", "Int")); - data.put("Long", createForType("long", "Long", "Long")); - data.put("Float", createForType("float", "Float", "Float")); - data.put("Double", createForType("double", "Double", "Double")); - data.put("Object", createForType("Object", "T", "Object")); + return true; } - private List> createForType(String lowercase, String upperCase, String classType) + @Override + protected void init() { + varibles.clear(); + for(int i = 0,m=KEY_TYPE.length;i> createForType(String lowercase, String upperCase, String classType, String consumer) + { + Files List> list = new ArrayList<>(); - list.add(new SimpleMapper("LIST", classType+"List")); + list.add(new SimpleMapper("JAVA_CONSUMER", "java.util.function."+consumer)); + list.add(new SimpleMapper("CONSUMER", classType+"Consumer")); list.add(new SimpleMapper("CLASS_TYPE", upperCase)); list.add(new SimpleMapper("KEY_TYPE", lowercase)); - list.add(new SimpleMapper("KEY_GENERIC_TYPE", "")); + list.add(new InjectMapper("OBJ_TO_KEY(\\([^)]+\\)|\\S)", "%s."+lowercase+"Value()").removeBraces()); return list; } @@ -60,27 +71,31 @@ public class TestBuilder extends TemplateProcessor { TemplateProcess process = new TemplateProcess(entry.getKey()+name+".java", Paths.get("")); process.addMappers(entry.getValue()); - if(entry.getKey().equals("Object")) - { - process.addFlags("OBJECT"); - } acceptor.accept(process); } } public static void main(String...args) { - try + Path path = Paths.get("").toAbsolutePath(); + System.out.println(path.toString()); + for(int i = 0,m=path.getNameCount();i parsePool = new HashSet<>(); List> mappers = new ArrayList<>(); - public TemplateProcess(String fileName, Path path) + public TemplateProcess(String fileName) { this.fileName = fileName; - this.path = path; } public void addFlags(String...flags) diff --git a/Primitive-Collections/src/main/java/speiger/src/builder/processor/TemplateProcessor.java b/src/main/java/speiger/src/builder/processor/TemplateProcessor.java similarity index 89% rename from Primitive-Collections/src/main/java/speiger/src/builder/processor/TemplateProcessor.java rename to src/main/java/speiger/src/builder/processor/TemplateProcessor.java index 5394f29..035695b 100644 --- a/Primitive-Collections/src/main/java/speiger/src/builder/processor/TemplateProcessor.java +++ b/src/main/java/speiger/src/builder/processor/TemplateProcessor.java @@ -19,13 +19,14 @@ public abstract class TemplateProcessor Path sourceFolder; Path outputFolder; Path dataFolder; + boolean init = false; + public TemplateProcessor(Path sourceFolder, Path outputFolder, Path dataFolder) { this.sourceFolder = sourceFolder; this.outputFolder = outputFolder; this.dataFolder = dataFolder; - init(); } protected abstract void init(); @@ -34,8 +35,15 @@ public abstract class TemplateProcessor public abstract void createProcesses(String fileName, Consumer process); + protected abstract boolean relativePackages(); + public boolean process(boolean force) throws IOException, InterruptedException { + if(!init) + { + init = true; + init(); + } Map existing = FileUtils.loadMappings(dataFolder); List pathsLeft = Files.walk(sourceFolder).filter(Files::isRegularFile).filter(T -> isFileValid(T.getFileName())).filter(T -> force || FileUtils.isValid(T, existing)).collect(Collectors.toList()); if(pathsLeft.isEmpty() && !force) @@ -43,6 +51,7 @@ public abstract class TemplateProcessor System.out.println("Nothing has changed"); return false; } + final boolean relative = relativePackages(); ThreadPoolExecutor service = (ThreadPoolExecutor)Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); service.setKeepAliveTime(10, TimeUnit.MILLISECONDS); service.allowCoreThreadTimeOut(true); @@ -53,7 +62,7 @@ public abstract class TemplateProcessor try { Template template = Template.parse(path); - createProcesses(FileUtils.getFileName(path), T -> service.execute(new BuildTask(outputFolder, template, T))); + createProcesses(FileUtils.getFileName(path), T -> service.execute(new BuildTask(relative ? outputFolder.resolve(sourceFolder.relativize(path).getParent()) : outputFolder, template, T))); } catch(Exception e) { diff --git a/Primitive-Collections/src/main/java/speiger/src/collections/.gitignore b/src/main/java/speiger/src/collections/.gitignore similarity index 100% rename from Primitive-Collections/src/main/java/speiger/src/collections/.gitignore rename to src/main/java/speiger/src/collections/.gitignore diff --git a/src/main/resources/speiger/assets/collections/cache.bin b/src/main/resources/speiger/assets/collections/cache.bin new file mode 100644 index 0000000..8bf93c7 --- /dev/null +++ b/src/main/resources/speiger/assets/collections/cache.bin @@ -0,0 +1,2 @@ +List=8346cdbb0624aa07f1c54d00f765cbd5 +Consumer=e0112061d850a9ea6049cfe6571e2750 diff --git a/src/main/resources/speiger/assets/collections/templates/functions/Consumer.template b/src/main/resources/speiger/assets/collections/templates/functions/Consumer.template new file mode 100644 index 0000000..4b8cbe9 --- /dev/null +++ b/src/main/resources/speiger/assets/collections/templates/functions/Consumer.template @@ -0,0 +1,22 @@ +package speiger.src.collections.example.functions; + +import java.util.Objects; +import java.util.function.Consumer; + +public interface CONSUMER extends Consumer, JAVA_CONSUMER +{ + void accept(KEY_TYPE t); + + default void accept(CLASS_TYPE t) { accept(OBJ_TO_KEY(t)); } + + @Override + default CONSUMER andThen(Consumer after) { + Objects.requireNonNull(after); + return T -> {accept(T); after.accept(T);}; + } + + default CONSUMER andThen(CONSUMER after) { + Objects.requireNonNull(after); + return T -> {accept(T); after.accept(T);}; + } +} \ No newline at end of file