Compare commits

...

2 Commits

Author SHA1 Message Date
Speiger cdcf5dc087 Fixing a few things and testing more. Not useable atm. 2023-07-04 17:07:02 +02:00
Speiger 54aae530a1 Start of a Advanced Dependency System.
The idea behind this system is that you can select systems a lot easier.
So if a custom system isn't required it can be disabled and all the
subsystems that require it either get disabled too.
it also allows you to set systems as: Only if they are required. Meaning
if only a specific system is required its dependencies can still load.
2023-07-02 01:22:04 +02:00
19 changed files with 834 additions and 2852 deletions

File diff suppressed because it is too large Load Diff

View File

@ -128,10 +128,12 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
for(int i = 0,m=modules.size();i<m;i++) { for(int i = 0,m=modules.size();i<m;i++) {
modules.get(i).setManager(manager); modules.get(i).setManager(manager);
} }
manager.resolve();
for(int i = 0,m=modules.size();i<m;i++) { for(int i = 0,m=modules.size();i<m;i++) {
biPackages.forEach(modules.get(i)::init); biPackages.forEach(modules.get(i)::init);
} }
modules.forEach(BaseModule::cleanup); modules.forEach(BaseModule::cleanup);
manager.printModuleSettings(Arrays.asList(MapModule.INSTANCE));
} }
private void finishPackages() { private void finishPackages() {
@ -212,7 +214,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
boolean force = flags.contains("force"); boolean force = flags.contains("force");
boolean tests = flags.contains("tests"); boolean tests = flags.contains("tests");
boolean forceTests = flags.contains("force-tests"); boolean forceTests = flags.contains("force-tests");
boolean load = flags.contains("load"); boolean load = !flags.contains("load");
boolean save = flags.contains("save"); boolean save = flags.contains("save");
int flag = (load ? LOAD : 0) | (save ? SAVE : 0); int flag = (load ? LOAD : 0) | (save ? SAVE : 0);
new PrimitiveCollectionsBuilder(silent).setFlags(flag).process(force); new PrimitiveCollectionsBuilder(silent).setFlags(flag).process(force);

View File

@ -1,8 +1,12 @@
package speiger.src.builder; package speiger.src.builder;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@ -11,6 +15,7 @@ import com.google.gson.JsonParser;
import com.google.gson.internal.Streams; import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonWriter; import com.google.gson.stream.JsonWriter;
import speiger.src.builder.dependency.IDependency;
import speiger.src.builder.modules.BaseModule; import speiger.src.builder.modules.BaseModule;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
@ -19,36 +24,43 @@ public class SettingsManager
boolean loaded; boolean loaded;
JsonObject data = new JsonObject(); JsonObject data = new JsonObject();
Set<String> moduleNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); Set<String> moduleNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
Set<IDependency> allDependencies = new LinkedHashSet<>();
public boolean isModuleEnabled(BaseModule base, ClassType keyType, ClassType valueType) { public void resolve() {
if(!loaded) return true; boolean valid = true;
if(!isEnabled(data, base.getModuleName())) return false; for(int i = 0;i<10000 && valid;i++) {
JsonObject result = getObject(data, keyType.getClassPath(), false); boolean result = false;
if(!isEnabled(result, "Enabled")) return false; for(IDependency entry : allDependencies) {
if(base.isBiModule()) { result |= entry.resolveDependencies();
result = getObject(result, valueType.getClassPath(), false);
if(!isEnabled(result, "Enabled")) return false;
} }
result = getObject(result, base.getModuleName(), false); valid = result;
return (result.size() <= 0 || isEnabled(result, "Enabled")) && base.areDependenciesLoaded();
} }
if(valid) throw new RuntimeException("Couldn't resolve dependencies!");
public boolean isModuleEnabled(BaseModule base, ClassType keyType, ClassType valueType, String entry)
{
if(!loaded) return true;
if(!isEnabled(data, base.getModuleName())) return false;
JsonObject result = getObject(data, keyType.getClassPath(), false);
if(!isEnabled(result, "Enabled")) return false;
if(base.isBiModule()) {
result = getObject(result, valueType.getClassPath(), false);
if(!isEnabled(result, "Enabled")) return false;
}
result = getObject(result, base.getModuleName(), false);
return (result.size() <= 0 || (isEnabled(result, "Enabled") && isEnabled(result, entry))) && base.areDependenciesLoaded();
} }
public void addModule(BaseModule module) { public void addModule(BaseModule module) {
if(loaded) return; if(loaded) {
if(module.isBiModule()) {
for(ClassType keyType : ModulePackage.TYPE) {
for(ClassType valueType : ModulePackage.TYPE) {
if(!module.isModuleValid(keyType, valueType)) continue;
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
dependency.load(data, keyType, valueType);
allDependencies.add(dependency);
}
}
}
return;
}
for(ClassType keyType : ModulePackage.TYPE) {
if(!module.isModuleValid(keyType, keyType)) continue;
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
dependency.load(data, keyType, keyType);
allDependencies.add(dependency);
}
}
return;
}
String moduleName = module.getModuleName(); String moduleName = module.getModuleName();
moduleNames.add(moduleName); moduleNames.add(moduleName);
data.addProperty(moduleName, true); data.addProperty(moduleName, true);
@ -57,9 +69,10 @@ public class SettingsManager
for(ClassType valueType : ModulePackage.TYPE) { for(ClassType valueType : ModulePackage.TYPE) {
if(!module.isModuleValid(keyType, valueType)) continue; if(!module.isModuleValid(keyType, valueType)) continue;
JsonObject obj = new JsonObject(); JsonObject obj = new JsonObject();
obj.addProperty("Enabled", true); for(IDependency dependency : module.getDependencies(keyType, valueType)) {
for(String key : module.getModuleKeys(keyType, valueType)) { String key = dependency.getName();
obj.addProperty(key, true); if(key != null) obj.addProperty(key, true);
dependency.setLoaded();
} }
addModule(keyType, valueType, true, moduleName, obj); addModule(keyType, valueType, true, moduleName, obj);
} }
@ -69,14 +82,55 @@ public class SettingsManager
for(ClassType keyType : ModulePackage.TYPE) { for(ClassType keyType : ModulePackage.TYPE) {
if(!module.isModuleValid(keyType, keyType)) continue; if(!module.isModuleValid(keyType, keyType)) continue;
JsonObject obj = new JsonObject(); JsonObject obj = new JsonObject();
obj.addProperty("Enabled", true); for(IDependency dependency : module.getDependencies(keyType, keyType)) {
for(String key : module.getModuleKeys(keyType, keyType)) { String key = dependency.getName();
obj.addProperty(key, true); if(key != null) obj.addProperty(key, true);
dependency.setLoaded();
} }
addModule(keyType, keyType, false, moduleName, obj); addModule(keyType, keyType, false, moduleName, obj);
} }
} }
public void printModuleSettings(List<BaseModule> modules) {
JsonObject data = new JsonObject();
for(BaseModule module : modules) {
String moduleName = module.getModuleName();
if(module.isBiModule()) {
for(ClassType keyType : ModulePackage.TYPE) {
for(ClassType valueType : ModulePackage.TYPE) {
if(!module.isModuleValid(keyType, valueType)) continue;
JsonObject obj = new JsonObject();
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
String key = dependency.getName();
if(key != null) obj.addProperty(key, dependency.getState(keyType, valueType).getJsonResult());
}
addModule(data, keyType, valueType, true, moduleName, obj);
}
}
continue;
}
for(ClassType keyType : ModulePackage.TYPE) {
if(!module.isModuleValid(keyType, keyType)) continue;
JsonObject obj = new JsonObject();
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
String key = dependency.getName();
if(key != null) obj.addProperty(key, dependency.getState(keyType, keyType).getJsonResult());
}
addModule(data, keyType, keyType, false, moduleName, obj);
}
}
try {
System.out.println();
JsonWriter writer = new JsonWriter(new OutputStreamWriter(System.out));
writer.setIndent("\t");
Streams.write(data, writer);
writer.flush();
System.out.println();
} catch (IOException e) {
e.printStackTrace();
}
}
public void load() { public void load() {
try(BufferedReader reader = Files.newBufferedReader(Paths.get("ModulSettings.json"))) { try(BufferedReader reader = Files.newBufferedReader(Paths.get("ModulSettings.json"))) {
data = JsonParser.parseReader(reader).getAsJsonObject(); data = JsonParser.parseReader(reader).getAsJsonObject();
@ -100,6 +154,14 @@ public class SettingsManager
catch(Exception e) { e.printStackTrace(); } catch(Exception e) { e.printStackTrace(); }
} }
private void addModule(JsonObject data, ClassType keyType, ClassType valueType, boolean bi, String moduleName, JsonObject obj) {
JsonObject result = getObject(data, keyType.getClassPath(), true);
if(bi) {
result = getObject(result, valueType.getClassPath(), true);
}
result.add(moduleName, obj);
}
private void addModule(ClassType keyType, ClassType valueType, boolean bi, String moduleName, JsonObject obj) { private void addModule(ClassType keyType, ClassType valueType, boolean bi, String moduleName, JsonObject obj) {
JsonObject result = getObject(data, keyType.getClassPath(), true); JsonObject result = getObject(data, keyType.getClassPath(), true);
if(bi) { if(bi) {
@ -117,9 +179,4 @@ public class SettingsManager
} }
return obj; return obj;
} }
private boolean isEnabled(JsonObject obj, String key) {
if(obj.has(key)) return obj.getAsJsonPrimitive(key).getAsBoolean();
return true;
}
} }

