private void configureContext(Context context) { Set<Model> models = AnnotationUtils.getAnnotations(context.getClass(), Model.class); GraphWalker annotation = context.getClass().getAnnotation(GraphWalker.class); if (!models.isEmpty()) { Path path = Paths.get(models.iterator().next().file()); ContextFactoryScanner.get(reflections, path).create(path, context); } if (!"".equals(annotation.value())) { context.setPathGenerator(GeneratorFactory.parse(annotation.value())); } else { context.setPathGenerator(PathGeneratorFactory.createPathGenerator(annotation)); } if (!"".equals(annotation.start())) { context.setNextElement(getElement(context.getModel(), annotation.start())); } }
private List<Element> createConnectedComponent( Map<Element, ElementStatus> elementStatusMap, Element root) { List<Element> connectedComponent = new ArrayList<>(); Deque<Element> stack = new ArrayDeque<>(); stack.push(root); while (!stack.isEmpty()) { Element element = stack.pop(); if (ElementStatus.UNREACHABLE.equals(elementStatusMap.get(element))) { connectedComponent.add(element); elementStatusMap.put(element, ElementStatus.REACHABLE); if (element instanceof RuntimeVertex) { RuntimeVertex vertex = (RuntimeVertex) element; for (RuntimeEdge edge : context.getModel().getOutEdges(vertex)) { stack.push(edge); } } else if (element instanceof RuntimeEdge) { RuntimeEdge edge = (RuntimeEdge) element; stack.push(edge.getTargetVertex()); } } } return Collections.unmodifiableList(connectedComponent); }
public List<Element> getConnectedComponent(Element root) { return createConnectedComponent(createElementStatusMap(context.getModel().getElements()), root); }