示例#1
0
 public void addTask(int id, String name, int time, int staff, int[] dependencies) {
   Task tmp = new Task(id, this);
   if (!tasks.contains(tmp)) {
     addTask(tmp);
   } else {
     tmp = getTask(tmp);
   }
   tmp.setParameters(name, time, staff, dependencies);
 }
示例#2
0
  public static void readFromFile(File inFile, Project project) {
    Scanner sc = null;
    try {
      sc = new Scanner(inFile);
    } catch (java.io.FileNotFoundException e) {
      System.out.println("File not found, quitting");
      System.exit(1);
    }
    if (sc.hasNext()) {
      num_tasks = Integer.parseInt(sc.next());
      System.out.println("Number of tasks: " + Integer.toString(num_tasks));
    }

    int counter = 1;

    while (sc.hasNextLine()) {
      ArrayList<String> tmp_string_arr = new ArrayList<>();
      for (String s : sc.nextLine().split("\\s")) tmp_string_arr.add(s);

      while (tmp_string_arr.remove("")) ;
      while (tmp_string_arr.remove(" ")) ;

      for (String s : tmp_string_arr) System.out.print(s + ",");
      System.out.println("");

      String[] tmp_string = {};
      tmp_string = tmp_string_arr.toArray(tmp_string);

      int id = -1;

      try {
        id = Integer.parseInt(tmp_string[0]);
      } catch (java.lang.NumberFormatException e) {
        id = -1; // Will not make new task
      } catch (java.lang.ArrayIndexOutOfBoundsException e) {
        id = -1;
      }

      if (id == counter) {
        String name = tmp_string[1];
        int time = Integer.parseInt(tmp_string[2]);
        int staff = Integer.parseInt(tmp_string[3]);
        int[] dependencies = new int[tmp_string.length - 5];
        for (int i = 4; i < tmp_string.length - 1; i++)
          dependencies[i - 4] = Integer.parseInt(tmp_string[i]);
        project.addTask(id, name, time, staff, dependencies);
        System.out.println("Created new task");
        counter++;
      }
    }
  }
示例#3
0
 public void setParameters(String name, int time, int staff, int[] dependencies) {
   this.name = name;
   this.time = time;
   this.staff = staff;
   for (int id : dependencies) {
     if (project.tasks.contains(new Task(id, project)) && (id != -1)) {
       Task tmp_t = project.getTask(new Task(id, project));
       Edge tmp_e = new Edge(tmp_t, this);
       project.addEdge(tmp_e);
       tmp_t.addEdge(tmp_e);
     } else {
       Task tmp_t = new Task(id, project);
       project.addTask(tmp_t);
       Edge tmp_e = new Edge(tmp_t, this);
       tmp_t.addEdge(tmp_e);
       project.addEdge(tmp_e);
     }
   }
 }