public TimeLagGraphWrapper(GraphWrapper graphWrapper) {
    if (graphWrapper == null) {
      throw new NullPointerException("No graph wrapper.");
    }

    TimeLagGraph graph = new TimeLagGraph();

    Graph _graph = graphWrapper.getGraph();

    for (Node node : _graph.getNodes()) {
      Node _node = node.like(node.getName() + ":0");
      _node.setNodeType(node.getNodeType());
      graph.addNode(_node);
    }

    for (Edge edge : _graph.getEdges()) {
      if (!Edges.isDirectedEdge(edge)) {
        throw new IllegalArgumentException();
      }

      Node from = edge.getNode1();
      Node to = edge.getNode2();

      Node _from = graph.getNode(from.getName(), 1);
      Node _to = graph.getNode(to.getName(), 0);

      graph.addDirectedEdge(_from, _to);
    }

    this.graph = graph;
  }
Exemple #2
0
  public boolean setMaxLag(int maxLag) {
    if (maxLag < 0) {
      throw new IllegalArgumentException("Max lag must be at least 0: " + maxLag);
    }

    List<Node> lag0Nodes = getLag0Nodes();

    boolean changed = false;

    if (maxLag > this.getMaxLag()) {
      this.maxLag = maxLag;
      for (Node node : lag0Nodes) {
        addNode(node);
      }

      for (Node node : lag0Nodes) {
        List<Edge> edges = getGraph().getEdges(node);

        for (Edge edge : edges) {
          boolean b = addEdge(edge);
          changed = changed || b;
        }
      }
    } else if (maxLag < this.getMaxLag()) {
      for (Node node : lag0Nodes) {
        List<Edge> edges = getGraph().getEdges(node);

        for (Edge edge : edges) {
          Node tail = Edges.getDirectedEdgeTail(edge);

          if (getNodeId(tail).getLag() > maxLag) {
            getGraph().removeEdge(edge);
            //                        throw new IllegalArgumentException("This edge has lag greater
            // than the new maxLag: " + edge +
            //                                " Please remove first.");
          }
        }
      }

      for (Node _node : getNodes()) {
        if (getNodeId(_node).getLag() > maxLag) {
          boolean b = getGraph().removeNode(_node);
          changed = changed || b;
        }
      }

      this.maxLag = maxLag;
    }

    getPcs().firePropertyChange("editingFinished", null, null);

    return changed;
  }