/** * If the RTree has no entries returns {@link Optional#absent} otherwise returns * the minimum bounding rectangle of all entries in the RTree. * * @return minimum bounding rectangle of all entries in RTree */ public Optional<Rectangle> mbr() { if (!root.isPresent()) return absent(); else return of(root.get().geometry().mbr()); }
private Rectangle calculateMaxView(RTree<T, S> tree) { return tree.entries().reduce(Optional.<Rectangle>absent(), new Func2<Optional<Rectangle>, Entry<T, S>, Optional<Rectangle>>() { @Override public Optional<Rectangle> call(Optional<Rectangle> r, Entry<T, S> entry) { if (r.isPresent()) return of(r.get().add(entry.geometry().mbr())); else return of(entry.geometry().mbr()); } }).toBlocking().single().or(rectangle(0, 0, 0, 0)); }
/** * Sets the max number of children in an R-tree node. * * @param maxChildren * max number of children in R-tree node. * @return builder */ public Builder maxChildren(int maxChildren) { this.maxChildren = of(maxChildren); return this; }
@Override public Observable<WatchEvent<?>> call(WatchService watchService) { if (!scheduler.isPresent()) { if (!pollDuration.isPresent() || pollDuration.get() == 0) { scheduler = Optional.of(rx.schedulers.Schedulers.computation()); } else { // poll will block so don't do on // computation() scheduler = Optional.of(rx.schedulers.Schedulers.io()); } } return from(watchService, scheduler.get(), pollDuration.or(Long.MAX_VALUE), pollDurationUnit, pollInterval, pollIntervalUnit, backpressureStrategy); } });
@SuppressWarnings("unchecked") private <T, S extends Geometry> RTree<T, S> packingSTR(List<? extends HasGeometry> objects, boolean isLeaf, int size, Context<T, S> context) { int capacity = (int) Math.round(maxChildren.get() * loadingFactor); int nodeCount = (int) Math.ceil(1.0 * objects.size() / capacity); root = context.factory().createNonLeaf((List<Node<T, S>>) objects, context); return new RTree<T, S>(of(root), size, context);
/** * Builds the {@link RTree}. * * @param <T> * value type * @param <S> * geometry type * @return RTree */ @SuppressWarnings("unchecked") public <T, S extends Geometry> RTree<T, S> create() { setDefaultCapacity(); return new RTree<T, S>(Optional.<Node<T, S>>absent(), 0, new Context<T, S>(minChildren.get(), maxChildren.get(), selector, splitter, (Factory<T, S>) factory)); }
public T peek() { // if (isEmpty()) // throw new RuntimeException("cannot peek on empty stack"); // else return this.head.get(); }
public boolean isEmpty() { return !head.isPresent(); }
public static <T> Optional<T> of(T t) { return new Optional<T>(t, true); }
private static <T, S extends Geometry> RTree<T, S> read(Input input) { Context<T, S> context = readContext(input); boolean hasRoot = input.readBoolean(); int size = input.readInt(); final Optional<Node<T, S>> root; if (hasRoot) { root = Optional.of(SerializerKryo.<T, S>readNode(input)); } else { root = Optional.absent(); } return SerializerHelper.create(root, size, context); }
/** * Constructor. * * @param root * the root node of the R-tree * @param context * options for the R-tree */ private RTree(Node<T, S> root, int size, Context<T, S> context) { this(of(root), size, context); }
@SuppressWarnings("unchecked") private <T, S extends Geometry> RTree<T, S> packingSTR(List<? extends HasGeometry> objects, boolean isLeaf, int size, Context<T, S> context) { int capacity = (int) Math.round(maxChildren.get() * loadingFactor); int nodeCount = (int) Math.ceil(1.0 * objects.size() / capacity); root = context.factory().createNonLeaf((List<Node<T, S>>) objects, context); return new RTree<T, S>(of(root), size, context);
private RTree() { this(Optional.<Node<T, S>>absent(), 0, null); }