Beispiel #1
0
  public void testEdgeListWithStringsDirectedUnweightedWithSemicolon() throws ImportException {
    DirectedPseudograph<String, DefaultEdge> g =
        new DirectedPseudograph<>(DefaultWeightedEdge.class);
    g.addVertex("'john doe'");
    g.addVertex("fred");
    g.addVertex("fred\n\"21\"");
    g.addVertex("who;;");
    g.addEdge("'john doe'", "fred");
    g.addEdge("fred", "fred\n\"21\"");
    g.addEdge("fred\n\"21\"", "who;;");
    g.addEdge("who;;", "'john doe'");

    CSVExporter<String, DefaultEdge> exporter =
        new CSVExporter<>(stringNameProvider, CSVFormat.EDGE_LIST, ';');
    StringWriter w = new StringWriter();
    exporter.exportGraph(g, w);
    assertEquals(DIRECTED_EDGE_LIST_ESCAPE, w.toString());
  }
  private static void checkIsDAG(List<QueryQueueRule> rules) {
    DirectedPseudograph<String, DefaultEdge> graph = new DirectedPseudograph<>(DefaultEdge.class);
    for (QueryQueueRule rule : rules) {
      String lastQueueName = null;
      for (QueryQueueDefinition queue : rule.getQueues()) {
        String currentQueueName = queue.getTemplate();
        graph.addVertex(currentQueueName);
        if (lastQueueName != null) {
          graph.addEdge(lastQueueName, currentQueueName);
        }
        lastQueueName = currentQueueName;
      }
    }

    List<String> shortestCycle = shortestCycle(graph);

    if (shortestCycle != null) {
      String s = Joiner.on(", ").join(shortestCycle);
      throw new IllegalArgumentException(
          format("Queues must not contain a cycle. The shortest cycle found is [%s]", s));
    }
  }