View File

@ -0,0 +1,49 @@
package speiger.src.builder.dependency;
import java.util.ArrayList;
import java.util.List;
import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
public abstract class DependencyBase implements IDependency {
protected List<IDependency> children = new ArrayList<>();
protected List<IDependency> parents = new ArrayList<>();
public <T extends DependencyBase> T addChild(T child) {
children.add(child);
child.addParent(this);
return child;
}
public <T extends DependencyBase> T addParent(DependencyBase parent) {
parents.add(parent);
return (T) this;
}
public List<IDependency> getParents() {
return parents;
}
public List<IDependency> getChildren() {
return children;
}
protected LoadingState getChildState(ClassType keyType, ClassType valueType) {
LoadingState state = LoadingState.UNDEFINED;
for(IDependency child : children) {
if(state == LoadingState.LOADED) return LoadingState.LOADED;
state = state.mergeDown(child.getState(keyType, valueType));
}
return state;
}
protected LoadingState getParentState(ClassType keyType, ClassType valueType) {
LoadingState state = LoadingState.UNDEFINED;
for(IDependency parent : parents) {
if(state == LoadingState.UNLOADED) return LoadingState.UNLOADED;
state = state.mergeUp(parent.getState(keyType, valueType));
}
return state;
}
}

View File

@ -0,0 +1,131 @@
package speiger.src.builder.dependency;
import java.util.Arrays;
import com.google.gson.JsonObject;
import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
public abstract class DependencyFunction extends DependencyBase {
protected DependencyModule owner;
public DependencyFunction(DependencyModule owner) {
this.owner = owner;
}
@Override
public boolean isEnabled() {
return getState(owner.owner.keyType(), owner.owner.valueType()) == LoadingState.LOADED;
}
public abstract DependencyFunction createSubFunction(String function);
public static class SingleFunction extends DependencyFunction {
LoadingState[] state = new LoadingState[ClassType.values().length];
String functionName;
public SingleFunction(DependencyModule owner, String functionName) {
super(owner);
this.functionName = functionName;
Arrays.fill(state, LoadingState.UNDEFINED);
}
@Override
public DependencyFunction createSubFunction(String function) {
return addChild(new SingleFunction(owner, function));
}
@Override
public void load(JsonObject obj, ClassType keyType, ClassType valueType) {
state[keyType.ordinal()] = owner.isFunctionLoaded(obj, keyType, valueType, functionName);
}
@Override
public LoadingState getState(ClassType keyType, ClassType valueType) {
return state[keyType.ordinal()];
}
@Override
public boolean resolveDependencies() {
boolean returnType = false;
for(ClassType type : ClassType.values()) {
LoadingState state = this.state[type.ordinal()];
if(state == LoadingState.UNLOADED) continue;
state = state.merge(getChildState(type, type)).merge(getParentState(type, type));
if(state != this.state[type.ordinal()]) {
this.state[type.ordinal()] = state;
returnType = true;
}
}
return returnType;
}
@Override
public String getName() {
return functionName;
}
@Override
public void setLoaded() {
Arrays.fill(state, LoadingState.LOADED);
}
}
public static class BiTypeFunction extends DependencyFunction {
LoadingState[][] state = new LoadingState[ClassType.values().length][ClassType.values().length];
String functionName;
BiTypeFunction(DependencyModule owner, String functionName) {
super(owner);
this.functionName = functionName;
for(int i = 0;i<state.length;i++) {
Arrays.fill(state[i], LoadingState.UNDEFINED);
}
}
@Override
public DependencyFunction createSubFunction(String function) {
return new BiTypeFunction(owner, function);
}
@Override
public void load(JsonObject obj, ClassType keyType, ClassType valueType) {
state[keyType.ordinal()][valueType.ordinal()] = owner.isFunctionLoaded(obj, keyType, valueType, functionName);
}
@Override
public LoadingState getState(ClassType keyType, ClassType valueType) {
return state[keyType.ordinal()][valueType.ordinal()];
}
@Override
public boolean resolveDependencies() {
boolean returnType = false;
for(ClassType keyType : ClassType.values()) {
for(ClassType valueType : ClassType.values()) {
LoadingState state = this.state[keyType.ordinal()][valueType.ordinal()];
if(state == LoadingState.UNLOADED) continue;
state = state.merge(getChildState(keyType, valueType)).merge(getParentState(keyType, valueType));
if(state != this.state[keyType.ordinal()][valueType.ordinal()]) {
this.state[keyType.ordinal()][valueType.ordinal()] = state;
returnType = true;
}
}
}
return returnType;
}
@Override
public String getName() {
return functionName;
}
@Override
public void setLoaded() {
for(int i = 0;i<state.length;i++) {
Arrays.fill(state[i], LoadingState.LOADED);
}
}
}
}

View File

