/*
   * The subroutine of DFS. NOTE: the set is used to distinguish between 1st
   * and 2nd round of DFS. set == null: finished vertices are stored (1st
   * round). set != null: all vertices found will be saved in the set (2nd
   * round)
   */
  private void dfsVisit(
      DirectedGraph<V, E> visitedGraph, VertexData<V> vertexData, Set<V> vertices) {
    Deque<VertexData<V>> stack = new ArrayDeque<VertexData<V>>();
    stack.add(vertexData);

    while (!stack.isEmpty()) {
      VertexData<V> data = stack.removeLast();

      if (!data.isDiscovered()) {
        data.setDiscovered(true);

        if (vertices != null) {
          vertices.add(data.getVertex());
        }

        stack.add(new VertexData1<V>(data, true, true));

        // follow all edges
        for (E edge : visitedGraph.outgoingEdgesOf(data.getVertex())) {
          VertexData<V> targetData = vertexToVertexData.get(visitedGraph.getEdgeTarget(edge));

          if (!targetData.isDiscovered()) {
            // the "recursion"
            stack.add(targetData);
          }
        }
      } else if (data.isFinished()) {
        if (vertices == null) {
          orderedVertices.addFirst(data.getFinishedData());
        }
      }
    }
  }
  private boolean isPrimaryKey(
      DirectedGraph<IStructureElement, DefaultEdge> schema, ISqlElement column) {
    Set<DefaultEdge> outgoingEdges = schema.outgoingEdgesOf(column);

    for (DefaultEdge outgoingEdge : outgoingEdges) {
      IStructureElement element = schema.getEdgeTarget(outgoingEdge);

      if (element instanceof ColumnConstraintVertex
          && ((ColumnConstraintVertex) element)
              .getConstraintType()
              .equals(ConstraintType.PRIMARY_KEY)) {
        return true;
      }
    }

    return false;
  }
Exemplo n.º 3
0
  public static <V, E> void write(DirectedGraph<V, E> g, String fileName, EdgeFilter<E> filter)
      throws FileNotFoundException {
    PrintWriter out = new PrintWriter(fileName);

    // System.out.println("Writing '" + fileName + "'");

    out.print("digraph \"DirectedGraph\" { \n graph [label=\"");
    out.print(g.toString());
    out.print("\", labelloc=t, concentrate=true]; ");
    out.print("center=true;fontsize=12;node [fontsize=12];edge [fontsize=12]; \n");

    for (V node : g.vertexSet()) {
      out.print("   \"");
      out.print(getId(node));
      out.print("\" ");
      out.print("[label=\"");
      out.print(node.toString());
      out.print("\" shape=\"box\" color=\"blue\" ] \n");
    }

    for (V src : g.vertexSet()) {
      for (E e : g.outgoingEdgesOf(src)) {
        if (!filter.accept(e)) {
          continue;
        }

        V tgt = g.getEdgeTarget(e);

        out.print(" \"");
        out.print(getId(src));
        out.print("\" -> \"");
        out.print(getId(tgt));
        out.print("\" ");
        out.print("[label=\"");
        out.print(e.toString());
        out.print("\"]\n");
      }
    }

    out.print("\n}");

    out.flush();
    out.close();
  }
Exemplo n.º 4
0
 public Set<TableToTableReference> referredToBy(Table table) {
   checkNotNull(table, "table must not be null");
   return graph.outgoingEdgesOf(table);
 }
Exemplo n.º 5
0
 /** @see CrossComponentIterator.Specifics#edgesOf(Object) */
 public Set<? extends EE> edgesOf(VV vertex) {
   return graph.outgoingEdgesOf(vertex);
 }