mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Added new Lookup table for sortable collector number to avoid repeated computations for the same coll numbers!
This commit is contained in:
@@ -199,15 +199,21 @@ public final class CardEdition implements Comparable<CardEdition> {
|
|||||||
* @param collectorNumber: Input collectorNumber tro transform in a Sorting Key
|
* @param collectorNumber: Input collectorNumber tro transform in a Sorting Key
|
||||||
* @return A 5-digits zero-padded collector number + any non-numerical parts attached.
|
* @return A 5-digits zero-padded collector number + any non-numerical parts attached.
|
||||||
*/
|
*/
|
||||||
|
private static Map<String, String> sortableCollNumberLookup = new HashMap<>();
|
||||||
public static String getSortableCollectorNumber(final String collectorNumber){
|
public static String getSortableCollectorNumber(final String collectorNumber){
|
||||||
String sortableCollNr = collectorNumber;
|
String inputCollNumber = collectorNumber;
|
||||||
if (sortableCollNr == null || sortableCollNr.length() == 0)
|
if (collectorNumber == null || collectorNumber.length() == 0)
|
||||||
sortableCollNr = "50000"; // very big number of 5 digits to have them in last positions
|
inputCollNumber = "50000"; // very big number of 5 digits to have them in last positions
|
||||||
|
|
||||||
|
String matchedCollNr = sortableCollNumberLookup.getOrDefault(inputCollNumber, null);
|
||||||
|
if (matchedCollNr != null)
|
||||||
|
return matchedCollNr;
|
||||||
|
|
||||||
// Now, for proper sorting, let's zero-pad the collector number (if integer)
|
// Now, for proper sorting, let's zero-pad the collector number (if integer)
|
||||||
int collNr;
|
int collNr;
|
||||||
|
String sortableCollNr = inputCollNumber;
|
||||||
try {
|
try {
|
||||||
collNr = Integer.parseInt(sortableCollNr);
|
collNr = Integer.parseInt(collectorNumber);
|
||||||
sortableCollNr = String.format("%05d", collNr);
|
sortableCollNr = String.format("%05d", collNr);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
String nonNumeric = sortableCollNr.replaceAll("[0-9]", "");
|
String nonNumeric = sortableCollNr.replaceAll("[0-9]", "");
|
||||||
@@ -222,6 +228,7 @@ public final class CardEdition implements Comparable<CardEdition> {
|
|||||||
else // e.g. WS6, S1
|
else // e.g. WS6, S1
|
||||||
sortableCollNr = nonNumeric + String.format("%05d", collNr);
|
sortableCollNr = nonNumeric + String.format("%05d", collNr);
|
||||||
}
|
}
|
||||||
|
sortableCollNumberLookup.put(inputCollNumber, sortableCollNr);
|
||||||
return sortableCollNr;
|
return sortableCollNr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user