structures.lazy.LazyActionManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nostream Show documentation
Show all versions of nostream Show documentation
Extension of classic Java data structures that avoid the use of Stream abstraction in favour of direct list transformation methods
The newest version!
package structures.lazy;
import java.util.Objects;
import factory.IOCollectionFactory;
import factory.ListFactory;
import operations.OperationImpl;
import structures.ArrayList;
import structures.List;
public class LazyActionManager {
private List input;
private List output;
private List> outputTrasformedList;
private boolean invokedTrasformingTypeAction = false;
private List actions = new ArrayList<>();
private OperationImpl operationImpl;
private IOCollectionFactory ioCollectionFactory;
private ListFactory l;
public LazyActionManager(ListFactory l){
input = l.buildList();
output = l.buildList();
this.l = l;
ioCollectionFactory = new IOCollectionFactory<>();
operationImpl = new OperationImpl<>();
}
public void addAction(Runnable action) {
assertNoOneTransformingTypeAction();
actions.add(() -> {
output.clear();
operationImpl.setIOCollection(ioCollectionFactory.buildWithDefinedCollectionOutput(input, output));
action.run();
});
swapInputAndOutput();
}
private void swapInputAndOutput() {
List tmp = input;
input = output;
output = tmp;
}
public void addTrasformingTypeAction(Runnable endingRunnable) {
assertNoOneTransformingTypeAction();
invokedTrasformingTypeAction = true;
outputTrasformedList = l.buildList();
actions.add(() ->
{
operationImpl
.setIOCollection(ioCollectionFactory.buildWithDefinedCollectionOutput(input, outputTrasformedList));
endingRunnable.run();
});
}
public void assertNoOneTransformingTypeAction() throws IllegalAccessError {
if(isInvokedTrasformingTypeAction()){
throw new IllegalAccessError("Yet invoked a last action");
}
}
public void setInput(List inputList) {
this.input = inputList;
}
public OperationImpl getOperationList() {
return operationImpl;
}
public List getActions() {
return actions;
}
public boolean isInvokedTrasformingTypeAction() {
return invokedTrasformingTypeAction;
}
public List getOutputTrasformingType() {
if(!isInvokedTrasformingTypeAction()){
throw new IllegalStateException("Actually are not invoked trasforming type method");
}
return (List) outputTrasformedList;
}
public List getInput() {
return input;
}
public List getOutput() {
return output;
}
public int numActions() {
return actions.size();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy