@Test public void uniqueName_returns_new_name_if_taken_file_starts_with_dot() { final File file = new File(".ignore"); Assert.assertEquals(".ignore_2", FileUtil.uniqueName(file, CollectionUtils.asSet(".ignore", ".ignore_1"))); }
public static String uniqueName(File source, Set<String> taken) { String name = source.getName(); for (int i = 1; taken.contains(name); i++) { name = getFileNameWithoutExtention(source) + "_" + i; final String extension = getFileExtension(source); if (!extension.isEmpty()) { name += "." + extension; } } return name; }
FileUtil { public static String uniqueName(File source, Set<String> taken) { String name = source.getName(); for (int i = 1; taken.contains(name); i++) { name = getFileNameWithoutExtention(source) + "_" + i; final String extension = getFileExtension(source); if (!extension.isEmpty()) { name += "." + extension; } } return name; } }
FileUtil { public static String uniqueName(File source, Set<String> taken) { String name = source.getName(); for (int i = 1; taken.contains(name); i++) { name = getFileNameWithoutExtention(source) + "_" + i; final String extension = getFileExtension(source); if (!extension.isEmpty()) { name += "." + extension; } } return name; } private  FileUtil(); }
FileUtil { public static String uniqueName(File source, Set<String> taken) { String name = source.getName(); for (int i = 1; taken.contains(name); i++) { name = getFileNameWithoutExtention(source) + "_" + i; final String extension = getFileExtension(source); if (!extension.isEmpty()) { name += "." + extension; } } return name; } private  FileUtil(); static void write(String text, File target); static Uri getUri(Context context, String authority, File file); static void saveBitmap(Bitmap bitmap, File targetFile, int quality); static void saveBitmap(Bitmap bitmap, File targetFile, Bitmap.CompressFormat format, int quality); static void zip(List<File> sources, File target); static List<File> walk(File source); static List<File> walk(List<File> sources); static String uniqueName(File source, Set<String> taken); static String getFileExtension(File file); static String getFileNameWithoutExtention(File file); }
FileUtil { public static String uniqueName(File source, Set<String> taken) { String name = source.getName(); for (int i = 1; taken.contains(name); i++) { name = getFileNameWithoutExtention(source) + "_" + i; final String extension = getFileExtension(source); if (!extension.isEmpty()) { name += "." + extension; } } return name; } private  FileUtil(); static void write(String text, File target); static Uri getUri(Context context, String authority, File file); static void saveBitmap(Bitmap bitmap, File targetFile, int quality); static void saveBitmap(Bitmap bitmap, File targetFile, Bitmap.CompressFormat format, int quality); static void zip(List<File> sources, File target); static List<File> walk(File source); static List<File> walk(List<File> sources); static String uniqueName(File source, Set<String> taken); static String getFileExtension(File file); static String getFileNameWithoutExtention(File file);  }