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

library building optimization

This commit is contained in:
Nikolay Pultsin 2012-09-16 13:48:52 +03:00
parent 6fa0fe8da3
commit c765fa9b5e
6 changed files with 56 additions and 13 deletions

View file

@ -46,7 +46,15 @@ public class AuthorTree extends LibraryTree {
@Override @Override
protected String getSortKey() { protected String getSortKey() {
return Author != null ? "ASK:" + Author.SortKey + ":" + Author.DisplayName : null; if (Author == null) {
return null;
}
return new StringBuilder()
.append(" Author:")
.append(Author.SortKey)
.append(":")
.append(Author.DisplayName)
.toString();
} }
@Override @Override

View file

@ -88,11 +88,6 @@ public class BookTree extends LibraryTree {
return book != null && book.equals(Book); return book != null && book.equals(Book);
} }
@Override
protected String getSortKey() {
return "BSK:" + super.getSortKey();
}
@Override @Override
public int compareTo(FBTree tree) { public int compareTo(FBTree tree) {
final int cmp = super.compareTo(tree); final int cmp = super.compareTo(tree);

View file

@ -56,10 +56,15 @@ public final class Library extends AbstractLibrary {
private final static int STATUS_LOADING = 1; private final static int STATUS_LOADING = 1;
private final static int STATUS_SEARCHING = 2; private final static int STATUS_SEARCHING = 2;
private volatile int myStatusMask = 0; private volatile int myStatusMask = 0;
private final Object myStatusLock = new Object();
private synchronized void setStatus(int status) { private void setStatus(int status) {
myStatusMask = status; synchronized (myStatusLock) {
fireModelChangedEvent(ChangeListener.Code.StatusChanged); if (myStatusMask != status) {
myStatusMask = status;
fireModelChangedEvent(ChangeListener.Code.StatusChanged);
}
}
} }
public Library(BooksDatabase db) { public Library(BooksDatabase db) {
@ -341,12 +346,20 @@ public final class Library extends AbstractLibrary {
// remove from recent/favorites list if no; // remove from recent/favorites list if no;
// collect newly "orphaned" books // collect newly "orphaned" books
final Set<Book> orphanedBooks = new HashSet<Book>(); final Set<Book> orphanedBooks = new HashSet<Book>();
final Set<ZLPhysicalFile> physicalFiles = new HashSet<ZLPhysicalFile>();
int count = 0; int count = 0;
for (Book book : savedBooksByFileId.values()) { for (Book book : savedBooksByFileId.values()) {
synchronized (this) { synchronized (this) {
final ZLPhysicalFile file = book.File.getPhysicalFile();
if (file != null) {
physicalFiles.add(file);
}
if (file != book.File && file != null && file.getPath().endsWith(".epub")) {
myDatabase.deleteFromBookList(book.getId());
continue;
}
if (book.File.exists()) { if (book.File.exists()) {
boolean doAdd = true; boolean doAdd = true;
final ZLPhysicalFile file = book.File.getPhysicalFile();
if (file == null) { if (file == null) {
continue; continue;
} }
@ -382,6 +395,9 @@ public final class Library extends AbstractLibrary {
final List<ZLPhysicalFile> physicalFilesList = collectPhysicalFiles(); final List<ZLPhysicalFile> physicalFilesList = collectPhysicalFiles();
for (ZLPhysicalFile file : physicalFilesList) { for (ZLPhysicalFile file : physicalFilesList) {
if (physicalFiles.contains(file)) {
continue;
}
collectBooks( collectBooks(
file, fileInfos, file, fileInfos,
savedBooksByFileId, orphanedBooksByFileId, savedBooksByFileId, orphanedBooksByFileId,

View file

@ -64,6 +64,6 @@ public final class SeriesTree extends LibraryTree {
@Override @Override
protected String getSortKey() { protected String getSortKey() {
return "SSK:" + super.getSortKey(); return " Series:" + super.getSortKey();
} }
} }

View file

@ -43,7 +43,7 @@ public final class TagTree extends LibraryTree {
} }
protected String getSortKey() { protected String getSortKey() {
return (Tag != null) ? Tag.Name : null; return Tag != null ? Tag.Name : null;
} }
@Override @Override

View file

@ -134,6 +134,30 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
return sortKey; return sortKey;
} }
private static int compareStringsIgnoreCase(String s0, String s1) {
final int len = Math.min(s0.length(), s1.length());
for (int i = 0; i < len; ++i) {
char c0 = s0.charAt(i);
char c1 = s1.charAt(i);
if (c0 == c1) {
continue;
}
c0 = Character.toLowerCase(c0);
c1 = Character.toLowerCase(c1);
if (c0 == c1) {
continue;
}
return c0 - c1;
}
if (s0.length() > len) {
return 1;
}
if (s0.length() > len) {
return -1;
}
return 0;
}
public int compareTo(FBTree tree) { public int compareTo(FBTree tree) {
final String key0 = getSortKey(); final String key0 = getSortKey();
final String key1 = tree.getSortKey(); final String key1 = tree.getSortKey();
@ -143,7 +167,7 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
if (key1 == null) { if (key1 == null) {
return 1; return 1;
} }
return key0.toLowerCase().compareTo(key1.toLowerCase()); return compareStringsIgnoreCase(key0, key1);
} }
public String getSummary() { public String getSummary() {