1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +02:00

TitleTree: code unification

This commit is contained in:
Nikolay Pultsin 2011-07-17 16:09:02 +01:00
parent f79aaeb132
commit 6f864809a5
2 changed files with 25 additions and 18 deletions

View file

@ -300,31 +300,23 @@ public final class Library {
boolean doGroupTitlesByFirstLetter = false;
if (myBooks.size() > 10) {
final HashSet<Character> letterSet = new HashSet<Character>();
final HashSet<String> letterSet = new HashSet<String>();
for (Book book : myBooks) {
String title = book.getTitle();
if (title != null) {
title = title.trim();
if (!"".equals(title)) {
letterSet.add(title.charAt(0));
}
final String letter = TitleTree.firstTitleLetter(book);
if (letter != null) {
letterSet.add(letter);
}
}
doGroupTitlesByFirstLetter = myBooks.size() > letterSet.size() * 5 / 4;
}
if (doGroupTitlesByFirstLetter) {
for (Book book : myBooks) {
String title = book.getTitle();
if (title == null) {
continue;
final String letter = TitleTree.firstTitleLetter(book);
if (letter != null) {
final TitleTree tree =
getFirstLevelTree(ROOT_BY_TITLE).getTitleSubTree(letter);
tree.getBookSubTree(book, true);
}
title = title.trim();
if ("".equals(title)) {
continue;
}
Character c = title.charAt(0);
final TitleTree tree = getFirstLevelTree(ROOT_BY_TITLE).getTitleSubTree(c.toString());
tree.getBookSubTree(book, true);
}
} else {
for (Book book : myBooks) {