@Test public void testSubtreeSize() { BasicEventList<String> source = new BasicEventList<>(); source.add("ABCD"); source.add("ABEFG"); source.add("ACDC"); source.add("ACE"); TreeList<String> treeList = new TreeList<>(source, COMPRESSED_CHARACTER_TREE_FORMAT, TreeList.<String>nodesStartExpanded()); assertTreeStructure(treeList, new String[] { "A", "AB", "ABC", "ABCD", "ABE", "ABEF", "ABEFG", "AC", "ACD", "ACDC", "ACE", }); assertEquals(11, treeList.subtreeSize(0, true)); assertEquals(6, treeList.subtreeSize(1, true)); assertEquals(2, treeList.subtreeSize(2, true)); assertEquals(1, treeList.subtreeSize(3, true)); assertEquals(3, treeList.subtreeSize(4, true)); assertEquals(2, treeList.subtreeSize(5, true)); assertEquals(1, treeList.subtreeSize(6, true)); assertEquals(4, treeList.subtreeSize(7, true)); assertEquals(2, treeList.subtreeSize(8, true)); assertEquals(1, treeList.subtreeSize(9, true)); assertEquals(1, treeList.subtreeSize(10, true)); }
private int subtreeSize(int index, boolean indexIsVisibleIndex, boolean includeCollapsedNodes) { byte coloursIn = indexIsVisibleIndex ? VISIBLE_NODES : ALL_NODES; byte coloursOut = includeCollapsedNodes ? ALL_NODES : VISIBLE_NODES; Node<E> node = data.get(index, coloursIn).get(); int indexOut; if(coloursIn == coloursOut) { indexOut = index; } else { assert((node.element.getColor() & coloursOut) != 0); indexOut = data.convertIndexColor(index, coloursIn, coloursOut); } Node<E> nextNodeNotInSubtree = nextNodeThatsNotAChildOfByStructure(node); if(nextNodeNotInSubtree == null) { return data.size(coloursOut) - indexOut; } return data.indexOfNode(nextNodeNotInSubtree.element, coloursOut) - indexOut; }
TreeList extends TransformedList<TreeList.Node<E>,E> { private int subtreeSize(int index, boolean indexIsVisibleIndex, boolean includeCollapsedNodes) { byte coloursIn = indexIsVisibleIndex ? VISIBLE_NODES : ALL_NODES; byte coloursOut = includeCollapsedNodes ? ALL_NODES : VISIBLE_NODES; Node<E> node = data.get(index, coloursIn).get(); int indexOut; if(coloursIn == coloursOut) { indexOut = index; } else { assert((node.element.getColor() & coloursOut) != 0); indexOut = data.convertIndexColor(index, coloursIn, coloursOut); } Node<E> nextNodeNotInSubtree = nextNodeThatsNotAChildOfByStructure(node); if(nextNodeNotInSubtree == null) { return data.size(coloursOut) - indexOut; } return data.indexOfNode(nextNodeNotInSubtree.element, coloursOut) - indexOut; } }
TreeList extends TransformedList<TreeList.Node<E>,E> { private int subtreeSize(int index, boolean indexIsVisibleIndex, boolean includeCollapsedNodes) { byte coloursIn = indexIsVisibleIndex ? VISIBLE_NODES : ALL_NODES; byte coloursOut = includeCollapsedNodes ? ALL_NODES : VISIBLE_NODES; Node<E> node = data.get(index, coloursIn).get(); int indexOut; if(coloursIn == coloursOut) { indexOut = index; } else { assert((node.element.getColor() & coloursOut) != 0); indexOut = data.convertIndexColor(index, coloursIn, coloursOut); } Node<E> nextNodeNotInSubtree = nextNodeThatsNotAChildOfByStructure(node); if(nextNodeNotInSubtree == null) { return data.size(coloursOut) - indexOut; } return data.indexOfNode(nextNodeNotInSubtree.element, coloursOut) - indexOut; } TreeList(EventList<E> source, Format<E> format, ExpansionModel<E> expansionModel); private  TreeList(InitializationData<E> initializationData); @Deprecated  TreeList(EventList<E> source, Format<E> format); }
TreeList extends TransformedList<TreeList.Node<E>,E> { private int subtreeSize(int index, boolean indexIsVisibleIndex, boolean includeCollapsedNodes) { byte coloursIn = indexIsVisibleIndex ? VISIBLE_NODES : ALL_NODES; byte coloursOut = includeCollapsedNodes ? ALL_NODES : VISIBLE_NODES; Node<E> node = data.get(index, coloursIn).get(); int indexOut; if(coloursIn == coloursOut) { indexOut = index; } else { assert((node.element.getColor() & coloursOut) != 0); indexOut = data.convertIndexColor(index, coloursIn, coloursOut); } Node<E> nextNodeNotInSubtree = nextNodeThatsNotAChildOfByStructure(node); if(nextNodeNotInSubtree == null) { return data.size(coloursOut) - indexOut; } return data.indexOfNode(nextNodeNotInSubtree.element, coloursOut) - indexOut; } TreeList(EventList<E> source, Format<E> format, ExpansionModel<E> expansionModel); private  TreeList(InitializationData<E> initializationData); @Deprecated  TreeList(EventList<E> source, Format<E> format); @SuppressWarnings("unchecked") static final ExpansionModel<E> nodesStartExpanded(); @SuppressWarnings("unchecked") static final ExpansionModel<E> nodesStartCollapsed(); EventList<Node<E>> getNodesList(); int depth(int visibleIndex); int subtreeSize(int visibleIndex, boolean includeCollapsed); @Override int size(); @Override E get(int visibleIndex); @Override E remove(int visibleIndex); Node<E> getTreeNode(int visibleIndex); boolean hasChildren(int visibleIndex); void setTreeFormat(Format<E> treeFormat); List<Node<E>> getRoots(); boolean getAllowsChildren(int visibleIndex); boolean isExpanded(int visibleIndex); void setExpanded(int visibleIndex, boolean expanded); void toggleExpanded(int visibleIndex); @Override void listChanged(ListEvent<Node<E>> listChanges); @Override void dispose(); }
TreeList extends TransformedList<TreeList.Node<E>,E> { private int subtreeSize(int index, boolean indexIsVisibleIndex, boolean includeCollapsedNodes) { byte coloursIn = indexIsVisibleIndex ? VISIBLE_NODES : ALL_NODES; byte coloursOut = includeCollapsedNodes ? ALL_NODES : VISIBLE_NODES; Node<E> node = data.get(index, coloursIn).get(); int indexOut; if(coloursIn == coloursOut) { indexOut = index; } else { assert((node.element.getColor() & coloursOut) != 0); indexOut = data.convertIndexColor(index, coloursIn, coloursOut); } Node<E> nextNodeNotInSubtree = nextNodeThatsNotAChildOfByStructure(node); if(nextNodeNotInSubtree == null) { return data.size(coloursOut) - indexOut; } return data.indexOfNode(nextNodeNotInSubtree.element, coloursOut) - indexOut; } TreeList(EventList<E> source, Format<E> format, ExpansionModel<E> expansionModel); private  TreeList(InitializationData<E> initializationData); @Deprecated  TreeList(EventList<E> source, Format<E> format); @SuppressWarnings("unchecked") static final ExpansionModel<E> nodesStartExpanded(); @SuppressWarnings("unchecked") static final ExpansionModel<E> nodesStartCollapsed(); EventList<Node<E>> getNodesList(); int depth(int visibleIndex); int subtreeSize(int visibleIndex, boolean includeCollapsed); @Override int size(); @Override E get(int visibleIndex); @Override E remove(int visibleIndex); Node<E> getTreeNode(int visibleIndex); boolean hasChildren(int visibleIndex); void setTreeFormat(Format<E> treeFormat); List<Node<E>> getRoots(); boolean getAllowsChildren(int visibleIndex); boolean isExpanded(int visibleIndex); void setExpanded(int visibleIndex, boolean expanded); void toggleExpanded(int visibleIndex); @Override void listChanged(ListEvent<Node<E>> listChanges); @Override void dispose(); static final ExpansionModel NODES_START_EXPANDED; static final ExpansionModel NODES_START_COLLAPSED; }