mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Robust sorting of CollectorNumber (as string) handling properly non-numerical nrs. and N.A.s
This commit is contained in:
@@ -662,12 +662,19 @@ public enum ColumnDef {
|
||||
String collectorNumber;
|
||||
if (i instanceof PaperCard) {
|
||||
collectorNumber = ((PaperCard) i).getCollectorNumber();
|
||||
// First off, make all NO_COLLECTOR_NUMBER the last in sortings
|
||||
if (collectorNumber.equals(IPaperCard.NO_COLLECTOR_NUMBER))
|
||||
collectorNumber = "50000"; // very big number of 5 digits to have them in last positions
|
||||
|
||||
// Now, for proper sorting, let's zero-pad the collector number (if integer)
|
||||
try {
|
||||
int collNr = Integer.parseInt(collectorNumber);
|
||||
collectorNumber = String.format("%05d", collNr);
|
||||
} catch (NumberFormatException ex) {
|
||||
} // NOOP, leave it as it is - NaN (may contains letters)
|
||||
String nonNumeric = collectorNumber.replaceAll("[0-9]", "");
|
||||
String onlyNumeric = collectorNumber.replaceAll("[^0-9]", "");
|
||||
collectorNumber = String.format("%05d", Integer.parseInt(onlyNumeric)) + nonNumeric;
|
||||
}
|
||||
} else {
|
||||
collectorNumber = IPaperCard.NO_COLLECTOR_NUMBER;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user