@Test public void shouldVisitModelTopDownDepthFirst() { final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("process") .startEvent("start-1-1") .subProcess("sub-1-2") .embeddedSubProcess() .startEvent("start-2-1") .subProcessDone() .subProcess("sub-1-3") .embeddedSubProcess() .startEvent("start-3-1") .subProcessDone() .endEvent("end-1-4") .done(); final List<BpmnModelElementInstance> visitedElements = new ArrayList<>(); final ModelWalker walker = new ModelWalker(modelInstance); walker.walk(visitedElements::add); final List<BaseElement> visitedBaseElements = visitedElements.stream() .filter(e -> e instanceof BaseElement) .map(e -> (BaseElement) e) .collect(Collectors.toList()); final List<String> subprocessVisitingOrder = visitedBaseElements.stream() .filter(e -> e instanceof SubProcess) .map(e -> e.getId()) .collect(Collectors.toList()); assertThat(subprocessVisitingOrder).hasSize(2); final String firstSubprocess = subprocessVisitingOrder.get(0); final String secondSubprocess = subprocessVisitingOrder.get(1); final String firstSubprocessStart = "sub-1-2".equals(firstSubprocess) ? "start-2-1" : "start-3-1"; final String secondSubprocessStart = "sub-1-2".equals(secondSubprocess) ? "start-2-1" : "start-3-1"; assertThat(visitedBaseElements) .extracting(e -> e.getId()) .containsSubsequence("process", "start-1-1") .containsSubsequence("process", "sub-1-2") .containsSubsequence("process", "sub-1-3") .containsSubsequence("process", "end-1-4") .containsSubsequence(firstSubprocess, secondSubprocess) .containsSubsequence(firstSubprocess, firstSubprocessStart) .containsSubsequence(secondSubprocess, secondSubprocessStart) .containsSubsequence(firstSubprocessStart, secondSubprocessStart); }
public void walk(final ModelElementVisitor visitor) { final Definitions rootElement = modelInstance.getDefinitions(); elementsToVisit.add(rootElement); BpmnModelElementInstance currentElement; while ((currentElement = elementsToVisit.poll()) != null) { visitor.visit(currentElement); final Collection<BpmnModelElementInstance> children = getChildElements(currentElement); children.forEach(c -> elementsToVisit.addFirst(c)); } }
ModelWalker { public void walk(final ModelElementVisitor visitor) { final Definitions rootElement = modelInstance.getDefinitions(); elementsToVisit.add(rootElement); BpmnModelElementInstance currentElement; while ((currentElement = elementsToVisit.poll()) != null) { visitor.visit(currentElement); final Collection<BpmnModelElementInstance> children = getChildElements(currentElement); children.forEach(c -> elementsToVisit.addFirst(c)); } } }
ModelWalker { public void walk(final ModelElementVisitor visitor) { final Definitions rootElement = modelInstance.getDefinitions(); elementsToVisit.add(rootElement); BpmnModelElementInstance currentElement; while ((currentElement = elementsToVisit.poll()) != null) { visitor.visit(currentElement); final Collection<BpmnModelElementInstance> children = getChildElements(currentElement); children.forEach(c -> elementsToVisit.addFirst(c)); } } ModelWalker(final BpmnModelInstance modelInstance); }
ModelWalker { public void walk(final ModelElementVisitor visitor) { final Definitions rootElement = modelInstance.getDefinitions(); elementsToVisit.add(rootElement); BpmnModelElementInstance currentElement; while ((currentElement = elementsToVisit.poll()) != null) { visitor.visit(currentElement); final Collection<BpmnModelElementInstance> children = getChildElements(currentElement); children.forEach(c -> elementsToVisit.addFirst(c)); } } ModelWalker(final BpmnModelInstance modelInstance); void walk(final ModelElementVisitor visitor); }
ModelWalker { public void walk(final ModelElementVisitor visitor) { final Definitions rootElement = modelInstance.getDefinitions(); elementsToVisit.add(rootElement); BpmnModelElementInstance currentElement; while ((currentElement = elementsToVisit.poll()) != null) { visitor.visit(currentElement); final Collection<BpmnModelElementInstance> children = getChildElements(currentElement); children.forEach(c -> elementsToVisit.addFirst(c)); } } ModelWalker(final BpmnModelInstance modelInstance); void walk(final ModelElementVisitor visitor);  }