diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFileHelper.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFileHelper.java index a5067fd..9a5f177 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFileHelper.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFileHelper.java @@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -116,17 +115,13 @@ public final class BookFileHelper { */ @NotNull public static Map populateLetterIndices(@NotNull List books) { - List firstCharacter = new ArrayList<>(books.size()); - for (String bookIdentifier : books) { - firstCharacter.add(BookFormatter.stripColor(bookIdentifier).toLowerCase().charAt(0)); - } - Map firstEncounter = new HashMap<>(); - for (int characterIndex = 0; characterIndex <= 25; characterIndex++) { - char character = (char) ('a' + characterIndex); - int index = Collections.binarySearch(firstCharacter, character); - if (index >= 0) { - firstEncounter.put(character, index); + Character current = null; + for (int i = 0; i < books.size(); i++) { + char first = BookFormatter.stripColor(books.get(i)).toLowerCase().charAt(0); + if (current == null || current != first) { + current = first; + firstEncounter.put(first, i); } } return firstEncounter; @@ -170,7 +165,8 @@ public final class BookFileHelper { // Sort the book list Comparator bookComparator = Comparator.naturalOrder(); - fileList.sort((a, b) -> bookComparator.compare(BookFormatter.stripColor(a), BookFormatter.stripColor(b))); + fileList.sort((a, b) -> bookComparator.compare(BookFormatter.stripColor(a).toLowerCase(), + BookFormatter.stripColor(b).toLowerCase())); return fileList; }