.nextElement(); AbstractIterationStrategyNode parent = (AbstractIterationStrategyNode) n .getParent(); && n.getChildCount() == 0) { parent.remove(n); finished = false; } else if (!(n.isLeaf()) && parent != null && n.getChildCount() == 1) { .getChildAt(0); int oldIndex = parent.getIndex(n); parent.remove(n); parent.insert(child, oldIndex); finished = false;
/** * Implements IterationStrategyNode */ protected final synchronized void addChild( AbstractIterationStrategyNode newChild) { newChild.setParent(this); }
public void remove(int index) { if (!getAllowsChildren()) { throw new IllegalStateException("Node does not allow children"); } children.remove(index); }
public synchronized void insert(MutableTreeNode child) { insert(child, getChildCount()); }
AbstractIterationStrategyNode terminal = (AbstractIterationStrategyNode) iterationStrategies .getStrategies().get(0).getTerminalNode(); assertEquals(1, terminal.getChildCount()); assertTrue(terminal.getChildAt(0) instanceof CrossProduct); assertEquals(1, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertEquals("input_1", ((NamedInputPortNode) terminal .getChildAt(0).getChildAt(0)).getPortName()); } else if (processor.getLocalName().equals("processor_b")) { AbstractIterationStrategyNode terminal = (AbstractIterationStrategyNode) iterationStrategies .getStrategies().get(0).getTerminalNode(); assertEquals(1, terminal.getChildCount()); assertTrue(terminal.getChildAt(0) instanceof CrossProduct); assertEquals(2, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertTrue(terminal.getChildAt(0).getChildAt(1) instanceof NamedInputPortNode); assertEquals("input_2", ((NamedInputPortNode) terminal .getChildAt(0).getChildAt(0)).getPortName()); assertEquals("input_3", ((NamedInputPortNode) terminal .getChildAt(0).getChildAt(1)).getPortName());
public Object nextElement() { return getChildAt(currentPosition++); } };
private static Element elementForNode(AbstractIterationStrategyNode node) { Element nodeElement = null; if (node instanceof DotProduct) { nodeElement = new Element("dot"); } else if (node instanceof CrossProduct) { nodeElement = new Element("cross"); } else if (node instanceof PrefixDotProduct) { nodeElement = new Element("prefix"); } else if (node instanceof NamedInputPortNode) { NamedInputPortNode nipn = (NamedInputPortNode) node; nodeElement = new Element("port"); nodeElement.setAttribute("name", nipn.getPortName()); nodeElement.setAttribute("depth", nipn.getCardinality() + ""); } else { throw new IllegalArgumentException("Unknown node " + node); } Enumeration<?> children = node.children(); while (children.hasMoreElements()) { TreeNode tn = (TreeNode) children.nextElement(); nodeElement .addContent(elementForNode((AbstractIterationStrategyNode) tn)); } return nodeElement; }
@Override public synchronized void insert(MutableTreeNode child, int index) { if (getChildCount() > 0 && getChildAt(0) != child) { throw new IllegalStateException( "The terminal node can have maximum one child"); } super.insert(child, index); } }
/** * Implements IterationStrategyNode */ 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) { if (!parent.getChildren().contains(this)) { parent.insert(this); } } }
AbstractIterationStrategyNode terminal = (AbstractIterationStrategyNode) iterationStrategies .getStrategies().get(0).getTerminal(); assertEquals(1, terminal.getChildCount()); assertTrue(terminal.getChildAt(0) instanceof NamedInputPortNode); assertEquals("input_1", ((NamedInputPortNode) terminal .getChildAt(0)).getPortName()); } else if (processor.getLocalName().equals("processor_b")) { AbstractIterationStrategyNode terminal = (AbstractIterationStrategyNode) iterationStrategies .getStrategies().get(0).getTerminal(); assertEquals(1, terminal.getChildCount()); assertTrue(terminal.getChildAt(0) instanceof CrossProduct); assertEquals(2, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertTrue(terminal.getChildAt(0).getChildAt(1) instanceof NamedInputPortNode); assertEquals("input_2", ((NamedInputPortNode) terminal .getChildAt(0).getChildAt(0)).getPortName()); assertEquals("input_3", ((NamedInputPortNode) terminal .getChildAt(0).getChildAt(1)).getPortName());
public synchronized void insert(MutableTreeNode child) { insert(child, getChildCount()); }
private static Element elementForNode(AbstractIterationStrategyNode node) { Element nodeElement = null; if (node instanceof DotProduct) { nodeElement = new Element("dot", XMLSerializationConstants.T2_WORKFLOW_NAMESPACE); } else if (node instanceof CrossProduct) { nodeElement = new Element("cross", XMLSerializationConstants.T2_WORKFLOW_NAMESPACE); } else if (node instanceof PrefixDotProduct) { nodeElement = new Element("prefix", XMLSerializationConstants.T2_WORKFLOW_NAMESPACE); } else if (node instanceof NamedInputPortNode) { NamedInputPortNode nipn = (NamedInputPortNode) node; nodeElement = new Element("port", XMLSerializationConstants.T2_WORKFLOW_NAMESPACE); nodeElement.setAttribute("name", nipn.getPortName()); nodeElement.setAttribute("depth", nipn.getCardinality() + ""); } else { throw new IllegalArgumentException("Unknown node " + node); } Enumeration<?> children = node.children(); while (children.hasMoreElements()) { TreeNode tn = (TreeNode) children.nextElement(); nodeElement .addContent(elementForNode((AbstractIterationStrategyNode) tn)); } return nodeElement; }
@Override public synchronized void insert(MutableTreeNode child, int index) { if (getChildCount() > 0 && getChildAt(0) != child) { throw new IllegalStateException( "The terminal node can have maximum one child"); } super.insert(child, index); } }
/** * Implements IterationStrategyNode */ 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) { if (!parent.getChildren().contains(this)) { parent.insert(this); } } }
AbstractIterationStrategyNode terminal = (AbstractIterationStrategyNode) iterationStrategies .getStrategies().get(0).getTerminalNode(); assertEquals(1, terminal.getChildCount()); assertTrue(terminal.getChildAt(0) instanceof CrossProduct); assertEquals(1, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertEquals("input_1", ((NamedInputPortNode) terminal .getChildAt(0).getChildAt(0)).getPortName()); } else if (processor.getLocalName().equals("processor_b")) { AbstractIterationStrategyNode terminal = (AbstractIterationStrategyNode) iterationStrategies .getStrategies().get(0).getTerminalNode(); assertEquals(1, terminal.getChildCount()); assertTrue(terminal.getChildAt(0) instanceof CrossProduct); assertEquals(2, ((CrossProduct) terminal.getChildAt(0)) .getChildCount()); assertTrue(terminal.getChildAt(0).getChildAt(0) instanceof NamedInputPortNode); assertTrue(terminal.getChildAt(0).getChildAt(1) instanceof NamedInputPortNode); .getChildAt(0).getChildAt(0)).getPortName()); assertEquals("input_2", ((NamedInputPortNode) terminal .getChildAt(0).getChildAt(1)).getPortName());
/** * Configure from an XML element * * @param strategyElement */ protected void configureFromXML(Element strategyElement) { inputs.clear(); terminal.clear(); if (strategyElement.getChildren().isEmpty() == false) { nodeForElement((Element) strategyElement.getChildren().get(0)) .setParent(terminal); } }
private static Element elementForNode(AbstractIterationStrategyNode node) { Element nodeElement = null; if (node instanceof DotProduct) { nodeElement = new Element("dot", XMLSerializationConstants.T2_WORKFLOW_NAMESPACE); } else if (node instanceof CrossProduct) { nodeElement = new Element("cross", XMLSerializationConstants.T2_WORKFLOW_NAMESPACE); } else if (node instanceof PrefixDotProduct) { nodeElement = new Element("prefix", XMLSerializationConstants.T2_WORKFLOW_NAMESPACE); } else if (node instanceof NamedInputPortNode) { NamedInputPortNode nipn = (NamedInputPortNode) node; nodeElement = new Element("port", XMLSerializationConstants.T2_WORKFLOW_NAMESPACE); nodeElement.setAttribute("name", nipn.getPortName()); nodeElement.setAttribute("depth", nipn.getCardinality() + ""); } else { throw new IllegalArgumentException("Unknown node " + node); } Enumeration<?> children = node.children(); while (children.hasMoreElements()) { TreeNode tn = (TreeNode) children.nextElement(); nodeElement .addContent(elementForNode((AbstractIterationStrategyNode) tn)); } return nodeElement; }
public void remove(int index) { if (!getAllowsChildren()) { throw new IllegalStateException("Node does not allow children"); } children.remove(index); }
/** * Configure from an XML element * * @param strategyElement */ @SuppressWarnings("unchecked") protected void configureFromXML(Element strategyElement) { inputs.clear(); terminal.clear(); if (!strategyElement.getChildren().isEmpty()) { for (Element childElement : (List<Element>) strategyElement .getChildren()) { AbstractIterationStrategyNode node = nodeForElement(childElement); node.setParent(terminal); } } }
public synchronized void remove(MutableTreeNode node) { if (!getAllowsChildren()) { throw new IllegalStateException("Node does not allow children"); } children.remove(node); if (node.getParent() == this) { node.setParent(null); } }