예제 #1
0
    @Override
    public FormattedFuture set(int index, FormattedFuture value) {
      FormattedFuture obsolete = get(index);

      source.set(index, value.getMatch().getValue());

      return obsolete;
    }
예제 #2
0
  public Map<File, String> getRenameMap() {
    Map<File, String> map = new LinkedHashMap<File, String>();

    for (int i = 0; i < names.size(); i++) {
      if (hasComplement(i)) {
        // make sure we're dealing with regular File objects form here on out
        File originalFile = new File(files().get(i).getPath());

        FormattedFuture formattedFuture = names.get(i);
        StringBuilder nameBuilder = new StringBuilder();

        // append formatted name, throw exception if not ready
        try {
          nameBuilder.append(formattedFuture.get(0, TimeUnit.SECONDS));
        } catch (ExecutionException e) {
          throw new IllegalStateException(
              String.format(
                  "\"%s\" could not be formatted: %s.",
                  formattedFuture.preview(), e.getCause().getMessage()));
        } catch (TimeoutException e) {
          throw new IllegalStateException(
              String.format("\"%s\" has not been formatted yet.", formattedFuture.preview()));
        } catch (InterruptedException e) {
          throw new RuntimeException(e);
        }

        // append extension, if desired
        if (preserveExtension) {
          String extension = FileUtilities.getExtension(originalFile);

          if (extension != null) {
            nameBuilder.append('.').append(extension.toLowerCase());
          }
        }

        // insert mapping
        if (map.put(originalFile, nameBuilder.toString()) != null) {
          throw new IllegalStateException(
              String.format("Duplicate file entry: \"%s\"", originalFile.getName()));
        }
      }
    }

    return map;
  }
예제 #3
0
    public void refresh() {
      updates.beginEvent(true);

      for (int i = 0; i < size(); i++) {
        FormattedFuture obsolete = futures.get(i);
        FormattedFuture future =
            new FormattedFuture(
                obsolete.getMatch(), getFormatter(obsolete.getMatch()), getMatchContext());

        // replace and cancel old future
        cancel(futures.set(i, future));

        // submit new future
        submit(future);

        updates.elementUpdated(i, obsolete, future);
      }

      updates.commitEvent();
    }
예제 #4
0
 private void cancel(FormattedFuture future) {
   // remove listener and cancel worker task
   future.removePropertyChangeListener(futureListener);
   future.cancel(true);
 }
예제 #5
0
 private void submit(FormattedFuture future) {
   // observe and enqueue worker task
   future.addPropertyChangeListener(futureListener);
   backgroundFormatter.execute(future);
 }
예제 #6
0
 @Override
 public void add(int index, FormattedFuture value) {
   source.add(index, value.getMatch().getValue());
 }