@ -0,0 +1,170 @@
package speiger.src.builder.dependency;
import java.util.Arrays;
import com.google.gson.JsonObject;
import speiger.src.builder.ClassType;
import speiger.src.builder.dependency.DependencyFunction.BiTypeFunction;
import speiger.src.builder.dependency.DependencyFunction.SingleFunction;
import speiger.src.builder.modules.BaseModule;
@SuppressWarnings("javadoc")
public abstract class DependencyModule extends DependencyBase {
protected BaseModule owner;
public DependencyModule(BaseModule owner) {
this.owner = owner;
}
public LoadingState isFunctionLoaded(JsonObject obj, ClassType keyType, ClassType valueType, String function) { return isModuleEnabled(obj, keyType, valueType, function); }
public abstract DependencyFunction createFunction(String functionName);
@Override
public boolean isEnabled() {
return getState(owner.keyType(), owner.valueType()) == LoadingState.LOADED;
}
public static class SingleTypeModule extends DependencyModule {
LoadingState[] state = new LoadingState[ClassType.values().length];
public SingleTypeModule(BaseModule owner) {
super(owner);
Arrays.fill(state, LoadingState.UNDEFINED);
}
@Override
public DependencyFunction createFunction(String functionName) {
return addChild(new SingleFunction(this, functionName));
}
@Override
public void load(JsonObject obj, ClassType keyType, ClassType valueType) {
state[keyType.ordinal()] = isModuleEnabled(obj, keyType, valueType);
}
@Override
public LoadingState getState(ClassType keyType, ClassType valueType) {
return state[keyType.ordinal()];
}
@Override
public boolean resolveDependencies() {
boolean returnType = false;
for(ClassType type : ClassType.values()) {
LoadingState state = this.state[type.ordinal()];
if(state == LoadingState.UNLOADED) continue;
state = state.merge(getChildState(type, type)).merge(getParentState(type, type));
if(state != this.state[type.ordinal()]) {
this.state[type.ordinal()] = state;
returnType = true;
}
}
return returnType;
}
@Override
public String getName() {
return "Enabled";
}
@Override
public void setLoaded() {
Arrays.fill(state, LoadingState.LOADED);
}
}
public static class BiTypeModule extends DependencyModule {
LoadingState[][] state = new LoadingState[ClassType.values().length][ClassType.values().length];
public BiTypeModule(BaseModule owner) {
super(owner);
for(int i = 0;i<state.length;i++) {
Arrays.fill(state[i], LoadingState.UNDEFINED);
}
}
@Override
public DependencyFunction createFunction(String functionName) {
return addChild(new BiTypeFunction(this, functionName));
}
@Override
public void load(JsonObject obj, ClassType keyType, ClassType valueType) {
state[keyType.ordinal()][valueType.ordinal()] = isModuleEnabled(obj, keyType, valueType);
}
@Override
public LoadingState getState(ClassType keyType, ClassType valueType) {
return state[keyType.ordinal()][valueType.ordinal()];
}
@Override
public boolean resolveDependencies() {
boolean returnType = false;
for(ClassType keyType : ClassType.values()) {
for(ClassType valueType : ClassType.values()) {
LoadingState state = this.state[keyType.ordinal()][valueType.ordinal()];
if(state == LoadingState.UNLOADED) continue;
state = state.merge(getChildState(keyType, valueType)).merge(getParentState(keyType, valueType));
if(state != this.state[keyType.ordinal()][valueType.ordinal()]) {
this.state[keyType.ordinal()][valueType.ordinal()] = state;
returnType = true;
}
}
}
return returnType;
}
@Override
public String getName() {
return "Enabled";
}
@Override
public void setLoaded() {
for(int i = 0;i<state.length;i++) {
Arrays.fill(state[i], LoadingState.LOADED);
}
}
}
protected LoadingState isModuleEnabled(JsonObject data, ClassType keyType, ClassType valueType) {
LoadingState state = isEnabled(data, owner.getModuleName());
JsonObject result = getObject(data, keyType.getClassPath(), false);
state = state.replaceIfDefined(isEnabled(result, "Enabled"));
if(owner.isBiModule()) {
result = getObject(result, valueType.getClassPath(), false);
state = state.replaceIfDefined(isEnabled(result, "Enabled"));
}
return state = state.replaceIfDefined(isEnabled(getObject(result, owner.getModuleName(), false), "Enabled"));
}
protected LoadingState isModuleEnabled(JsonObject data, ClassType keyType, ClassType valueType, String entry) {
LoadingState state = isEnabled(data, owner.getModuleName());
JsonObject result = getObject(data, keyType.getClassPath(), false);
state = state.replaceIfDefined(isEnabled(result, "Enabled"));
if(owner.isBiModule()) {
result = getObject(result, valueType.getClassPath(), false);
state = state.replaceIfDefined(isEnabled(result, "Enabled"));
}
result = getObject(result, owner.getModuleName(), false);
return state.replaceIfDefined(isEnabled(result, "Enabled")).replaceIfDefined(isEnabled(result, entry));
}
private JsonObject getObject(JsonObject data, String name, boolean create) {
JsonObject obj = data.getAsJsonObject(name);
if(obj == null) {
obj = new JsonObject();
data.add(name, obj);
if(create) obj.addProperty("Enabled", true);
}
return obj;
}
private LoadingState isEnabled(JsonObject obj, String key) {
if (obj.has(key)) return LoadingState.of(obj.getAsJsonPrimitive(key).getAsBoolean());
return LoadingState.UNDEFINED;
}
}

View File

@ -0,0 +1,42 @@
package speiger.src.builder.dependency;
import com.google.gson.JsonObject;
import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
public class DependencyType extends DependencyBase {
DependencyBase owner;
ClassType myType;
public DependencyType(DependencyBase owner, ClassType myType) {
this.owner = owner;
this.myType = myType;
}
@Override
public void load(JsonObject obj, ClassType keyType, ClassType valueType) {}
@Override
public LoadingState getState(ClassType keyType, ClassType valueType) {
if(keyType != myType || valueType != myType) return LoadingState.UNDEFINED;
return owner.getState(keyType, valueType);
}
@Override
public boolean resolveDependencies() { return false; }
@Override
public boolean isEnabled() {
return owner.getState(myType, myType) == LoadingState.LOADED;
}
@Override
public String getName() {
return null;
}
@Override
public void setLoaded() {
}
}

View File

@ -0,0 +1,41 @@
package speiger.src.builder.dependency;
import com.google.gson.JsonObject;
import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
public class DependencyValue extends DependencyBase {
DependencyBase owner;
public DependencyValue(DependencyBase owner) {
this.owner = owner;
}
@Override
public void load(JsonObject obj, ClassType keyType, ClassType valueType) {}
@Override
public LoadingState getState(ClassType keyType, ClassType valueType) {
return owner.getState(valueType, keyType);
}
@Override
public boolean resolveDependencies() {
return false;
}
@Override
public boolean isEnabled() {
return owner.isEnabled();
}
@Override
public String getName() {
return null;
}
@Override
public void setLoaded() {
}
}

View File

@ -0,0 +1,51 @@
package speiger.src.builder.dependency;
import com.google.gson.JsonObject;
import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
public interface IDependency {
public void load(JsonObject obj, ClassType keyType, ClassType valueType);
public LoadingState getState(ClassType keyType, ClassType valueType);
public boolean resolveDependencies();
public boolean isEnabled();
public void setLoaded();
public String getName();
public static enum LoadingState {
UNDEFINED,
LOADED,
UNLOADED;
public static LoadingState of(boolean value) {
return value ? LOADED : UNLOADED;
}
public LoadingState merge(LoadingState merge) {
return ordinal() > merge.ordinal() ? this : merge;
}
public LoadingState replaceIfDefined(LoadingState state) {
return state == UNDEFINED ? this : state;
}
public LoadingState mergeDown(LoadingState merge) {
if(merge == UNLOADED || ordinal() > merge.ordinal()) {
return this;
}
return merge;
}
public LoadingState mergeUp(LoadingState merge) {
if(merge == LOADED || ordinal() > merge.ordinal()) {
return this;
}
return merge;
}
public boolean getJsonResult() {
return this == LOADED;
}
}
}

View File

@ -1,9 +1,19 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import java.util.Arrays;
import java.util.List;
import speiger.src.builder.ClassType;
import speiger.src.builder.dependency.DependencyModule;
import speiger.src.builder.dependency.DependencyModule.SingleTypeModule;
import speiger.src.builder.dependency.IDependency;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class AsyncModule extends BaseModule public class AsyncModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new AsyncModule(); public static final BaseModule INSTANCE = new AsyncModule();
public static final DependencyModule MODULE = CollectionModule.MODULE.addChild(new SingleTypeModule(INSTANCE));
@Override @Override
public String getModuleName() { return "Async"; } public String getModuleName() { return "Async"; }
@ -16,16 +26,16 @@ public class AsyncModule extends BaseModule
@Override @Override
protected void loadFunctions() {} protected void loadFunctions() {}
@Override @Override
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); } public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE); }
@Override @Override
protected void loadBlockades() { protected void loadBlockades() {
if(!isModuleEnabled()) { if(MODULE.isEnabled()) {
addBlockedFiles("AsyncBuilder", "Task"); addBlockedFiles("AsyncBuilder", "Task");
} }
} }
@Override @Override
protected void loadFlags() { protected void loadFlags() {
if(isModuleEnabled()) { if(MODULE.isEnabled()) {
addKeyFlag("ASYNC_MODULE"); addKeyFlag("ASYNC_MODULE");
} }
} }

View File

@ -1,13 +1,15 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import speiger.src.builder.ClassType; import speiger.src.builder.ClassType;
import speiger.src.builder.ModulePackage; import speiger.src.builder.ModulePackage;
import speiger.src.builder.RequiredType; import speiger.src.builder.RequiredType;
import speiger.src.builder.SettingsManager; import speiger.src.builder.SettingsManager;
import speiger.src.builder.dependency.IDependency;
import speiger.src.builder.mappers.ArgumentMapper; import speiger.src.builder.mappers.ArgumentMapper;
import speiger.src.builder.mappers.InjectMapper; import speiger.src.builder.mappers.InjectMapper;
import speiger.src.builder.mappers.LineMapper; import speiger.src.builder.mappers.LineMapper;
@ -56,32 +58,12 @@ public abstract class BaseModule
public abstract String getModuleName(); public abstract String getModuleName();
public boolean isBiModule() { return false; } public boolean isBiModule() { return false; }
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return Collections.emptySet(); } public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Collections.emptyList(); }
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return true; } public boolean isModuleValid(ClassType keyType, ClassType valueType) { return true; }
public ClassType keyType() { return keyType; } public ClassType keyType() { return keyType; }
public ClassType valueType() { return valueType; } public ClassType valueType() { return valueType; }
protected boolean isModuleEnabled() {
return manager == null || manager.isModuleEnabled(this, keyType, valueType);
}
protected boolean isModuleEnabled(String name) {
return manager == null || manager.isModuleEnabled(this, keyType, valueType, name);
}
protected boolean isDependencyLoaded(BaseModule module) {
return isDependencyLoaded(module, true);
}
protected boolean isDependencyLoaded(BaseModule module, boolean key) {
return manager == null || (module.isBiModule() ? manager.isModuleEnabled(module, keyType, valueType) : (key ? manager.isModuleEnabled(module, keyType, keyType) : manager.isModuleEnabled(module, valueType, valueType)));
}
public boolean areDependenciesLoaded() {
return true;
}
protected void addFlag(String name) { protected void addFlag(String name) {
entry.addFlag(name); entry.addFlag(name);
} }
@ -205,4 +187,9 @@ public abstract class BaseModule
entry.addMapper(mapper); entry.addMapper(mapper);
return mapper; return mapper;
} }
public static <T> T make(T input, Consumer<T> processor) {
processor.accept(input);
return input;
}
} }

View File

@ -1,52 +1,56 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.List;
import java.util.TreeSet;
import speiger.src.builder.ClassType; import speiger.src.builder.ClassType;
import speiger.src.builder.dependency.DependencyFunction;
import speiger.src.builder.dependency.DependencyModule;
import speiger.src.builder.dependency.DependencyModule.SingleTypeModule;
import speiger.src.builder.dependency.IDependency;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class CollectionModule extends BaseModule public class CollectionModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new CollectionModule(); public static final BaseModule INSTANCE = new CollectionModule();
public static final DependencyModule MODULE = JavaModule.MODULE.addChild(new SingleTypeModule(INSTANCE));
public static final DependencyFunction STREAMS = MODULE.createFunction("Streams");
public static final DependencyFunction SPLIT_ITERATORS = MODULE.createFunction("Splititerators");
public static final DependencyFunction IARRAY = MODULE.createFunction("IArray");
public static final DependencyFunction STRATEGY = MODULE.createFunction("Strategy");
@Override @Override
public String getModuleName() { return "Collection"; } public String getModuleName() { return "Collection"; }
@Override @Override
protected void loadVariables() {} protected void loadVariables() {}
@Override @Override
public boolean areDependenciesLoaded(){ return isDependencyLoaded(JavaModule.INSTANCE); } public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, STREAMS, SPLIT_ITERATORS, IARRAY, STRATEGY); }
@Override
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType)
{
return new TreeSet<>(Arrays.asList("Streams", "Splititerators", "IArray", "Strategy"));
}
@Override @Override
protected void loadFlags() { protected void loadFlags() {
if(isModuleEnabled()) addKeyFlag("COLLECTION_MODULE"); if(MODULE.isEnabled()) addKeyFlag("COLLECTION_MODULE");
if(isModuleEnabled("Streams")) addKeyFlag("STREAM_FEATURE"); if(STREAMS.isEnabled()) addKeyFlag("STREAM_FEATURE");
if(isModuleEnabled("Splititerators")) addKeyFlag("SPLIT_ITERATOR_FEATURE"); if(SPLIT_ITERATORS.isEnabled()) addKeyFlag("SPLIT_ITERATOR_FEATURE");
if(isModuleEnabled("IArray")) addKeyFlag("IARRAY_FEATURE"); if(IARRAY.isEnabled()) addKeyFlag("IARRAY_FEATURE");
} }
@Override @Override
protected void loadBlockades() { protected void loadBlockades() {
if(!isModuleEnabled()) { if(!MODULE.isEnabled()) {
addBlockedFiles("Iterable", "Iterables", "Iterator", "Iterators", "BidirectionalIterator", "ListIterator"); addBlockedFiles("Iterable", "Iterables", "Iterator", "Iterators", "BidirectionalIterator", "ListIterator");
addBlockedFiles("Arrays", "Collection", "AbstractCollection", "Collections", "Stack"); addBlockedFiles("Arrays", "Collection", "AbstractCollection", "Collections", "Stack");
} }
if(!isModuleEnabled("Splititerators")) addBlockedFiles("Splititerator", "Splititerators"); if(!SPLIT_ITERATORS.isEnabled()) addBlockedFiles("Splititerator", "Splititerators");
if(!isModuleEnabled("IArray")) addBlockedFiles("IArray"); if(!IARRAY.isEnabled()) addBlockedFiles("IArray");
if(!isModuleEnabled("Strategy")) addBlockedFiles("Strategy"); if(!STRATEGY.isEnabled()) addBlockedFiles("Strategy");
if(keyType.isObject()) { if(keyType.isObject())
{
addBlockedFiles("Stack"); addBlockedFiles("Stack");
addBlockedFiles("CollectionStreamTester"); addBlockedFiles("CollectionStreamTester");
} }
if(keyType == ClassType.BOOLEAN) { if(keyType == ClassType.BOOLEAN)
{
addBlockedFiles("CollectionRemoveIfTester", "CollectionStreamTester"); addBlockedFiles("CollectionRemoveIfTester", "CollectionStreamTester");
addBlockedFilter(T -> T.endsWith("Tester") && T.startsWith("Iterable")); addBlockedFilter(T -> T.endsWith("Tester") && T.startsWith("Iterable"));
} }

View File

@ -1,12 +1,19 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import java.util.Arrays;
import java.util.List;
import speiger.src.builder.ClassType; import speiger.src.builder.ClassType;
import speiger.src.builder.RequiredType; import speiger.src.builder.RequiredType;
import speiger.src.builder.dependency.DependencyModule;
import speiger.src.builder.dependency.IDependency;
import speiger.src.builder.dependency.DependencyModule.BiTypeModule;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class FunctionModule extends BaseModule public class FunctionModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new FunctionModule(); public static final BaseModule INSTANCE = new FunctionModule();
public static final DependencyModule MODULE = new BiTypeModule(INSTANCE);
@Override @Override
public String getModuleName() { return "Function"; } public String getModuleName() { return "Function"; }
@ -19,6 +26,11 @@ public class FunctionModule extends BaseModule
@Override @Override
protected void loadTestClasses() {} protected void loadTestClasses() {}
@Override
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
return Arrays.asList(MODULE);
}
@Override @Override
protected void loadBlockades() protected void loadBlockades()
{ {

View File

@ -1,11 +1,18 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import java.util.Arrays;
import java.util.List;
import speiger.src.builder.ClassType; import speiger.src.builder.ClassType;
import speiger.src.builder.dependency.DependencyBase;
import speiger.src.builder.dependency.IDependency;
import speiger.src.builder.dependency.DependencyModule.SingleTypeModule;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class JavaModule extends BaseModule public class JavaModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new JavaModule(); public static final BaseModule INSTANCE = new JavaModule();
public static final DependencyBase MODULE = new SingleTypeModule(INSTANCE);
@Override @Override
public String getModuleName() { return "Base"; } public String getModuleName() { return "Base"; }
@ -17,6 +24,11 @@ public class JavaModule extends BaseModule
loadBaseVariables(); loadBaseVariables();
} }
@Override
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
return Arrays.asList(MODULE);
}
@Override @Override
protected void loadFlags() protected void loadFlags()
{ {

View File

@ -1,55 +1,58 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.List;
import java.util.TreeSet;
import speiger.src.builder.ClassType; import speiger.src.builder.ClassType;
import speiger.src.builder.dependency.DependencyFunction;
import speiger.src.builder.dependency.DependencyModule;
import speiger.src.builder.dependency.DependencyModule.SingleTypeModule;
import speiger.src.builder.dependency.IDependency;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class ListModule extends BaseModule public class ListModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new ListModule(); public static final BaseModule INSTANCE = new ListModule();
public static final DependencyModule MODULE = CollectionModule.MODULE.addChild(new SingleTypeModule(INSTANCE));
public static final DependencyFunction IMPLEMENTATION = MODULE.createFunction("Implementations");
public static final DependencyFunction WRAPPERS = MODULE.createFunction("Wrappers");
public static final DependencyFunction ARRAY_LIST = IMPLEMENTATION.createSubFunction("ArrayList");
public static final DependencyFunction LINKED_LIST = IMPLEMENTATION.createSubFunction("LinkedList");
public static final DependencyFunction IMMUTABLE_LIST = IMPLEMENTATION.createSubFunction("ImmutableList");
public static final DependencyFunction COPY_ON_WRITE_LIST = IMPLEMENTATION.createSubFunction("CopyOnWriteList");
@Override @Override
public String getModuleName() { return "List"; } public String getModuleName() { return "List"; }
@Override @Override
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, IMPLEMENTATION, WRAPPERS, ARRAY_LIST, LINKED_LIST, IMMUTABLE_LIST, COPY_ON_WRITE_LIST); }
@Override
protected void loadVariables() {} protected void loadVariables() {}
@Override @Override
protected void loadFlags() { protected void loadFlags() {
if(isModuleEnabled()) addKeyFlag("LIST_MODULE"); if(MODULE.isEnabled()) addKeyFlag("LIST_MODULE");
if(isModuleEnabled("Wrappers")) addKeyFlag("LISTS_FEATURE"); if(WRAPPERS.isEnabled()) addKeyFlag("LISTS_FEATURE");
boolean implementations = isModuleEnabled("Implementations"); if(ARRAY_LIST.isEnabled()) addKeyFlag("ARRAY_LIST_FEATURE");
if(implementations && isModuleEnabled("ArrayList")) addKeyFlag("ARRAY_LIST_FEATURE"); if(LINKED_LIST.isEnabled()) addKeyFlag("LINKED_LIST_FEATURE");
if(implementations && isModuleEnabled("LinkedList")) addKeyFlag("LINKED_LIST_FEATURE"); if(IMMUTABLE_LIST.isEnabled()) addKeyFlag("IMMUTABLE_LIST_FEATURE");
if(implementations && isModuleEnabled("ImmutableList")) addKeyFlag("IMMUTABLE_LIST_FEATURE"); if(COPY_ON_WRITE_LIST.isEnabled()) addKeyFlag("COPY_ON_WRITE_LIST_FEATURE");
if(implementations && isModuleEnabled("CopyOnWriteList")) addKeyFlag("COPY_ON_WRITE_LIST_FEATURE");
} }
@Override @Override
protected void loadBlockades() protected void loadBlockades()
{ {
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Lists"); if(!WRAPPERS.isEnabled()) addBlockedFiles("Lists");
boolean implementations = !isModuleEnabled("Implementations"); if(!ARRAY_LIST.isEnabled()) addBlockedFiles("ArrayList");
if(implementations || !isModuleEnabled("ArrayList")) addBlockedFiles("ArrayList"); if(!LINKED_LIST.isEnabled()) addBlockedFiles("LinkedList");
if(implementations || !isModuleEnabled("LinkedList")) addBlockedFiles("LinkedList"); if(!IMMUTABLE_LIST.isEnabled()) addBlockedFiles("ImmutableList");
if(implementations || !isModuleEnabled("ImmutableList")) addBlockedFiles("ImmutableList"); if(!COPY_ON_WRITE_LIST.isEnabled()) addBlockedFiles("CopyOnWriteList");
if(implementations || !isModuleEnabled("CopyOnWriteList")) addBlockedFiles("CopyOnWriteList"); if(!MODULE.isEnabled()) addBlockedFiles("List", "AbstractList");
if(!isModuleEnabled()) addBlockedFiles("List", "AbstractList");
if(keyType.isObject()) addBlockedFiles("ListFillBufferTester"); if(keyType.isObject()) addBlockedFiles("ListFillBufferTester");
if(keyType == ClassType.BOOLEAN) addBlockedFiles("ListFillBufferTester", "ListReplaceAllTester"); if(keyType == ClassType.BOOLEAN) addBlockedFiles("ListFillBufferTester", "ListReplaceAllTester");
} }
@Override
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
return new TreeSet<>(Arrays.asList("Implementations", "Wrappers", "ArrayList", "LinkedList", "ImmutableList", "CopyOnWriteList"));
}
@Override
public boolean areDependenciesLoaded() {
return isDependencyLoaded(CollectionModule.INSTANCE);
}
@Override @Override
protected void loadRemappers() protected void loadRemappers()

