File (@NotNull File parentFolder, @NotNull String filePrefix, @NotNull String extension, @NotNull Predicate<? super File> condition) { int postfix = 0; String ext = extension.isEmpty() ? "" : '.' + extension; File candidate = new File(parentFolder, filePrefix + ext); while (!condition.test(candidate)) { postfix++; candidate = new File(parentFolder, filePrefix + postfix + ext); } return candidate; }