use of com.ichi2.libanki.sched.AbstractDeckTreeNode in project AnkiChinaAndroid by ankichinateam.
the class SchedV2 method _groupChildrenMain.
/**
* @return the tree structure of all decks from @grps, starting
* at specified depth.
*
* @param grps a list of decks of dept at least depth, having all
* the same first depth name elements, sorted in deck order.
* @param depth The depth of the tree we are creating
* @param checkDone whether the set of deck was checked. If
* false, we can't assume all decks have parents and that there
* is no duplicate. Instead, we'll ignore problems.
*/
@NonNull
protected <T extends AbstractDeckTreeNode> List<T> _groupChildrenMain(@NonNull List<T> grps, int depth, boolean checkDone) {
List<T> tree = new ArrayList<>();
// group and recurse
ListIterator<T> it = grps.listIterator();
while (it.hasNext()) {
T node = it.next();
String head = node.getDeckNameComponent(depth);
List<AbstractDeckTreeNode> children = new ArrayList<>();
/* Compose the "children" node list. The children is a
* list of all the nodes that proceed the current one that
* contain the same at depth `depth`, except for the
* current one itself. I.e., they are subdecks that stem
* from this node. This is our version of python's
* itertools.groupby. */
if (!checkDone && node.getDepth() != depth) {
JSONObject deck = mCol.getDecks().get(node.getDid());
Timber.d("Deck %s (%d)'s parent is missing. Ignoring for quick display.", deck.getString("name"), node.getDid());
continue;
}
while (it.hasNext()) {
AbstractDeckTreeNode next = it.next();
if (head.equals(next.getDeckNameComponent(depth))) {
// Same head - add to tail of current head.
if (!checkDone && next.getDepth() == depth) {
JSONObject deck = mCol.getDecks().get(next.getDid());
Timber.d("Deck %s (%d)'s is a duplicate name. Ignoring for quick display.", deck.getString("name"), next.getDid());
continue;
}
children.add(next);
} else {
// We've iterated past this head, so step back in order to use this node as the
// head in the next iteration of the outer loop.
it.previous();
break;
}
}
// the children set contains direct children but not the children of children...
node.setChildren(_groupChildrenMain(children, depth + 1, checkDone), "std".equals(getName()));
tree.add(node);
}
return tree;
}
use of com.ichi2.libanki.sched.AbstractDeckTreeNode in project Anki-Android by ankidroid.
the class SchedV2 method _groupChildrenMain.
/**
* @return the tree structure of all decks from @descandants, starting
* at specified depth.
*
* @param descendants a list of decks of dept at least depth, having all
* the same first depth name elements, sorted in deck order.
* @param depth The depth of the tree we are creating
* @param checkDone whether the set of deck was checked. If
* false, we can't assume all decks have parents and that there
* is no duplicate. Instead, we'll ignore problems.
*/
@NonNull
protected <T extends AbstractDeckTreeNode<T>> List<T> _groupChildrenMain(@NonNull List<T> descendants, int depth, boolean checkDone) {
List<T> children = new ArrayList<>();
// group and recurse
ListIterator<T> it = descendants.listIterator();
while (it.hasNext()) {
T child = it.next();
String head = child.getDeckNameComponent(depth);
List<T> descendantsOfChild = new ArrayList<>();
/* Compose the "children" node list. The children is a
* list of all the nodes that proceed the current one that
* contain the same at depth `depth`, except for the
* current one itself. I.e., they are subdecks that stem
* from this descendant. This is our version of python's
* itertools.groupby. */
if (!checkDone && child.getDepth() != depth) {
Deck deck = mCol.getDecks().get(child.getDid());
Timber.d("Deck %s (%d)'s parent is missing. Ignoring for quick display.", deck.getString("name"), child.getDid());
continue;
}
while (it.hasNext()) {
T descendantOfChild = it.next();
if (head.equals(descendantOfChild.getDeckNameComponent(depth))) {
// Same head - add to tail of current head.
if (!checkDone && descendantOfChild.getDepth() == depth) {
Deck deck = mCol.getDecks().get(descendantOfChild.getDid());
Timber.d("Deck %s (%d)'s is a duplicate name. Ignoring for quick display.", deck.getString("name"), descendantOfChild.getDid());
continue;
}
descendantsOfChild.add(descendantOfChild);
} else {
// We've iterated past this head, so step back in order to use this descendant as the
// head in the next iteration of the outer loop.
it.previous();
break;
}
}
// the children_sDescendant set contains direct children_sDescendant but not the children_sDescendant of children_sDescendant...
List<T> childrenNode = _groupChildrenMain(descendantsOfChild, depth + 1, checkDone);
child.setChildren(childrenNode, "std".equals(getName()));
children.add(child);
}
return children;
}
Aggregations