private boolean remove(Object searchBounds, AbstractNode node, Object item) { // first try removing item from this node boolean found = removeItem(node, item); if (found) return true; AbstractNode childToPrune = null; // next try removing item from lower nodes for (Iterator i = node.getChildBoundables().iterator(); i.hasNext(); ) { Boundable childBoundable = (Boundable) i.next(); if (!getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds)) { continue; } if (childBoundable instanceof AbstractNode) { found = remove(searchBounds, (AbstractNode) childBoundable, item); // if found, record child for pruning and exit if (found) { childToPrune = (AbstractNode) childBoundable; break; } } } // prune child if possible if (childToPrune != null) { if (childToPrune.getChildBoundables().isEmpty()) { node.getChildBoundables().remove(childToPrune); } } return found; }
private void queryInternal(Object searchBounds, AbstractNode node, ItemVisitor visitor) { List childBoundables = node.getChildBoundables(); for (int i = 0; i < childBoundables.size(); i++) { Boundable childBoundable = (Boundable) childBoundables.get(i); if (! getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds)) { continue; } if (childBoundable instanceof AbstractNode) { queryInternal(searchBounds, (AbstractNode) childBoundable, visitor); } else if (childBoundable instanceof ItemBoundable) { visitor.visitItem(((ItemBoundable)childBoundable).getItem()); } else { Assert.shouldNeverReachHere(); } } }
private void queryInternal(Object searchBounds, AbstractNode node, List matches) { List childBoundables = node.getChildBoundables(); for (int i = 0; i < childBoundables.size(); i++) { Boundable childBoundable = (Boundable) childBoundables.get(i); if (! getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds)) { continue; } if (childBoundable instanceof AbstractNode) { queryInternal(searchBounds, (AbstractNode) childBoundable, matches); } else if (childBoundable instanceof ItemBoundable) { matches.add(((ItemBoundable)childBoundable).getItem()); } else { Assert.shouldNeverReachHere(); } } }
/** * Also builds the tree, if necessary. */ protected List query(Object searchBounds) { build(); ArrayList matches = new ArrayList(); if (isEmpty()) { //Assert.isTrue(root.getBounds() == null); return matches; } if (getIntersectsOp().intersects(root.getBounds(), searchBounds)) { queryInternal(searchBounds, root, matches); } return matches; }
/** * Also builds the tree, if necessary. */ protected void query(Object searchBounds, ItemVisitor visitor) { build(); if (isEmpty()) { // nothing in tree, so return //Assert.isTrue(root.getBounds() == null); return; } if (getIntersectsOp().intersects(root.getBounds(), searchBounds)) { queryInternal(searchBounds, root, visitor); } }
/** * Removes an item from the tree. * (Builds the tree, if necessary.) */ protected boolean remove(Object searchBounds, Object item) { build(); if (getIntersectsOp().intersects(root.getBounds(), searchBounds)) { return remove(searchBounds, root, item); } return false; }