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; }
public void useFormatter(Object key, MatchFormatter formatter) { if (formatter != null) { formatters.put(key, formatter); } else { formatters.remove(key); } // reformat matches names.refresh(); }