Ejemplo n.º 1
0
  public String getGraphCommands() {
    String commands = "";

    for (Node aNode : nodeList) {
      commands += ("node " + aNode.getName() + "\n");
    }

    for (DirectedArc dirArc : dirArcList) {
      commands +=
          ("dir-arc "
              + dirArc.getParent().getName()
              + " "
              + dirArc.getChild().getName()
              + " "
              + dirArc.getRelation()
              + "\n");
    }

    for (UndirectedArc undirArc : undirArcList) {
      Node[] nodes = undirArc.getNodes();
      commands +=
          ("undir-arc "
              + nodes[0].getName()
              + " "
              + nodes[1].getName()
              + " "
              + undirArc.getRelation()
              + "\n");
    }

    return commands;
  }
Ejemplo n.º 2
0
 /**
  * Tests whether a directed arc exists between two nodes in the graph
  *
  * @param parent parent node
  * @param child child node
  * @return true if arc exists
  */
 public boolean dirArcExists(Node parent, Node child) {
   for (DirectedArc dirArc : dirArcList) {
     if (dirArc.getParent().equals(parent) && dirArc.getChild().equals(child)) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 3
0
 /**
  * Gets directed arc between two nodes in the graph
  *
  * @param parent parent node
  * @param child child node
  * @return Directed arc between nodes if arc exists
  * @throws Exception if arc does not exist
  */
 public DirectedArc getDirArc(Node parent, Node child) throws Exception {
   for (DirectedArc dirArc : dirArcList) {
     if (dirArc.getParent().equals(parent) && dirArc.getChild().equals(child)) {
       return dirArc;
     }
   }
   throw new Exception("Directed arc does not exist between the two nodes");
 }