@Test public void testAddTwo() { rTree = rTree.add(splitterContext, "A", r1); rTree = rTree.add(splitterContext, "B", r2); testAreas(rTree); }
public RTree<T> add(SplitterContext<T> splitterContext, T element, Rectangle2D bounds) { if (!root.isPresent()) { return new RTree(LeafNode.create(element, bounds)); } Node<T> node = root.get(); if (node instanceof LeafNode) { LeafNode<T> leafNode = (LeafNode) node; Node<T> got = leafNode.add(splitterContext, element, bounds); Preconditions.checkArgument( !got.getParent().isPresent(), "return from LeafNode add has a parent"); return new RTree(got); } else { InnerNode<T> innerNode = (InnerNode) node; Node<T> got = innerNode.add(splitterContext, element, bounds); Preconditions.checkArgument( !got.getParent().isPresent(), "return from InnerNode add has a parent"); return new RTree(got); } }
RTree { public RTree<T> add(SplitterContext<T> splitterContext, T element, Rectangle2D bounds) { if (!root.isPresent()) { return new RTree(LeafNode.create(element, bounds)); } Node<T> node = root.get(); if (node instanceof LeafNode) { LeafNode<T> leafNode = (LeafNode) node; Node<T> got = leafNode.add(splitterContext, element, bounds); Preconditions.checkArgument( !got.getParent().isPresent(), "return from LeafNode add has a parent"); return new RTree(got); } else { InnerNode<T> innerNode = (InnerNode) node; Node<T> got = innerNode.add(splitterContext, element, bounds); Preconditions.checkArgument( !got.getParent().isPresent(), "return from InnerNode add has a parent"); return new RTree(got); } } }
RTree { public RTree<T> add(SplitterContext<T> splitterContext, T element, Rectangle2D bounds) { if (!root.isPresent()) { return new RTree(LeafNode.create(element, bounds)); } Node<T> node = root.get(); if (node instanceof LeafNode) { LeafNode<T> leafNode = (LeafNode) node; Node<T> got = leafNode.add(splitterContext, element, bounds); Preconditions.checkArgument( !got.getParent().isPresent(), "return from LeafNode add has a parent"); return new RTree(got); } else { InnerNode<T> innerNode = (InnerNode) node; Node<T> got = innerNode.add(splitterContext, element, bounds); Preconditions.checkArgument( !got.getParent().isPresent(), "return from InnerNode add has a parent"); return new RTree(got); } } private  RTree(); private  RTree(Node<T> node); }
RTree { public RTree<T> add(SplitterContext<T> splitterContext, T element, Rectangle2D bounds) { if (!root.isPresent()) { return new RTree(LeafNode.create(element, bounds)); } Node<T> node = root.get(); if (node instanceof LeafNode) { LeafNode<T> leafNode = (LeafNode) node; Node<T> got = leafNode.add(splitterContext, element, bounds); Preconditions.checkArgument( !got.getParent().isPresent(), "return from LeafNode add has a parent"); return new RTree(got); } else { InnerNode<T> innerNode = (InnerNode) node; Node<T> got = innerNode.add(splitterContext, element, bounds); Preconditions.checkArgument( !got.getParent().isPresent(), "return from InnerNode add has a parent"); return new RTree(got); } } private  RTree(); private  RTree(Node<T> node); Optional<Node<T>> getRoot(); static RTree<T> create(); RTree<T> add(SplitterContext<T> splitterContext, T element, Rectangle2D bounds); RTree<T> remove(T element); T getPickedObject(Point2D p); Set<Shape> getGrid(); Collection<TreeNode> getContainingLeafs(Point2D p); int count(); @Override String toString(); }
RTree { public RTree<T> add(SplitterContext<T> splitterContext, T element, Rectangle2D bounds) { if (!root.isPresent()) { return new RTree(LeafNode.create(element, bounds)); } Node<T> node = root.get(); if (node instanceof LeafNode) { LeafNode<T> leafNode = (LeafNode) node; Node<T> got = leafNode.add(splitterContext, element, bounds); Preconditions.checkArgument( !got.getParent().isPresent(), "return from LeafNode add has a parent"); return new RTree(got); } else { InnerNode<T> innerNode = (InnerNode) node; Node<T> got = innerNode.add(splitterContext, element, bounds); Preconditions.checkArgument( !got.getParent().isPresent(), "return from InnerNode add has a parent"); return new RTree(got); } } private  RTree(); private  RTree(Node<T> node); Optional<Node<T>> getRoot(); static RTree<T> create(); RTree<T> add(SplitterContext<T> splitterContext, T element, Rectangle2D bounds); RTree<T> remove(T element); T getPickedObject(Point2D p); Set<Shape> getGrid(); Collection<TreeNode> getContainingLeafs(Point2D p); int count(); @Override String toString();  }