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

new FBTree class has been added

git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1059 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Vasiliy Bout 2010-02-24 13:15:11 +00:00
parent 5c1ea34fd2
commit 30e9f8dae0
4 changed files with 77 additions and 38 deletions

View file

@ -21,9 +21,11 @@ package org.geometerplus.fbreader.library;
import java.util.*;
import org.geometerplus.zlibrary.core.tree.ZLTree;
//import org.geometerplus.zlibrary.core.tree.ZLTree;
public abstract class LibraryTree extends ZLTree<LibraryTree> implements Comparable<LibraryTree> {
import org.geometerplus.fbreader.tree.FBTree;
public abstract class LibraryTree extends FBTree {
protected LibraryTree() {
super();
}
@ -44,18 +46,12 @@ public abstract class LibraryTree extends ZLTree<LibraryTree> implements Compara
return new BookTree(this, book, showAuthors);
}
public abstract String getName();
protected String getSortKey() {
return getName();
}
private String myChildrenString;
public String getSecondString() {
if (myChildrenString == null) {
StringBuilder builder = new StringBuilder();
int count = 0;
for (LibraryTree subtree : subTrees()) {
for (FBTree subtree : subTrees()) {
if (count++ > 0) {
builder.append(", ");
}
@ -69,43 +65,21 @@ public abstract class LibraryTree extends ZLTree<LibraryTree> implements Compara
return myChildrenString;
}
public int compareTo(LibraryTree ct) {
final String key0 = getSortKey();
final String key1 = ct.getSortKey();
if (key0 == null) {
return (key1 == null) ? 0 : -1;
}
if (key1 == null) {
return 1;
}
return key0.toLowerCase().compareTo(key1.toLowerCase());
}
public final void sortAllChildren() {
List<LibraryTree> children = subTrees();
if (!children.isEmpty()) {
Collections.sort(children);
for (LibraryTree tree : children) {
tree.sortAllChildren();
}
}
}
public boolean removeBook(Book book) {
final LinkedList<LibraryTree> toRemove = new LinkedList<LibraryTree>();
for (LibraryTree tree : this) {
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
for (FBTree tree : this) {
if ((tree instanceof BookTree) && ((BookTree)tree).Book.equals(book)) {
toRemove.add(tree);
}
}
for (LibraryTree tree : toRemove) {
for (FBTree tree : toRemove) {
tree.removeSelf();
LibraryTree parent = tree.Parent;
FBTree parent = tree.Parent;
for (; (parent != null) && !parent.hasChildren(); parent = parent.Parent) {
parent.removeSelf();
}
for (; parent != null; parent = parent.Parent) {
parent.myChildrenString = null;
((LibraryTree)parent).myChildrenString = null;
}
}
return !toRemove.isEmpty();