Add the TestCommandMetaDataFactory to generate the metadata.
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
package space.kklochko.simple_jbdd.tests.factories.meta;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class AbstractTestCommandMetaDataFactory {
|
||||
abstract public ArrayList<AbstractMap.SimpleEntry<String, String>> create();
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package space.kklochko.simple_jbdd.tests.factories.meta;
|
||||
|
||||
import space.kklochko.simple_jbdd.tests.commands.AbstractTestCommand;
|
||||
import space.kklochko.simple_jbdd.tests.commands.decorators.AbstractDecorator;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TestCommandMetaDataFactory extends AbstractTestCommandMetaDataFactory {
|
||||
private AbstractTestCommand command;
|
||||
|
||||
public TestCommandMetaDataFactory(AbstractTestCommand command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public ArrayList<AbstractMap.SimpleEntry<String, String>> create() {
|
||||
ArrayList<AbstractMap.SimpleEntry<String, String>> blocks = new ArrayList<>();
|
||||
AbstractTestCommand currentCommand = command;
|
||||
Class<?> aClass = command.getClass();
|
||||
|
||||
while(AbstractDecorator.class.isAssignableFrom(aClass)) {
|
||||
AbstractDecorator block = (AbstractDecorator) currentCommand;
|
||||
blocks.add(new AbstractMap.SimpleEntry<>(block.getType(), block.getLabel()));
|
||||
|
||||
currentCommand = block.getCommand();
|
||||
aClass = currentCommand.getClass();
|
||||
}
|
||||
|
||||
blocks.add(0, (new AbstractMap.SimpleEntry<>(currentCommand.getType(), currentCommand.getLabel())));
|
||||
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user