Commit 4644867d authored by hm-schuhba1's avatar hm-schuhba1

Add ScenarioChecker for processors with MeasurementAreas

The ProcessorFlag interface is a marker interface used anywehre a
specifc attribute of some DataProcessors are needed. For instnace
the UsesMeasurementArea Interface is implemented by all Processors
usinge one or more MeasurementAreas. In this example the interface
exposes an array of given MeasurementAreaIds which can be used
within the ScenarioChecker.

These interfaces are therefore aribtraty flags used to filter a
generic list of DataProcesors if needed.
parent 42ce721a
Pipeline #102178 failed with stages
in 96 minutes and 34 seconds
......@@ -25,4 +25,6 @@ public @interface DataProcessorClass {
String label() default "";
String description() default "";
String[] processorFlags() default {};
}
......@@ -5,6 +5,8 @@ import com.google.auto.service.AutoService;
import org.vadere.annotation.factories.BaseFactoryProcessor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import javax.annotation.processing.Processor;
......@@ -12,6 +14,10 @@ import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
@SupportedAnnotationTypes("org.vadere.annotation.factories.dataprocessors.DataProcessorClass")
@SupportedSourceVersion(SourceVersion.RELEASE_11)
......@@ -32,10 +38,23 @@ public class DataProcessorFactoryProcessor extends BaseFactoryProcessor {
protected void addLastConstructor(Set<? extends Element> elements, PrintWriter writer) {
for (Element e : elements) {
writer.append(" addMember(");
writer.append(e.getSimpleName().toString()).append(".class, ");
writer.append("this::").append("get").append(name(e)).append(", ");
writer.append(quote(label(e))).append(", ");
writer.append(quote(descr(e))).println("); ");
writer.append(quote(descr(e))).append(", ");
writer.append(e.getSimpleName().toString()).append(".class");
//if flags are provides here...
String[] flags = processorFlags(e);
if (flags.length > 0){
writer.append(", ");
for (int i = 0; i < flags.length -1; i++) {
writer.append(quote(flags[i])).append(", ");
}
writer.append(quote(flags[flags.length-1]));
writer.println("); ");
} else {
writer.println("); ");
}
}
}
......@@ -76,4 +95,29 @@ public class DataProcessorFactoryProcessor extends BaseFactoryProcessor {
return dataProcessorClass.description();
}
private String[] processorFlags(Element element){
DataProcessorClass dataProcessorClass = element.getAnnotation(DataProcessorClass.class);
Elements elementUtil = processingEnv.getElementUtils();
Types typeUtil = processingEnv.getTypeUtils();
ArrayList<String> flags = new ArrayList<>();
TypeMirror processorFlag = elementUtil
.getTypeElement("org.vadere.simulator.projects.dataprocessing.flags.ProcessorFlag")
.asType();
// cast possible becuse element is a class
TypeElement e = (TypeElement)element;
for (TypeMirror anInterface : e.getInterfaces()) {
if (typeUtil.isAssignable(anInterface, processorFlag)){
flags.add(typeUtil.asElement(anInterface).getSimpleName().toString());
}
}
flags.addAll(Arrays.asList(dataProcessorClass.processorFlags()));
return flags.toArray(String[]::new);
}
}
......@@ -2,7 +2,7 @@
"name" : "group_OSM_1Source2Places_noGroups",
"description" : "",
"release" : "0.8",
`` "processWriters" : {
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "postvis.trajectories",
......@@ -240,4 +240,4 @@
},
"eventInfos" : [ ]
}
}
\ No newline at end of file
}
......@@ -39,6 +39,8 @@ ScenarioChecker.overlap.obstacle.obstacle=Two obstacles overlap / is enclosed co
ScenarioChecker.simAttr.simTimeStepWrong=simTimeStep parameter outside of allowed range
ScenarioChecker.processor.measuremetarea.doesNotExist=MeasurementArea referenced in processor does not exist.
ScenarioChecker.msg.ok=Scenario ok.
ScenarioChecker.msg.warn=Scenario contains warnings.
ScenarioChecker.msg.err=Scenario contains errors.
......@@ -39,6 +39,8 @@ ScenarioChecker.overlap.obstacle.obstacle=Zwei identische bzw. eingeschlossene H
ScenarioChecker.simAttr.simTimeStepWrong=simTimeStep Parameter au\u00dferhalb des Definitionsbereichs
ScenarioChecker.processor.measuremetarea.doesNotExist=Referenzierte Messfläche im Daten Prozessor existiert nicht.
ScenarioChecker.msg.ok=Szenario ok.
ScenarioChecker.msg.warn=Szenario hat Warnungen.
ScenarioChecker.msg.err=Szenario ist Fehlerhaft.
package org.vadere.simulator.projects.dataprocessing.flags;
/**
* Marker interface to identify a {@link org.vadere.simulator.projects.dataprocessing.processor.DataProcessor}
* based on some arbitrary property. These Interfaces are useful to filter processors of a
* scenario to check if the settings of the processor are correct.
*/
public interface ProcessorFlag {
}
package org.vadere.simulator.projects.dataprocessing.flags;
/**
* Return all id's referencing a {@link org.vadere.state.scenario.MeasurementArea}. These
* are used to check if the specified {@link org.vadere.state.scenario.MeasurementArea}
* exist in the simulation.
*/
public interface UsesMeasurementArea extends ProcessorFlag {
int[] getReferencedMeasurementAreaId();
}
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
import org.vadere.state.attributes.processor.AttributesAreaDensityVoronoiProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.factory.processors.Flag;
import java.util.List;
/**
* @author Mario Teixeira Parente
*
*/
@DataProcessorClass(label = "AreaDensityVoronoiProcessor")
public class AreaDensityVoronoiProcessor extends AreaDensityProcessor {
public class AreaDensityVoronoiProcessor extends AreaDensityProcessor implements UsesMeasurementArea {
public AreaDensityVoronoiProcessor(){
super();
......@@ -41,4 +45,11 @@ public class AreaDensityVoronoiProcessor extends AreaDensityProcessor {
return super.getAttributes();
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesAreaDensityVoronoiProcessor att = (AttributesAreaDensityVoronoiProcessor) this.getAttributes();
return new int[]{att.getMeasurementAreaId(), att.getMeasurementAreaId()};
}
}
......@@ -53,6 +53,7 @@ public abstract class DataProcessor<K extends DataKey<K>, V> {
this.lastStep = 0;
}
protected Map<K, V> getData() {
return this.data;
}
......
......@@ -6,14 +6,17 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramBProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Topography;
import org.vadere.state.simulation.VTrajectory;
import org.vadere.util.factory.processors.Flag;
import org.vadere.util.logging.Logger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
......@@ -32,7 +35,7 @@ import java.util.Map;
* @author Benedikt Zoennchen
*/
@DataProcessorClass()
public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>> {
public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>> implements UsesMeasurementArea {
private static Logger logger = Logger.getLogger(Topography.class);
......@@ -167,4 +170,11 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
public String[] toStrings(@NotNull final PedestrianIdKey key) {
return new String[]{ Double.toString(getValue(key).getLeft()), Double.toString(getValue(key).getRight()) };
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesFundamentalDiagramBProcessor att = (AttributesFundamentalDiagramBProcessor) this.getAttributes();
return new int[]{att.getMeasurementAreaId()};
}
}
......@@ -7,10 +7,13 @@ import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramCProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.factory.processors.Flag;
import java.util.List;
/**
* <p>This processor computes the fundamental diagram by computing at a certain time the
......@@ -24,7 +27,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
* @author Benedikt Zoennchen
*/
@DataProcessorClass()
public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, Double>> {
public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, Double>> implements UsesMeasurementArea {
private MeasurementArea measurementArea;
......@@ -91,4 +94,10 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
public String[] toStrings(@NotNull final TimestepKey key) {
return new String[]{ Double.toString(getValue(key).getLeft()), Double.toString(getValue(key).getRight()) };
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesFundamentalDiagramCProcessor att = (AttributesFundamentalDiagramCProcessor) this.getAttributes();
return new int[]{att.getMeasurementAreaId()};
}
}
......@@ -6,10 +6,13 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramDProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.factory.processors.Flag;
import java.util.List;
/**
* <p>This processor computes the fundamental diagram by computing at a certain time the
......@@ -25,7 +28,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
* @author Benedikt Zoennchen
*/
@DataProcessorClass()
public class FundamentalDiagramDProcessor extends AreaDataProcessor<Pair<Double, Double>> {
public class FundamentalDiagramDProcessor extends AreaDataProcessor<Pair<Double, Double>> implements UsesMeasurementArea {
private IntegralVoronoiAlgorithm integralVoronoiAlgorithm;
private APedestrianVelocityProcessor pedestrianVelocityProcessor;
......@@ -76,4 +79,11 @@ public class FundamentalDiagramDProcessor extends AreaDataProcessor<Pair<Double,
public String[] toStrings(@NotNull final TimestepKey key) {
return new String[]{ Double.toString(getValue(key).getLeft()), Double.toString(getValue(key).getRight()) };
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesFundamentalDiagramDProcessor att = (AttributesFundamentalDiagramDProcessor) this.getAttributes();
return new int[]{att.getVoronoiMeasurementAreaId(), att.getMeasurementAreaId()};
}
}
......@@ -6,16 +6,20 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramEProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.factory.processors.Flag;
import java.util.List;
/**
*
* @author Benedikt Zoennchen
*/
@DataProcessorClass()
public class FundamentalDiagramEProcessor extends AreaDataProcessor<Pair<Double, Double>> {
public class FundamentalDiagramEProcessor extends AreaDataProcessor<Pair<Double, Double>> implements UsesMeasurementArea {
private SumVoronoiAlgorithm sumVoronoiAlgorithm;
private APedestrianVelocityProcessor pedestrianVelocityProcessor;
......@@ -66,4 +70,12 @@ public class FundamentalDiagramEProcessor extends AreaDataProcessor<Pair<Double,
public String[] toStrings(@NotNull final TimestepKey key) {
return new String[]{ Double.toString(getValue(key).getLeft()), Double.toString(getValue(key).getRight()) };
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesFundamentalDiagramEProcessor att = (AttributesFundamentalDiagramEProcessor) this.getAttributes();
return new int[]{att.getVoronoiMeasurementAreaId(), att.getMeasurementAreaId()};
}
}
......@@ -6,20 +6,21 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
import org.vadere.state.attributes.processor.AttributesCrossingTimeProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.FootStep;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.factory.processors.Flag;
import org.vadere.util.logging.Logger;
import java.util.Collection;
import java.util.List;
//TODO
@DataProcessorClass()
public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>>{
public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>> implements UsesMeasurementArea {
private MeasurementArea measurementArea;
private static Logger logger = Logger.getLogger(PedestrianCrossingTimeProcessor.class);
......@@ -99,4 +100,11 @@ public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdK
Pair<Double, Double> times = getValue(key);
return new String[]{Double.toString(times.getLeft()), Double.toString(times.getRight())};
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesCrossingTimeProcessor att = (AttributesCrossingTimeProcessor) this.getAttributes();
return new int[]{att.getWaitingAreaId(), att.getMeasurementAreaId()};
}
}
......@@ -4,20 +4,22 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
import org.vadere.state.attributes.processor.AttributesPedestrianWaitingEndTimeProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.factory.processors.Flag;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.Collection;
import java.util.List;
/**
* @author Mario Teixeira Parente
*/
@DataProcessorClass()
public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianIdKey, Double> {
public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianIdKey, Double> implements UsesMeasurementArea {
private MeasurementArea waitingArea;
public PedestrianWaitingEndTimeProcessor() {
......@@ -59,4 +61,11 @@ public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianI
return super.getAttributes();
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesPedestrianWaitingEndTimeProcessor att = (AttributesPedestrianWaitingEndTimeProcessor) this.getAttributes();
return new int[]{att.getWaitingAreaId()};
}
}
......@@ -4,20 +4,22 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
import org.vadere.state.attributes.processor.AttributesPedestrianWaitingTimeProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.factory.processors.Flag;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.Collection;
import java.util.List;
/**
* @author Mario Teixeira Parente
*/
@DataProcessorClass()
public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKey, Double> {
public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKey, Double> implements UsesMeasurementArea {
private double lastSimTime;
private MeasurementArea waitingArea;
......@@ -67,4 +69,10 @@ public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKe
return super.getAttributes();
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesPedestrianWaitingTimeProcessor att = (AttributesPedestrianWaitingTimeProcessor) this.getAttributes();
return new int[]{att.getWaitingAreaId()};
}
}
......@@ -3,6 +3,7 @@ package org.vadere.simulator.utils.scenariochecker;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.utils.scenariochecker.checks.ScenarioCheckerTest;
import org.vadere.simulator.utils.scenariochecker.checks.dataProcessors.DataProcessorsLinkedToMeasurementArea;
import org.vadere.simulator.utils.scenariochecker.checks.simulation.SimulationTimeStepLengthCheck;
import org.vadere.simulator.utils.scenariochecker.checks.topography.PedestrianSpeedSetupCheck;
import org.vadere.simulator.utils.scenariochecker.checks.topography.SourceMinRadiusCheck;
......@@ -67,6 +68,7 @@ public class ScenarioChecker {
ret.addAll(checkSourceSpawnSetting());
ret.addAll(checkMinSourceRadius());
ret.addAll(runCheck(new TopographyOffsetCheck()));
ret.addAll(runCheck(new DataProcessorsLinkedToMeasurementArea()));
return ret;
}
......
......@@ -40,7 +40,9 @@ public enum ScenarioCheckerReason {
PEDESTRIAN_SPEED_NEGATIVE("ScenarioChecker.pedestrian.speedIsNegative"),
// Simulation attribute reasons
SIM_TIME_STEP_WRONG("ScenarioChecker.simAttr.simTimeStepWrong");
SIM_TIME_STEP_WRONG("ScenarioChecker.simAttr.simTimeStepWrong"),
PROCESSOR_MEASUREMENT_AREA("ScenarioChecker.processor.measuremetarea.doesNotExist");
private String msgId;
......
package org.vadere.simulator.utils.scenariochecker.checks.dataProcessors;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
import org.vadere.simulator.projects.dataprocessing.processor.DataProcessor;
import org.vadere.simulator.projects.dataprocessing.processor.DataProcessorFactory;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerReason;
import org.vadere.simulator.utils.scenariochecker.checks.AbstractScenarioCheck;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.factory.processors.Flag;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.stream.Collectors;
public class DataProcessorsLinkedToMeasurementArea extends AbstractScenarioCheck {
@Override
public PriorityQueue<ScenarioCheckerMessage> runScenarioCheckerTest(Scenario scenario) {
PriorityQueue<ScenarioCheckerMessage> ret = new PriorityQueue<>();
List<DataProcessor<?, ?>> processors
= scenario.getDataProcessingJsonManager().getDataProcessors();
List<Integer> measurementAreas = scenario.getTopography().getMeasurementAreas()
.stream()
.map(MeasurementArea::getId)
.collect(Collectors.toList());
processors.stream().filter(UsesMeasurementArea.class::isInstance).forEach( p -> {
UsesMeasurementArea pArea = (UsesMeasurementArea)p;
for (int areaId : pArea.getReferencedMeasurementAreaId()) {
if (!measurementAreas.contains(areaId)) {
ret.add(msgBuilder.dataProcessorAttrError()
.reason(ScenarioCheckerReason.PROCESSOR_MEASUREMENT_AREA,
String.format(" [Processor id: %d]", p.getId()))
.build()
);
}
}
});
return ret;
}
}
package org.vadere.util.factory.processors;
import java.util.ArrayList;
import java.util.Objects;
public class Flag {
public static final String needMeasurementArea = "needMeasurementArea";
private final String description;
public static ArrayList<Flag> getFlags(String... flags){
ArrayList<Flag> ret = new ArrayList<>();
for (String flag : flags) {
ret.add(new Flag(flag));
}
return ret;
}
public Flag(String description){
this.description = description;
}
public String getDescription() {
return description;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Flag that = (Flag) o;
return description.equals(that.description);
}
@Override
public int hashCode() {
return Objects.hash(description);
}
}
......@@ -2,15 +2,17 @@ package org.vadere.util.factory.processors;
import org.vadere.util.factory.BaseFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ProcessorBaseFactory<T> extends BaseFactory<T, ProcessorFactoryObject<T>> {
public void addMember(Class clazz, Supplier supplier, String label, String desc) {
supplierMap.put(clazz.getCanonicalName(), new ProcessorFactoryObject<>(clazz, supplier, label, desc));
public void addMember(Supplier supplier, String label, String desc, Class clazz, String... flags) {
supplierMap.put(clazz.getCanonicalName(), new ProcessorFactoryObject<>(supplier, label, desc, clazz, flags));
}
public HashMap<String, String> getLabelMap() {
......@@ -22,4 +24,18 @@ public class ProcessorBaseFactory<T> extends BaseFactory<T, ProcessorFactoryObje
public List<String> getProcessors() {
return supplierMap.keySet().stream().collect(Collectors.toList());
}
public ArrayList<Flag> getFlag(String key){
ProcessorFactoryObject<T> processorFactoryObject = supplierMap.get(key);
return processorFactoryObject.getFlags();
}
public boolean containsFlag(Class processor, String flagStr){
ProcessorFactoryObject<T> processorFactoryObject = supplierMap.get(processor.getCanonicalName());
if (processorFactoryObject == null)
return false;
Flag flag = new Flag(flagStr);
return processorFactoryObject.getFlags().stream().anyMatch(f -> f.equals(flag));
}
}
......@@ -2,17 +2,20 @@ package org.vadere.util.factory.processors;
import org.vadere.util.factory.FactoryObject;
import java.util.ArrayList;
import java.util.function.Supplier;
public class ProcessorFactoryObject<T> extends FactoryObject<T> {
private final String label;
private final String description;
private final ArrayList<Flag> flags;
public ProcessorFactoryObject(Class clazz, Supplier<T> supplier, String label, String description){
public ProcessorFactoryObject(Supplier<T> supplier, String label, String description, Class clazz, String... flags){
super(clazz, supplier);
this.label = label;
this.description = description;
this.flags = Flag.getFlags(flags);
}
public String getLabel() {
......@@ -24,4 +27,7 @@ public class ProcessorFactoryObject<T> extends FactoryObject<T> {
return description;
}
public ArrayList<Flag> getFlags(){
return flags;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment