private void pushEvent(IterationInternalEvent<?> e) { if (stack == null) return; IterationStrategyImpl below = stack .layerBelow(IterationStrategyImpl.this); if (below == null) stack.receiveEventFromStrategy(e); else below.receiveEvent(e); }
@Override public IterationStrategyStack applyEdit() throws EditException { ((IterationStrategyStackImpl) iterationStrategyStack).clear(); return iterationStrategyStack; }
@Override protected void pushData(String portName, String owningProcess, int[] index, T2Reference data, InvocationContext context) { parent.iterationStack.receiveData(portName, owningProcess, index, data, context); }
/** * Fundamentally pointless, combining two cross product iteration strategies * is the same as using the last one directly but we can check this * * @throws IterationTypeMismatchException * @throws MissingIterationInputException */ public void testStagedCombinationOfCross() throws IterationTypeMismatchException, MissingIterationInputException { IterationStrategyStackImpl iss; iss = new IterationStrategyStackImpl(); iss.addStrategy(getISCross(1, 1)); iss.addStrategy(getISCross(0, 0)); assertTrue(iss.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 2, 2 })) == 4); }
/** * Test that attempting to typecheck a mismatched dot product produces a * type mismatch exception * */ public void testValidationFailureWithDot() { try { IterationStrategyImpl isi = getISDot(0, 0); isi.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 1, 2 })); fail("should have failed due to mismatch"); } catch (IterationTypeMismatchException itme) { // Correct behaviour, this should cause a mismatch } }
/** * Test simple iteration type check based on dot products * * @throws IterationTypeMismatchException */ public void testDotUnstagedIteration() throws IterationTypeMismatchException { IterationStrategyImpl isi = getISDot(0, 0); assertTrue(isi.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 1, 1 })) == 1); assertTrue(isi.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 2, 2 })) == 2); isi = getISDot(0, 1); assertTrue(isi.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 1, 2 })) == 1); }
/** * Test a simple iteration based on a cross product * * @throws IterationTypeMismatchException */ public void testCrossUnstagedIteration() throws IterationTypeMismatchException { IterationStrategyImpl isi = getISCross(0, 0); assertTrue(isi.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 1, 1 })) == 2); assertTrue(isi.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 2, 2 })) == 4); assertTrue(isi.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 1, 2 })) == 3); isi = getISCross(0, 1); assertTrue(isi.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 1, 2 })) == 2); }
@Override public IterationStrategy createIterationStrategy() { return new IterationStrategyImpl(); }
@Override public IterationStrategyStack applyEdit() { stack.addStrategy(strategy); return stack; }
@Override public IterationStrategy applyEdit() throws EditException { strategy.addInput(namedInputPortNode); return strategy; }
@Override public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { if (getChildCount() == 0) return -1; return getChildAt(0).getIterationDepth(inputDepths); } }
@Override public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { return getTerminalNode().getIterationDepth(inputDepths); }
@Override protected void doEditAction(ProcessorImpl processor) throws EditException { if (processor.getInputPortWithName(port.getName()) == null) throw new EditException("The processor doesn't have a port named:" + port.getName()); for (IterationStrategyImpl is : processor.iterationStack .getStrategies()) is.removeInputByName(port.getName()); processor.inputPorts.remove(port); } };
@Override public void receiveCompletion(int inputIndex, Completion completion) { pushEvent(unwrap(completion)); }
@Override protected void pushCompletion(String portName, String owningProcess, int[] index, InvocationContext context) { parent.iterationStack.receiveCompletion(portName, owningProcess, index, context); }
public void receiveCompletion(String inputPortName, String owningProcess, int[] completionArray, InvocationContext context) { if (!strategies.isEmpty()) strategies.get(0).receiveCompletion(inputPortName, owningProcess, completionArray, context); }
public void receiveData(String inputPortName, String owningProcess, int[] indexArray, T2Reference dataReference, InvocationContext context) { if (!strategies.isEmpty()) strategies.get(0).receiveData(inputPortName, owningProcess, indexArray, dataReference, context); }
/** * Test whether Paul's example of iterating with dot product then cross * product can typecheck in a single staged iteration. This was an example * where the user had two lists of folders (a1, a2, b1, b2, c1, c2) and * wanted to compare all the contents of each 'a' folder with the other 'a' * folder and so on, doing a dot match to only compare a1 and a2 then a * cross product join within each pair to compare all contents of a1 with * all contents of a2. This appears to work! */ public void testStagedCombinationOfDotAndCross() throws IterationTypeMismatchException, MissingIterationInputException { IterationStrategyStackImpl iss; iss = new IterationStrategyStackImpl(); iss.addStrategy(getISDot(1, 1)); iss.addStrategy(getISCross(0, 0)); assertTrue(iss.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 2, 2 })) == 3); }
@Override public void receiveJob(int inputIndex, Job newJob) { pushEvent(unwrap(newJob)); }
IterationStrategyStackImpl iss; iss = new IterationStrategyStackImpl(); iss.addStrategy(getISDot(1, 1)); iss.addStrategy(getISDot(0, 0)); assertTrue(iss.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 2, 2 })) == 2); assertTrue(iss.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 0, 0 })) == 1); assertTrue(iss.getIterationDepth(getDepths(new String[] { "a", "b" }, new int[] { 1, 0 })) == 1);