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
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

View file

@ -88,11 +88,6 @@ public class BookTree extends LibraryTree {
return book != null && book.equals(Book);
}
@Override
protected String getSortKey() {
return "BSK:" + super.getSortKey();
}
@Override
public int compareTo(FBTree 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_SEARCHING = 2;
private volatile int myStatusMask = 0;
private final Object myStatusLock = new Object();
private synchronized void setStatus(int status) {
myStatusMask = status;
fireModelChangedEvent(ChangeListener.Code.StatusChanged);
private void setStatus(int status) {
synchronized (myStatusLock) {
if (myStatusMask != status) {
myStatusMask = status;
fireModelChangedEvent(ChangeListener.Code.StatusChanged);
}
}
}
public Library(BooksDatabase db) {
@ -341,12 +346,20 @@ public final class Library extends AbstractLibrary {
// remove from recent/favorites list if no;
// collect newly "orphaned" books
final Set<Book> orphanedBooks = new HashSet<Book>();
final Set<ZLPhysicalFile> physicalFiles = new HashSet<ZLPhysicalFile>();
int count = 0;
for (Book book : savedBooksByFileId.values()) {
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()) {
boolean doAdd = true;
final ZLPhysicalFile file = book.File.getPhysicalFile();
if (file == null) {
continue;
}
@ -382,6 +395,9 @@ public final class Library extends AbstractLibrary {
final List<ZLPhysicalFile> physicalFilesList = collectPhysicalFiles();
for (ZLPhysicalFile file : physicalFilesList) {
if (physicalFiles.contains(file)) {
continue;
}
collectBooks(
file, fileInfos,
savedBooksByFileId, orphanedBooksByFileId,

View file

@ -64,6 +64,6 @@ public final class SeriesTree extends LibraryTree {
@Override
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() {
return (Tag != null) ? Tag.Name : null;
return Tag != null ? Tag.Name : null;
}
@Override

View file

@ -134,6 +134,30 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
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) {
final String key0 = getSortKey();
final String key1 = tree.getSortKey();
@ -143,7 +167,7 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
if (key1 == null) {
return 1;
}
return key0.toLowerCase().compareTo(key1.toLowerCase());
return compareStringsIgnoreCase(key0, key1);
}
public String getSummary() {