コード例 #1
0
ファイル: Graph.java プロジェクト: sormaz/implanner-fx
  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;
  }
コード例 #2
0
ファイル: Graph.java プロジェクト: sormaz/implanner-fx
 /**
  * Tests whether an undirected arc exists between two nodes in the graph
  *
  * @param node1 graph node
  * @param node2 graph node
  * @return true if arc exists
  */
 public boolean undirArcExists(Node node1, Node node2) {
   for (UndirectedArc undirArc : undirArcList) {
     if (undirArc.nodeExists(node1) && undirArc.nodeExists(node2)) {
       return true;
     }
   }
   return false;
 }
コード例 #3
0
ファイル: Graph.java プロジェクト: sormaz/implanner-fx
 /**
  * Gets undirected arc between two nodes in the graph
  *
  * @param node1 graph node
  * @param node2 graph node
  * @return Undirected arc between nodes if arc exists
  * @throws Exception if arc does not exist
  */
 public UndirectedArc getUndirArc(Node node1, Node node2) throws Exception {
   for (UndirectedArc undirArc : undirArcList) {
     if (undirArc.nodeExists(node1) && undirArc.nodeExists(node2)) {
       return undirArc;
     }
   }
   throw new Exception("Undirected arc does not exist between the nodes");
 }
コード例 #4
0
ファイル: Graph.java プロジェクト: sormaz/implanner-fx
  /**
   * Executes the "Printout" command
   *
   * @param commandList the command along with the necessary parameters specified by the user
   */
  public void executePrintout(ArrayList<String> commandList) throws Exception {
    if (commandList.size() != 2 && commandList.size() != 3) {
      throw new Exception(
          "\nInvalid arguments, code not executed"
              + "\nCorrect Syntax: \nprintout node_name"
              + "\nprintout node1_name node2_name\n");
    }

    if (commandList.size() == 2) {
      Node node = getNode(commandList.get(1));

      System.out.println(node.toString());

      // Also printout all the arcs the node is connected to
      // I kept it because it helped in debugging
      for (UndirectedArc undirArc : node.getArcs()) {
        System.out.println(undirArc.toString());
      }
      for (DirectedArc dirArc : node.getInArcs()) {
        System.out.println(dirArc.toString());
      }
      for (DirectedArc dirArc : node.getOutArcs()) {
        System.out.println(dirArc.toString());
      }

    } else {
      Node node1 = getNode(commandList.get(1));
      Node node2 = getNode(commandList.get(2));
      Boolean arcExists = false;

      try {
        System.out.println(getDirArc(node1, node2).toString());
        arcExists = true;
      } catch (Exception e) {

      }
      try {
        System.out.println(getDirArc(node2, node1).toString());
        arcExists = true;
      } catch (Exception e) {

      }
      try {
        System.out.println(getUndirArc(node1, node2).toString());
        arcExists = true;
      } catch (Exception e) {

      }

      if (!arcExists) {
        System.out.println("No arcs exist between node");
      }
    }
  }
コード例 #5
0
ファイル: Graph.java プロジェクト: sormaz/implanner-fx
  /**
   * Executes the "Arcs" command
   *
   * @param commandList the command along with the necessary parameters specified by the user
   */
  public void executeArcs(ArrayList<String> commandList) throws Exception {
    if (commandList.size() != 1) {
      throw new Exception("\nInvalid arguments, code not executed" + "\nCorrect Syntax: \narcs\n");
    }

    HashSet<DirectedArc> dirArcList = getDirectedArcs();
    HashSet<UndirectedArc> undirArcList = getUndirectedArcs();

    for (DirectedArc dirArc : dirArcList) {
      System.out.println(dirArc.toString());
    }

    for (UndirectedArc undirArc : undirArcList) {
      System.out.println(undirArc.toString());
    }
  }
コード例 #6
0
ファイル: Graph.java プロジェクト: sormaz/implanner-fx
 /**
  * Removes an undirected arc from the graph
  *
  * @param arc undirected arc
  */
 public void removeArc(UndirectedArc arc) {
   undirArcList.remove(arc);
   arc.clear();
   notifyArcDeletion(arc);
 }