My problem comes down to this: I need to sort files in a specific order (the files got numbers at the beginning). Later I want to store them externally, the files are then sorted by alphabet by the system they're on, I got no influence on that process. So how could I rename them to make them stay in the correct order?
// this comparator sorts them by alphabetical order
Comparator<Mp3File> compAlphabetical = (x,y) -> getMp3TitleFromFilename(x).compareTo(getMp3TitleFromFilename(y));
//and this one does by number
//the inputs look like this "582 Some File Name" so they have to be edited with some regex before using them for sorting
Comparator<Mp3File> compNumeric = new Comparator<Mp3File>() {
@Override
public int compare(Mp3File o1, Mp3File o2) {
Integer i1 = Integer.parseInt(getMp3TitleFromFilename(o1).substring(0,3).replaceAll("[^0-9]", ""));
Integer i2 = Integer.parseInt(getMp3TitleFromFilename(o2).substring(0,3).replaceAll("[^0-9]", ""));
return i1.compareTo(i2);
}
};
What I want to achieve is a method which gets the list with the correct sorting (2nd) comparator and renames the files so they would maintain their order, even if I would run the first Comparator on the list.
Right now the sorting by alphabet puts out partly correct orders. It looks like this:
- 1 One File Name
- 10 Another File Name
- 100 A Good File Name
- 101 An Even Better File Name
- 102 Another File
- 103 A really good File Name
But this isn't really what I want so I thought about putting some letters at the beginning like this:
- AAA One File
- AAB Another File
- AAC And
- AAD So
- AAE On
But I can't figure out how to properly convert those numbers to chars and how to make that working inside Java. Maybe one of you got an idea for me how to figure this out? Thanks in advance!