/**
   * Finds the multichunks that need to be downloaded to apply the given file system actions. The
   * method looks at all {@link FileCreatingFileSystemAction}s and returns their multichunks.
   */
  private Set<MultiChunkId> determineRequiredMultiChunks(
      List<FileSystemAction> actions, MemoryDatabase winnersDatabase) {
    Set<MultiChunkId> multiChunksToDownload = new HashSet<MultiChunkId>();

    for (FileSystemAction action : actions) {
      if (action
          instanceof
          FileCreatingFileSystemAction) { // TODO [low] This adds ALL multichunks even though some
                                          // might be available locally
        multiChunksToDownload.addAll(
            determineMultiChunksToDownload(action.getFile2(), winnersDatabase));
      }
    }

    return multiChunksToDownload;
  }
  private String[] toArray(List<FileSystemAction> actions) {
    String[] actionStrArr = new String[actions.size()];

    for (int i = 0; i < actions.size(); i++) {
      FileSystemAction action = actions.get(i);

      actionStrArr[i] =
          action.getClass().getSimpleName()
              + ","
              + actions.get(i).getFile2().getPath()
              + ","
              + actions.get(i).getType();

      System.out.println("actual[" + i + "]: " + actionStrArr[i]);
    }

    return actionStrArr;
  }
  /**
   * Applies the given file system actions in a sensible order. To do that, the given actions are
   * first sorted using the {@link FileSystemActionComparator} and then executed individually using
   * {@link FileSystemAction#execute()}.
   */
  private void applyFileSystemActions(List<FileSystemAction> actions) throws Exception {
    // Sort
    FileSystemActionComparator actionComparator = new FileSystemActionComparator();
    actionComparator.sort(actions);

    logger.log(Level.FINER, "- Applying file system actions (sorted!) ...");

    // Apply
    for (FileSystemAction action : actions) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER, "   +  {0}", action);
      }

      // Execute the file system action

      // Note that exceptions are not caught here, to prevent
      // apply-failed-delete-on-up situations.

      action.execute();
    }
  }