Exemplo n.º 1
0
  /**
   * 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");
      }
    }
  }
Exemplo n.º 2
0
  /**
   * 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());
    }
  }