Skip to content

Commit

Permalink
Removed the double foldering and started some seriouse work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Speiger committed Nov 11, 2020
1 parent 51f447b commit 7903343
Show file tree
Hide file tree
Showing 30 changed files with 131 additions and 76 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions Primitive-Collections/.gitignore

This file was deleted.

This file was deleted.

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -48,27 +45,6 @@ public String build(Set<String> parsePool, List<UnaryOperator<String>> mappers)
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<String> 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<ConditionedSegment> segments = new ArrayList<ConditionedSegment>();
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/speiger/src/builder/example/GlobalVariables.java
Original file line number Diff line number Diff line change
@@ -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<UnaryOperator<String>> operators = new ArrayList<>();
Set<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
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<String, List<UnaryOperator<String>>> 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<GlobalVariables> varibles = new ArrayList<GlobalVariables>();

public TestBuilder()
{
Expand All @@ -30,26 +33,34 @@ protected boolean isFileValid(Path fileName)
return true;
}

@Override
protected boolean relativePackages()
{
return true;
}

@Override
protected void init()
{
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"));
varibles.clear();
for(int i = 0,m=KEY_TYPE.length;i<m;i++)
{
GlobalVariables type = new GlobalVariables(FILE_TYPE[i]);
type.createInitials(CLASS_TYPE[i], KEY_TYPE[i]);
type.createClassTypes(FILE_TYPE[i]);
varibles.add(type);
}
}

private List<UnaryOperator<String>> createForType(String lowercase, String upperCase, String classType)
private List<UnaryOperator<String>> createForType(String lowercase, String upperCase, String classType, String consumer)
{
Files
List<UnaryOperator<String>> 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", "<T>"));
list.add(new InjectMapper("OBJ_TO_KEY(\\([^)]+\\)|\\S)", "%s."+lowercase+"Value()").removeBraces());
return list;
}

Expand All @@ -60,27 +71,31 @@ public void createProcesses(String name, Consumer<TemplateProcess> acceptor)
{
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
{
new TestBuilder().process(true);
}
catch(InterruptedException e)
Path path = Paths.get("").toAbsolutePath();
System.out.println(path.toString());
for(int i = 0,m=path.getNameCount();i<m;i++)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
System.out.println(path.getName(i).toString());
}
// try
// {
// new TestBuilder().process(true);
// }
// catch(InterruptedException e)
// {
// e.printStackTrace();
// }
// catch(IOException e)
// {
// e.printStackTrace();
// }
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class BuildTask implements Runnable

public BuildTask(Path basePath, Template template, TemplateProcess process)
{
super();
this.basePath = basePath;
this.template = template;
this.process = process;
Expand All @@ -26,6 +25,13 @@ public void run()
{
String s = template.build(process.parsePool, process.mappers);
Path path = basePath.resolve(process.path).resolve(process.fileName);
try
{
Files.createDirectories(path.getParent());
}
catch(Exception e)
{
}
try(BufferedWriter writer = Files.newBufferedWriter(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE, StandardOpenOption.SYNC))
{
writer.write(s);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package speiger.src.builder.processor;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -11,15 +10,14 @@

public class TemplateProcess
{
Path path;
UnaryOperator pathBuilder;
String fileName;
Set<String> parsePool = new HashSet<>();
List<UnaryOperator<String>> mappers = new ArrayList<>();

public TemplateProcess(String fileName, Path path)
public TemplateProcess(String fileName)
{
this.fileName = fileName;
this.path = path;
}

public void addFlags(String...flags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -34,15 +35,23 @@ public TemplateProcessor(Path sourceFolder, Path outputFolder, Path dataFolder)

public abstract void createProcesses(String fileName, Consumer<TemplateProcess> process);

protected abstract boolean relativePackages();

public boolean process(boolean force) throws IOException, InterruptedException
{
if(!init)
{
init = true;
init();
}
Map<String, String> existing = FileUtils.loadMappings(dataFolder);
List<Path> 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)
{
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);
Expand All @@ -53,7 +62,7 @@ public boolean process(boolean force) throws IOException, InterruptedException
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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/speiger/assets/collections/cache.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
List=8346cdbb0624aa07f1c54d00f765cbd5
Consumer=e0112061d850a9ea6049cfe6571e2750
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package speiger.src.collections.example.functions;

import java.util.Objects;
import java.util.function.Consumer;

public interface CONSUMER extends Consumer<CLASS_TYPE>, JAVA_CONSUMER
{
void accept(KEY_TYPE t);

default void accept(CLASS_TYPE t) { accept(OBJ_TO_KEY(t)); }

@Override
default CONSUMER andThen(Consumer<? super CLASS_TYPE> 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);};
}
}

0 comments on commit 7903343

Please sign in to comment.