/** * Push the specified completion event to the parent node */ protected final void pushCompletion(Completion completion) { if (parent != null) parent.receiveCompletion(parent.getIndex(this), completion); }
/** * Push the specified job up to the parent node in the iteration strategy. */ protected final void pushJob(Job job) { if (parent != null) { int index = parent.getIndex(this); if (index < 0) throw new WorkflowStructureException( "Parent doesn't have this node in its child list!"); parent.receiveJob(parent.getIndex(this), job); } } }
@Override public void removeFromParent() { if (parent != null) { IterationStrategyNode oldParent = parent; parent = null; oldParent.remove(this); } }
@Override public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { if (getChildCount() == 0) return -1; return getChildAt(0).getIterationDepth(inputDepths); } }
/** * Implements IterationStrategyNode */ @Override public final synchronized void setParent(MutableTreeNode newParent) { if (newParent != null && !(newParent instanceof IterationStrategyNode)) throw new IllegalArgumentException( "Parent not a IterationStrategyNode instance: " + newParent); if (newParent != null && !newParent.getAllowsChildren()) throw new IllegalStateException( "New parent does not allow children"); if (newParent == this) throw new IllegalArgumentException("Can't be it's own parent"); removeFromParent(); parent = (IterationStrategyNode) newParent; if (parent != null && !parent.getChildren().contains(this)) parent.insert(this); }
/** * Clear the child list and parent of this node */ @Override public final synchronized void clear() { for (IterationStrategyNode child : children) child.setParent(null); children.clear(); this.parent = null; }
@Test public void moveNodeToDifferentParent() { crossProduct1.setParent(root); crossProduct1.insert(input1); crossProduct1.insert(dotProduct1); dotProduct1.insert(input2); dotProduct1.insert(crossProduct2); // Check tree assertEquals(crossProduct2, root.getChildAt(0).getChildAt(1) .getChildAt(1)); assertEquals(Arrays.asList(input2, crossProduct2), dotProduct1 .getChildren()); crossProduct1.insert(crossProduct2, 1); assertEquals(Arrays.asList(input1, crossProduct2, dotProduct1), crossProduct1.getChildren()); assertEquals(crossProduct1, crossProduct2.getParent()); // Should no longer be in dotProduct1 assertEquals(Arrays.asList(input2), dotProduct1.getChildren()); }
@Override public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { // Check that all input depths are the same if (isLeaf()) // No children! throw new IterationTypeMismatchException("Dot product with no children"); int depth = getChildAt(0).getIterationDepth(inputDepths); for (IterationStrategyNode childNode : getChildren()) if (childNode.getIterationDepth(inputDepths) != depth) throw new IterationTypeMismatchException( "Mismatched input types for dot product node"); return depth; } }
@Override public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { if (isLeaf()) // No children! throw new IterationTypeMismatchException( "Cross product with no children"); int temp = 0; for (IterationStrategyNode child : getChildren()) temp += child.getIterationDepth(inputDepths); return temp; } }