View File

@ -1,15 +1,40 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.List;
import java.util.TreeSet;
import speiger.src.builder.ClassType; import speiger.src.builder.ClassType;
import speiger.src.builder.dependency.DependencyFunction;
import speiger.src.builder.dependency.DependencyModule;
import speiger.src.builder.dependency.DependencyModule.BiTypeModule;
import speiger.src.builder.dependency.DependencyType;
import speiger.src.builder.dependency.DependencyValue;
import speiger.src.builder.dependency.IDependency;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class MapModule extends BaseModule public class MapModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new MapModule(); public static final BaseModule INSTANCE = new MapModule();
public static final DependencyModule MODULE = make(new BiTypeModule(INSTANCE), T -> {
CollectionModule.MODULE.addChild(new DependencyValue(T));
CollectionModule.MODULE.addChild(new DependencyType(T, ClassType.OBJECT));
SetModule.MODULE.addChild(T);
});
public static final DependencyFunction WRAPPERS = MODULE.createFunction("Wrappers");
public static final DependencyFunction IMPLEMENTATION = MODULE.createFunction("Implementations");
public static final DependencyFunction ORDERED_MAP = MODULE.createFunction("OrderedMap");
public static final DependencyFunction SORTED_MAP = MODULE.createFunction("SortedMap");
public static final DependencyFunction ARRAY_MAP = ORDERED_MAP.addChild(IMPLEMENTATION.createSubFunction("ArrayMap"));
public static final DependencyFunction IMMUTABLE_MAP = IMPLEMENTATION.createSubFunction("ImmutableMap");
public static final DependencyFunction HASH_MAP = IMPLEMENTATION.createSubFunction("HashMap");
public static final DependencyFunction LINKED_MAP = HASH_MAP.addChild(ORDERED_MAP.addChild(IMPLEMENTATION.createSubFunction("LinkedHashMap")));
public static final DependencyFunction CUSTOM_MAP = IMPLEMENTATION.createSubFunction("CustomHashMap");
public static final DependencyFunction LINKED_CUSTOM_MAP = CUSTOM_MAP.addChild(ORDERED_MAP.addChild(IMPLEMENTATION.createSubFunction("LinkedCustomHashMap")));
public static final DependencyFunction ENUM_MAP = IMPLEMENTATION.createSubFunction("EnumMap");
public static final DependencyFunction LINKED_ENUM_MAP = ENUM_MAP.addChild(ORDERED_MAP.addChild(IMPLEMENTATION.createSubFunction("LinkedEnumMap")));
public static final DependencyFunction CONCURRENT_MAP = IMPLEMENTATION.createSubFunction("ConcurrentMap");
public static final DependencyFunction AVL_TREE_MAP = SORTED_MAP.addChild(IMPLEMENTATION.createSubFunction("AVLTreeMap"));
public static final DependencyFunction RB_TREE_MAP = SORTED_MAP.addChild(IMPLEMENTATION.createSubFunction("RBTreeMap"));
@Override @Override
public String getModuleName() { return "Map"; } public String getModuleName() { return "Map"; }
@ -20,79 +45,48 @@ public class MapModule extends BaseModule
@Override @Override
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; } public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; }
@Override @Override
public boolean areDependenciesLoaded() { return isDependencyLoaded(SetModule.INSTANCE) && isDependencyLoaded(CollectionModule.INSTANCE, false); } public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, ORDERED_MAP, SORTED_MAP, IMPLEMENTATION, WRAPPERS, ARRAY_MAP, IMMUTABLE_MAP, HASH_MAP, LINKED_MAP, CUSTOM_MAP, LINKED_CUSTOM_MAP, ENUM_MAP, LINKED_ENUM_MAP, CONCURRENT_MAP, AVL_TREE_MAP, RB_TREE_MAP); }
@Override
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
Set<String> sets = new TreeSet<>();
sets.addAll(Arrays.asList("Wrappers", "Implementations"));
sets.addAll(Arrays.asList("OrderedMap", "SortedMap"));
sets.addAll(Arrays.asList("ArrayMap", "ConcurrentMap", "ImmutableMap"));
sets.addAll(Arrays.asList("HashMap", "LinkedHashMap"));
sets.addAll(Arrays.asList("CustomHashMap", "LinkedCustomHashMap"));
sets.addAll(Arrays.asList("EnumMap", "LinkedEnumMap"));
sets.addAll(Arrays.asList("AVLTreeMap", "RBTreeMap"));
return sets;
}
@Override @Override
protected void loadFlags() protected void loadFlags()
{ {
if(isModuleEnabled()) addFlag("MAP_MODULE"); if(MODULE.isEnabled()) addFlag("MAP_MODULE");
if(isModuleEnabled("Wrappers")) addFlag("MAPS_FEATURE"); if(WRAPPERS.isEnabled()) addFlag("MAPS_FEATURE");
boolean implementations = isModuleEnabled("Implementations"); if(ORDERED_MAP.isEnabled()) addFlag("ORDERED_MAP_FEATURE");
boolean hashMap = implementations && isModuleEnabled("HashMap"); if(ARRAY_MAP.isEnabled()) addFlag("ARRAY_MAP_FEATURE");
boolean customHashMap = implementations && isModuleEnabled("CustomHashMap"); if(LINKED_MAP.isEnabled()) addFlag("LINKED_MAP_FEATURE");
boolean enumMap = implementations && isModuleEnabled("EnumMap"); if(LINKED_CUSTOM_MAP.isEnabled()) addFlag("LINKED_CUSTOM_MAP_FEATURE");
if(LINKED_ENUM_MAP.isEnabled()) addFlag("LINKED_ENUM_MAP_FEATURE");
if(isModuleEnabled("OrderedMap")) { if(SORTED_MAP.isEnabled()) addFlag("SORTED_MAP_FEATURE");
addFlag("ORDERED_MAP_FEATURE"); if(AVL_TREE_MAP.isEnabled()) addFlag("AVL_TREE_MAP_FEATURE");
if(isModuleEnabled("ArrayMap")) addFlag("ARRAY_MAP_FEATURE"); if(RB_TREE_MAP.isEnabled()) addFlag("RB_TREE_MAP_FEATURE");
if(hashMap && isModuleEnabled("LinkedHashMap")) addFlag("LINKED_MAP_FEATURE");
if(customHashMap && isModuleEnabled("LinkedCustomHashMap")) addFlag("LINKED_CUSTOM_MAP_FEATURE"); if(CONCURRENT_MAP.isEnabled()) addFlag("CONCURRENT_MAP_FEATURE");
if(enumMap && isModuleEnabled("LinkedEnumMap")) addFlag("LINKED_ENUM_MAP_FEATURE"); if(IMMUTABLE_MAP.isEnabled()) addFlag("IMMUTABLE_MAP_FEATURE");
} if(HASH_MAP.isEnabled()) addFlag("MAP_FEATURE");
if(isModuleEnabled("SortedMap")) { if(CUSTOM_MAP.isEnabled()) addFlag("CUSTOM_MAP_FEATURE");
addFlag("SORTED_MAP_FEATURE"); if(ENUM_MAP.isEnabled()) addFlag("ENUM_MAP_FEATURE");
if(implementations && isModuleEnabled("AVLTreeMap")) addFlag("AVL_TREE_MAP_FEATURE");
if(implementations && isModuleEnabled("RBTreeMap")) addFlag("RB_TREE_MAP_FEATURE");
}
if(implementations && isModuleEnabled("ConcurrentMap")) addFlag("CONCURRENT_MAP_FEATURE");
if(implementations && isModuleEnabled("ImmutableMap")) addFlag("IMMUTABLE_MAP_FEATURE");
if(hashMap) addFlag("MAP_FEATURE");
if(customHashMap) addFlag("CUSTOM_MAP_FEATURE");
if(enumMap) addFlag("ENUM_MAP_FEATURE");
} }
@Override @Override
protected void loadBlockades() protected void loadBlockades()
{ {
if(!isModuleEnabled()) addBlockedFiles("Map", "AbstractMap"); if(!MODULE.isEnabled()) addBlockedFiles("Map", "AbstractMap");
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Maps"); if(!WRAPPERS.isEnabled()) addBlockedFiles("Maps");
boolean implementations = !isModuleEnabled("Implementations"); if(!IMMUTABLE_MAP.isEnabled()) addBlockedFiles("ImmutableOpenHashMap");
if(implementations || !isModuleEnabled("ImmutableMap")) addBlockedFiles("ImmutableOpenHashMap"); if(!CONCURRENT_MAP.isEnabled()) addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
if(implementations || !isModuleEnabled("ConcurrentMap")) addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap"); if(!ORDERED_MAP.isEnabled()) addBlockedFiles("OrderedMap");
if(!HASH_MAP.isEnabled()) addBlockedFiles("OpenHashMap");
boolean ordered = !isModuleEnabled("OrderedMap"); if(!LINKED_MAP.isEnabled()) addBlockedFiles("LinkedOpenHashMap");
if(ordered) addBlockedFiles("OrderedMap"); if(CUSTOM_MAP.isEnabled()) addBlockedFiles("OpenCustomHashMap");
boolean hashMap = implementations || !isModuleEnabled("HashMap"); if(!LINKED_CUSTOM_MAP.isEnabled()) addBlockedFiles("LinkedOpenCustomHashMap");
if(hashMap) addBlockedFiles("OpenHashMap"); if(!ENUM_MAP.isEnabled()) addBlockedFiles("EnumMap");
if(hashMap || ordered || !isModuleEnabled("LinkedHashMap")) addBlockedFiles("LinkedOpenHashMap"); if(!LINKED_ENUM_MAP.isEnabled()) addBlockedFiles("LinkedEnumMap");
if(!ARRAY_MAP.isEnabled()) addBlockedFiles("ArrayMap");
boolean customHashMap = implementations || !isModuleEnabled("CustomHashMap"); if(!SORTED_MAP.isEnabled()) addBlockedFiles("SortedMap", "NavigableMap");
if(customHashMap) addBlockedFiles("OpenCustomHashMap"); if(!AVL_TREE_MAP.isEnabled()) addBlockedFiles("AVLTreeMap");
if(customHashMap || ordered || !isModuleEnabled("LinkedCustomHashMap")) addBlockedFiles("LinkedOpenCustomHashMap"); if(!RB_TREE_MAP.isEnabled()) addBlockedFiles("RBTreeMap");
boolean enumMap = implementations || !isModuleEnabled("EnumMap");
if(enumMap) addBlockedFiles("EnumMap");
if(enumMap || ordered || !isModuleEnabled("LinkedEnumMap")) addBlockedFiles("LinkedEnumMap");
if(ordered || !isModuleEnabled("ArrayMap")) addBlockedFiles("ArrayMap");
boolean sorted = !isModuleEnabled("SortedMap");
if(sorted) addBlockedFiles("SortedMap", "NavigableMap");
if(implementations || sorted || !isModuleEnabled("AVLTreeMap")) addBlockedFiles("AVLTreeMap");
if(implementations || sorted || !isModuleEnabled("RBTreeMap")) addBlockedFiles("RBTreeMap");
if(keyType == ClassType.BOOLEAN) if(keyType == ClassType.BOOLEAN)
{ {

View File

@ -1,15 +1,22 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.List;
import java.util.TreeSet;
import speiger.src.builder.ClassType; import speiger.src.builder.ClassType;
import speiger.src.builder.dependency.DependencyFunction;
import speiger.src.builder.dependency.DependencyModule;
import speiger.src.builder.dependency.DependencyModule.BiTypeModule;
import speiger.src.builder.dependency.IDependency;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class PairModule extends BaseModule public class PairModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new PairModule(); public static final BaseModule INSTANCE = new PairModule();
public static final DependencyModule MODULE = new BiTypeModule(INSTANCE);
public static final DependencyFunction IMMUTABLE = MODULE.createFunction("Immutable");
public static final DependencyFunction MUTABLE = MODULE.createFunction("Mutable");
@Override @Override
public String getModuleName() { return "Pair"; } public String getModuleName() { return "Pair"; }
@Override @Override
@ -21,20 +28,20 @@ public class PairModule extends BaseModule
@Override @Override
protected void loadTestClasses() {} protected void loadTestClasses() {}
@Override @Override
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return new TreeSet<>(Arrays.asList("Mutable", "Immutable")); } public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, IMMUTABLE, MUTABLE); }
@Override @Override
protected void loadFlags() { protected void loadFlags() {
if(isModuleEnabled()) addFlag("PAIR_MODULE"); if(MODULE.isEnabled()) addFlag("PAIR_MODULE");
if(isModuleEnabled("Mutable")) addFlag("MUTABLE_PAIR"); if(MUTABLE.isEnabled()) addFlag("MUTABLE_PAIR");
if(isModuleEnabled("Immutable")) addFlag("IMMUTABLE_PAIR"); if(IMMUTABLE.isEnabled()) addFlag("IMMUTABLE_PAIR");
} }
@Override @Override
protected void loadBlockades() { protected void loadBlockades() {
if(!isModuleEnabled()) addBlockedFiles("Pair"); if(!MODULE.isEnabled()) addBlockedFiles("Pair");
if(!isModuleEnabled("Mutable")) addBlockedFiles("MutablePair"); if(!MUTABLE.isEnabled()) addBlockedFiles("MutablePair");
if(!isModuleEnabled("Immutable")) addBlockedFiles("ImmutablePair"); if(!IMMUTABLE.isEnabled()) addBlockedFiles("ImmutablePair");
} }
@Override @Override

View File

@ -1,15 +1,25 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.List;
import java.util.TreeSet;
import speiger.src.builder.ClassType; import speiger.src.builder.ClassType;
import speiger.src.builder.dependency.DependencyFunction;
import speiger.src.builder.dependency.DependencyModule;
import speiger.src.builder.dependency.DependencyModule.SingleTypeModule;
import speiger.src.builder.dependency.IDependency;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class PrioQueueModule extends BaseModule public class PrioQueueModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new PrioQueueModule(); public static final BaseModule INSTANCE = new PrioQueueModule();
public static final DependencyModule MODULE = CollectionModule.MODULE.addChild(new SingleTypeModule(INSTANCE));
public static final DependencyFunction IMPLEMENTATION = MODULE.createFunction("Implementations");
public static final DependencyFunction WRAPPERS = MODULE.createFunction("Wrappers");
public static final DependencyFunction DEQUEUE = MODULE.createFunction("Dequeue");
public static final DependencyFunction FIFO_QUEUE = DEQUEUE.addChild(IMPLEMENTATION.createSubFunction("FiFoQueue"));
public static final DependencyFunction HEAP_QUEUE = IMPLEMENTATION.createSubFunction("HeapQueue");
public static final DependencyFunction ARRAY_PRIO_QUEUE = IMPLEMENTATION.createSubFunction("ArrayPrioQueue");
@Override @Override
public String getModuleName() { return "PriorityQueue"; } public String getModuleName() { return "PriorityQueue"; }
@ -18,36 +28,26 @@ public class PrioQueueModule extends BaseModule
@Override @Override
protected void loadFunctions() {} protected void loadFunctions() {}
@Override @Override
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); } public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, WRAPPERS, IMPLEMENTATION, DEQUEUE, FIFO_QUEUE, HEAP_QUEUE, ARRAY_PRIO_QUEUE); }
@Override
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
return new TreeSet<>(Arrays.asList("Wrappers", "Implementations", "Dequeue", "FiFoQueue", "HeapQueue", "ArrayPrioQueue"));
}
@Override @Override
protected void loadFlags() { protected void loadFlags() {
if(isModuleEnabled()) addFlag("QUEUE_MODULE"); if(MODULE.isEnabled()) addFlag("QUEUE_MODULE");
if(isModuleEnabled("Wrappers")) addKeyFlag("QUEUES_FEATURE"); if(WRAPPERS.isEnabled()) addKeyFlag("QUEUES_FEATURE");
boolean implementations = isModuleEnabled("Implementations"); if(DEQUEUE.isEnabled()) addKeyFlag("DEQUEUE_FEATURE");
if(isModuleEnabled("Dequeue")) { if(FIFO_QUEUE.isEnabled()) addKeyFlag("FIFO_QUEUE_FEATURE");
addKeyFlag("DEQUEUE_FEATURE"); if(HEAP_QUEUE.isEnabled()) addKeyFlag("HEAP_QUEUE_FEATURE");
if(implementations && isModuleEnabled("FiFoQueue")) addKeyFlag("FIFO_QUEUE_FEATURE"); if(ARRAY_PRIO_QUEUE.isEnabled()) addKeyFlag("ARRAY_QUEUE_FEATURE");
}
if(implementations && isModuleEnabled("HeapQueue")) addKeyFlag("HEAP_QUEUE_FEATURE");
if(implementations && isModuleEnabled("ArrayPrioQueue")) addKeyFlag("ARRAY_QUEUE_FEATURE");
} }
@Override @Override
protected void loadBlockades() { protected void loadBlockades() {
if(!isModuleEnabled()) addBlockedFiles("PriorityQueue", "AbstractPriorityQueue"); if(!MODULE.isEnabled()) addBlockedFiles("PriorityQueue", "AbstractPriorityQueue");
if(!isModuleEnabled("Wrappers")) addBlockedFiles("PriorityQueues"); if(!WRAPPERS.isEnabled()) addBlockedFiles("PriorityQueues");
boolean implementations = !isModuleEnabled("Implementations"); if(!DEQUEUE.isEnabled()) addBlockedFiles("PriorityDequeue");
boolean dequeue = !isModuleEnabled("Dequeue"); if(!FIFO_QUEUE.isEnabled()) addBlockedFiles("ArrayFIFOQueue");
if(dequeue) addBlockedFiles("PriorityDequeue"); if(!HEAP_QUEUE.isEnabled()) addBlockedFiles("HeapPriorityQueue");
if(dequeue || implementations || !isModuleEnabled("FiFoQueue")) addBlockedFiles("ArrayFIFOQueue"); if(!ARRAY_PRIO_QUEUE.isEnabled()) addBlockedFiles("ArrayPriorityQueue");
if(implementations || !isModuleEnabled("HeapQueue")) addBlockedFiles("HeapPriorityQueue");
if(implementations || !isModuleEnabled("ArrayPrioQueue")) addBlockedFiles("ArrayPriorityQueue");
if(keyType == ClassType.BOOLEAN) { if(keyType == ClassType.BOOLEAN) {
addBlockedFiles("QueueTests"); addBlockedFiles("QueueTests");

View File

@ -1,15 +1,31 @@
package speiger.src.builder.modules; package speiger.src.builder.modules;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.List;
import java.util.TreeSet;
import speiger.src.builder.ClassType; import speiger.src.builder.ClassType;
import speiger.src.builder.dependency.DependencyFunction;
import speiger.src.builder.dependency.DependencyModule;
import speiger.src.builder.dependency.DependencyModule.SingleTypeModule;
import speiger.src.builder.dependency.IDependency;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class SetModule extends BaseModule public class SetModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new SetModule(); public static final BaseModule INSTANCE = new SetModule();
public static final DependencyModule MODULE = CollectionModule.MODULE.addChild(new SingleTypeModule(INSTANCE));
public static final DependencyFunction WRAPPERS = MODULE.createFunction("Wrappers");
public static final DependencyFunction IMPLEMENTATION = MODULE.createFunction("Implementations");
public static final DependencyFunction ORDERED_SET = MODULE.createFunction("OrderedSet");
public static final DependencyFunction SORTED_SET = MODULE.createFunction("SortedSet");
public static final DependencyFunction ARRAY_SET = ORDERED_SET.addChild(IMPLEMENTATION.createSubFunction("ArraySet"));
public static final DependencyFunction IMMUTABLE_SET = IMPLEMENTATION.createSubFunction("ImmutableSet");
public static final DependencyFunction HASH_SET = IMPLEMENTATION.createSubFunction("HashSet");
public static final DependencyFunction LINKED_SET = HASH_SET.addChild(ORDERED_SET.addChild(IMPLEMENTATION.createSubFunction("LinkedHashSet")));
public static final DependencyFunction CUSTOM_SET = IMPLEMENTATION.createSubFunction("CustomHashSet");
public static final DependencyFunction LINKED_CUSTOM_SET = CUSTOM_SET.addChild(ORDERED_SET.addChild(IMPLEMENTATION.createSubFunction("LinkedCustomHashSet")));
public static final DependencyFunction AVL_TREE_SET = SORTED_SET.addChild(IMPLEMENTATION.createSubFunction("AVLTreeSet"));
public static final DependencyFunction RB_TREE_SET = SORTED_SET.addChild(IMPLEMENTATION.createSubFunction("RBTreeSet"));
@Override @Override
public String getModuleName() { return "Set"; } public String getModuleName() { return "Set"; }
@ -19,68 +35,40 @@ public class SetModule extends BaseModule
@Override @Override
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; } public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; }
@Override @Override
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); } public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, WRAPPERS, ORDERED_SET, SORTED_SET, IMPLEMENTATION, ARRAY_SET, IMMUTABLE_SET, HASH_SET, LINKED_SET, CUSTOM_SET, LINKED_CUSTOM_SET, AVL_TREE_SET, RB_TREE_SET); }
@Override
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
Set<String> sets = new TreeSet<>();
sets.addAll(Arrays.asList("Wrappers", "Implementations"));
sets.addAll(Arrays.asList("OrderedSet", "SortedSet"));
sets.addAll(Arrays.asList("ArraySet", "ImmutableSet"));
sets.addAll(Arrays.asList("HashSet", "LinkedHashSet"));
sets.addAll(Arrays.asList("CustomHashSet", "LinkedCustomHashSet"));
sets.addAll(Arrays.asList("AVLTreeSet", "RBTreeSet"));
return sets;
}
@Override @Override
protected void loadFlags() protected void loadFlags()
{ {
if(isModuleEnabled()) addFlag("SET_MODULE"); if(MODULE.isEnabled()) addFlag("SET_MODULE");
if(isModuleEnabled("Wrappers")) addFlag("SETS_FEATURE"); if(WRAPPERS.isEnabled()) addFlag("SETS_FEATURE");
boolean implementations = isModuleEnabled("Implementations"); if(ORDERED_SET.isEnabled()) addFlag("ORDERED_SET_FEATURE");
boolean hashSet = implementations && isModuleEnabled("HashSet"); if(SORTED_SET.isEnabled()) addFlag("SORTED_SET_FEATURE");
boolean customHashSet = implementations && isModuleEnabled("CustomHashSet"); if(IMMUTABLE_SET.isEnabled()) addFlag("IMMUTABLE_SET_FEATURE");
if(ARRAY_SET.isEnabled()) addFlag("ARRAY_SET_FEATURE");
if(isModuleEnabled("OrderedSet")) { if(HASH_SET.isEnabled()) addFlag("HASH_SET_FEATURE");
addFlag("ORDERED_SET_FEATURE"); if(LINKED_SET.isEnabled()) addFlag("LINKED_SET_FEATURE");
if(implementations && isModuleEnabled("ArraySet")) addFlag("ARRAY_SET_FEATURE"); if(CUSTOM_SET.isEnabled()) addFlag("CUSTOM_HASH_SET_FEATURE");
if(hashSet && isModuleEnabled("LinkedHashSet")) addFlag("LINKED_SET_FEATURE"); if(LINKED_CUSTOM_SET.isEnabled()) addFlag("LINKED_CUSTOM_SET_FEATURE");
if(customHashSet && isModuleEnabled("LinkedCustomHashSet")) addFlag("LINKED_CUSTOM_SET_FEATURE"); if(AVL_TREE_SET.isEnabled()) addFlag("AVL_TREE_SET_FEATURE");
} if(RB_TREE_SET.isEnabled()) addFlag("RB_TREE_SET_FEATURE");
if(isModuleEnabled("SortedSet")) {
addFlag("SORTED_SET_FEATURE");
if(implementations && isModuleEnabled("AVLTreeSet")) addFlag("AVL_TREE_SET_FEATURE");
if(implementations && isModuleEnabled("RBTreeSet")) addFlag("RB_TREE_SET_FEATURE");
}
if(implementations && isModuleEnabled("ImmutableSet")) addFlag("IMMUTABLE_SET_FEATURE");
if(hashSet) addFlag("HASH_SET_FEATURE");
if(customHashSet) addFlag("CUSTOM_HASH_SET_FEATURE");
} }
@Override @Override
protected void loadBlockades() protected void loadBlockades()
{ {
if(!isModuleEnabled()) addBlockedFiles("Set", "AbstractSet"); if(!MODULE.isEnabled()) addBlockedFiles("Set", "AbstractSet");
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Sets"); if(!WRAPPERS.isEnabled()) addBlockedFiles("Sets");
boolean implementations = !isModuleEnabled("Implementations"); if(!IMMUTABLE_SET.isEnabled()) addBlockedFiles("ImmutableOpenHashSet");
if(implementations || !isModuleEnabled("ImmutableSet")) addBlockedFiles("ImmutableOpenHashSet"); if(!ORDERED_SET.isEnabled()) addBlockedFiles("OrderedSet");
if(!HASH_SET.isEnabled()) addBlockedFiles("OpenHashSet");
boolean ordered = !isModuleEnabled("OrderedSet"); if(!LINKED_SET.isEnabled()) addBlockedFiles("LinkedOpenHashSet");
if(ordered) addBlockedFiles("OrderedSet"); if(!CUSTOM_SET.isEnabled()) addBlockedFiles("OpenCustomHashSet");
boolean hashSet = implementations || !isModuleEnabled("HashSet"); if(!LINKED_CUSTOM_SET.isEnabled()) addBlockedFiles("LinkedOpenCustomHashSet");
if(hashSet) addBlockedFiles("OpenHashSet"); if(!ARRAY_SET.isEnabled()) addBlockedFiles("ArraySet");
if(hashSet || ordered || !isModuleEnabled("LinkedHashSet")) addBlockedFiles("LinkedOpenHashSet"); if(!SORTED_SET.isEnabled()) addBlockedFiles("SortedSet", "NavigableSet");
if(!AVL_TREE_SET.isEnabled()) addBlockedFiles("AVLTreeSet");
boolean customHashSet = implementations || !isModuleEnabled("CustomHashSet"); if(!RB_TREE_SET.isEnabled()) addBlockedFiles("RBTreeSet");
if(customHashSet) addBlockedFiles("OpenCustomHashSet");
if(customHashSet || ordered || !isModuleEnabled("LinkedCustomHashSet")) addBlockedFiles("LinkedOpenCustomHashSet");
if(implementations || ordered || !isModuleEnabled("ArraySet")) addBlockedFiles("ArraySet");
boolean sorted = !isModuleEnabled("SortedSet");
if(sorted) addBlockedFiles("SortedSet", "NavigableSet");
if(implementations || sorted || !isModuleEnabled("AVLTreeSet")) addBlockedFiles("AVLTreeSet");
if(implementations || sorted || !isModuleEnabled("RBTreeSet")) addBlockedFiles("RBTreeSet");
if(keyType == ClassType.BOOLEAN) if(keyType == ClassType.BOOLEAN)
{ {