/** * Creates parent nodes, grandparent nodes, and so forth up to the root * node, for the data that has been inserted into the tree. Can only be * called once, and thus can be called only after all of the data has been * inserted into the tree. */ public synchronized void build() { if (built) return; root = itemBoundables.isEmpty() ? createNode(0) : createHigherLevels(itemBoundables, -1); // the item list is no longer needed itemBoundables = null; built = true; }
/** * Creates the levels higher than the given level * * @param boundablesOfALevel * the level to build on * @param level * the level of the Boundables, or -1 if the boundables are item * boundables (that is, below level 0) * @return the root, which may be a ParentNode or a LeafNode */ private AbstractNode createHigherLevels(List boundablesOfALevel, int level) { Assert.isTrue(!boundablesOfALevel.isEmpty()); List parentBoundables = createParentBoundables(boundablesOfALevel, level + 1); if (parentBoundables.size() == 1) { return (AbstractNode) parentBoundables.get(0); } return createHigherLevels(parentBoundables, level + 1); }