@Test public void getExistingBackupFiles() throws IOException { File first = folder.newFile("1.log"); File second = folder.newFile("42.log"); folder.newFile("1.log.backup"); folder.newFile("42.log.backup"); folder.newFile("42.old.backup"); String pattern = new File(folder.getRoot(), "{pid}.log").getAbsolutePath(); DynamicPath path = new DynamicPath(pattern); assertThat(path.getAllFiles(".backup")) .extracting(FileTuple::getOriginal) .containsExactlyInAnyOrder(first, second); }
public List<FileTuple> getAllFiles(final String backupSuffix) { List<FileTuple> tuples = new ArrayList<FileTuple>(); Collection<File> originals = backupSuffix == null ? new ArrayList<File>() : new HashSet<File>(); collectFiles(folder, suffix, originals); if (backupSuffix != null) { Collection<File> backups = new ArrayList<File>(); collectFiles(folder, suffix + backupSuffix, backups); for (File backup : backups) { String path = backup.getAbsolutePath(); File original = new File(path.substring(0, path.length() - backupSuffix.length())); tuples.add(new FileTuple(original, backup)); originals.remove(original); } } for (File original : originals) { String path = original.getAbsolutePath(); File backup = new File(backupSuffix == null ? path : path + backupSuffix); tuples.add(new FileTuple(original, backup)); } Collections.sort(tuples, LastModifiedFileTupleComparator.INSTANCE); return tuples; }
DynamicPath { public List<FileTuple> getAllFiles(final String backupSuffix) { List<FileTuple> tuples = new ArrayList<FileTuple>(); Collection<File> originals = backupSuffix == null ? new ArrayList<File>() : new HashSet<File>(); collectFiles(folder, suffix, originals); if (backupSuffix != null) { Collection<File> backups = new ArrayList<File>(); collectFiles(folder, suffix + backupSuffix, backups); for (File backup : backups) { String path = backup.getAbsolutePath(); File original = new File(path.substring(0, path.length() - backupSuffix.length())); tuples.add(new FileTuple(original, backup)); originals.remove(original); } } for (File original : originals) { String path = original.getAbsolutePath(); File backup = new File(backupSuffix == null ? path : path + backupSuffix); tuples.add(new FileTuple(original, backup)); } Collections.sort(tuples, LastModifiedFileTupleComparator.INSTANCE); return tuples; } }
DynamicPath { public List<FileTuple> getAllFiles(final String backupSuffix) { List<FileTuple> tuples = new ArrayList<FileTuple>(); Collection<File> originals = backupSuffix == null ? new ArrayList<File>() : new HashSet<File>(); collectFiles(folder, suffix, originals); if (backupSuffix != null) { Collection<File> backups = new ArrayList<File>(); collectFiles(folder, suffix + backupSuffix, backups); for (File backup : backups) { String path = backup.getAbsolutePath(); File original = new File(path.substring(0, path.length() - backupSuffix.length())); tuples.add(new FileTuple(original, backup)); originals.remove(original); } } for (File original : originals) { String path = original.getAbsolutePath(); File backup = new File(backupSuffix == null ? path : path + backupSuffix); tuples.add(new FileTuple(original, backup)); } Collections.sort(tuples, LastModifiedFileTupleComparator.INSTANCE); return tuples; } DynamicPath(final String path); }
DynamicPath { public List<FileTuple> getAllFiles(final String backupSuffix) { List<FileTuple> tuples = new ArrayList<FileTuple>(); Collection<File> originals = backupSuffix == null ? new ArrayList<File>() : new HashSet<File>(); collectFiles(folder, suffix, originals); if (backupSuffix != null) { Collection<File> backups = new ArrayList<File>(); collectFiles(folder, suffix + backupSuffix, backups); for (File backup : backups) { String path = backup.getAbsolutePath(); File original = new File(path.substring(0, path.length() - backupSuffix.length())); tuples.add(new FileTuple(original, backup)); originals.remove(original); } } for (File original : originals) { String path = original.getAbsolutePath(); File backup = new File(backupSuffix == null ? path : path + backupSuffix); tuples.add(new FileTuple(original, backup)); } Collections.sort(tuples, LastModifiedFileTupleComparator.INSTANCE); return tuples; } DynamicPath(final String path); String resolve(); List<FileTuple> getAllFiles(final String backupSuffix); boolean isValid(final File file); }
DynamicPath { public List<FileTuple> getAllFiles(final String backupSuffix) { List<FileTuple> tuples = new ArrayList<FileTuple>(); Collection<File> originals = backupSuffix == null ? new ArrayList<File>() : new HashSet<File>(); collectFiles(folder, suffix, originals); if (backupSuffix != null) { Collection<File> backups = new ArrayList<File>(); collectFiles(folder, suffix + backupSuffix, backups); for (File backup : backups) { String path = backup.getAbsolutePath(); File original = new File(path.substring(0, path.length() - backupSuffix.length())); tuples.add(new FileTuple(original, backup)); originals.remove(original); } } for (File original : originals) { String path = original.getAbsolutePath(); File backup = new File(backupSuffix == null ? path : path + backupSuffix); tuples.add(new FileTuple(original, backup)); } Collections.sort(tuples, LastModifiedFileTupleComparator.INSTANCE); return tuples; } DynamicPath(final String path); String resolve(); List<FileTuple> getAllFiles(final String backupSuffix); boolean isValid(final File file);  }