{
Object lastItem = sequence.get(sequence.size() - 1);
if(!(lastItem instanceof Algorithm))
{
throw new WorkflowException("Last item was not an algorithm.");
}
if(!((Algorithm) lastItem).assertGraph2OutputType((Graph) item))
{
throw new WorkflowException("Postconditions failed: assertGraph2OutputType()");
}
((Algorithm) lastItem).setGraph2Output((Graph) item);
logger.debug("Adding a graph");
sequence.add(item);
}
}
else if(item instanceof Algorithm)
{
if(sequence.size() < 1)
{
throw new WorkflowException("Sequence is empty. First add a graph before adding an algorithm.");
}
Object lastItem = sequence.get(sequence.size() - 1);
Util.assertNotNull(lastItem);
if(!(lastItem instanceof Graph))
{
throw new WorkflowException("Last item was not a graph.");
}
Algorithm alg = (Algorithm) item;
if(!alg.assertGraph2ListenType((Graph) lastItem))
{
throw new WorkflowException("Failed preconditions: assertGraph2ListenType()");
}
alg.setGraph2Listen((Graph) lastItem);
((Graph) lastItem).addObserver(alg);
if(item instanceof EvaluationAlgorithm)
{
Util.assertNotNull(((EvaluationAlgorithm) alg).getWrappedAroundAlg());
}
logger.debug("Adding an algorithm.");
sequence.add(item);
}
else
{
throw new WorkflowException("Unknown element. Cannot add.");
}
}