Class AbstractRTree<T extends RNode>
- java.lang.Object
-
- java.util.AbstractCollection<T>
-
- oracle.spatial.geometry.AbstractRTree<T>
-
- Type Parameters:
T- The data type stored in this RTree
- All Implemented Interfaces:
java.lang.Iterable<T>,java.util.Collection<T>,RTreeInterface<T>
- Direct Known Subclasses:
RStarTree
public abstract class AbstractRTree<T extends RNode> extends java.util.AbstractCollection<T> implements RTreeInterface<T>
This class provides a skeletal implementation of theRTreeInterfaceinterface to minimize the effort required to implement an RTree.The programmer should generally provide a void (no argument) and collection constructor, as per the recommendation in the
Collectioninterface specification.Methods which modify the RTree should increment modCount so the stream methods can detect concurrent modification.
Subclasses should consider implementing:
- Standard Collection constructors: a no-argument constructor and a constructor taking a Collection
- clear
- add
- addAll (if preprocessing is helpful)
- Iterator iterator(); (to handle remove)
- remove
- removeAll (if doing a spatial join is helpful)
- removeIf
- retainAll (if doing a spatial join is helpful)
- Since:
- release specific (what release of product did this appear in)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractRTree.DoubleRNodeHelper class for {#search(ToDoubleFunction)} Stores the node plus a double value; sorts on the doubles.protected classAbstractRTree.JoinWalker<T extends RNode,Q extends RNode>TODOprotected static classAbstractRTree.JoinWalkerLevel<T extends RNode,Q extends RNode>Helper class for JoinWalker.static classAbstractRTree.PairDebug<P,Q>protected classAbstractRTree.PQItemprotected classAbstractRTree.TreeWalker<Q extends RNode>This helper class remembers its place in the search tree and can find the next node to return and/or do an intelligent split of the tree.
-
Field Summary
Fields Modifier and Type Field Description protected intmodCountprotected longnodesReturnedprotected longnodesVisited
-
Constructor Summary
Constructors Constructor Description AbstractRTree()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancontains(java.lang.Object obj)booleancontainsAll(java.util.Collection<?> c)voidforEach(java.util.function.Predicate<? super Mer> merFilter, java.util.function.Consumer<? super T> action)The specified action is applied to every node that touches the search mer.protected abstract oracle.spatial.geometry.AbstractRTree.Internal<T>getRoot()booleanisEmpty()<Q extends RNode>
java.util.stream.Stream<Pair<T,Q>>join(RTreeInterface<Q> rtree1, java.util.function.Predicate<? super Mer> merFilter)Do a join of this RTree with rtree1.java.util.stream.Stream<T>search(java.util.Comparator<? super RNode> compareFunc)Search the tree (Mers) in the order specified by the comparator.java.util.stream.Stream<T>search(java.util.function.ToDoubleFunction<? super RNode> sortMetric)Search the tree of Mers in the order specified by the metric computed on the Mers of the tree.java.util.stream.Stream<T>searchMer(java.util.function.Predicate<? super Mer> merFilter)Return all the objects which satisfy the merFilter.TsearchNearest(java.util.Comparator<? super RNode> compareFunc)Return the first data element as specified by the comparator.TsearchNearest(java.util.function.ToDoubleFunction<? super RNode> sortMetric)Search the tree of Mers in the order specified by the metric computed on the Mers of the tree and return the single smallest item.-
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
getRoot
protected abstract oracle.spatial.geometry.AbstractRTree.Internal<T> getRoot()
-
isEmpty
public boolean isEmpty()
-
searchMer
public java.util.stream.Stream<T> searchMer(java.util.function.Predicate<? super Mer> merFilter)
Description copied from interface:RTreeInterfaceReturn all the objects which satisfy the merFilter. See note on merFilter in the javadoc for this interface. For example, to create a list of all data in tree touching targetMer:List<T> touches = tree.searchmer(x -> targetMer.interacts(x)).collect(Collectors.toList());- Specified by:
searchMerin interfaceRTreeInterface<T extends RNode>- Parameters:
merFilter- the search mer- Returns:
- a Stream of the selected objects
-
search
public java.util.stream.Stream<T> search(java.util.Comparator<? super RNode> compareFunc)
Description copied from interface:RTreeInterfaceSearch the tree (Mers) in the order specified by the comparator. Creates a priority queue of all Mers seen as it searches the tree, choosing which subtree to descend according to the comparator.To order the priority queue, compareFunc will be called multiple times per node visited. If your comparison function is expensive, consider using
RTreeInterface.search(ToDoubleFunction)instead.- Specified by:
searchin interfaceRTreeInterface<T extends RNode>- Parameters:
compareFunc- indicates which Mer or leaf is closer to the target. See note on distance metric in the javadoc for this interface.- Returns:
- a Stream of the objects in the tree, sorted according to compareFunc
-
searchNearest
public T searchNearest(java.util.Comparator<? super RNode> compareFunc)
Description copied from interface:RTreeInterfaceReturn the first data element as specified by the comparator.To order the priority queue, compareFunc will be called multiple times per node visited. If your comparison function is expensive, consider using
RTreeInterface.searchNearest(ToDoubleFunction)instead.- Specified by:
searchNearestin interfaceRTreeInterface<T extends RNode>- Parameters:
compareFunc- indicates which Mer or leaf is closest to the target. See note on distance metric in the javadoc for this interface.- Returns:
- the closest leaf data in the tree (according to compareFunc), or null if the tree is empty.
-
search
public java.util.stream.Stream<T> search(java.util.function.ToDoubleFunction<? super RNode> sortMetric)
Description copied from interface:RTreeInterfaceSearch the tree of Mers in the order specified by the metric computed on the Mers of the tree. The sortMetric function is called only once per node visited or returned (including internal nodes of the tree).Distances of Double.POSITIVE_INFINITY will not be searched or returned. Data nodes of distance Double.NEGATIVE_INFINITY are returned immediately as they are found and may reduce the search effort.
- Specified by:
searchin interfaceRTreeInterface<T extends RNode>- Parameters:
sortMetric- indicates the "distance" to the target as a double value. See note on distance metric in the javadoc for this interface.- Returns:
- a Stream of the objects in the tree, sorted according to sortMetric
-
searchNearest
public T searchNearest(java.util.function.ToDoubleFunction<? super RNode> sortMetric)
Description copied from interface:RTreeInterfaceSearch the tree of Mers in the order specified by the metric computed on the Mers of the tree and return the single smallest item. The sortMetric function is called only once per node visited or returned.Distances of Double.POSITIVE_INFINITY will not be searched or returned. A data node with distance Double.NEGATIVE_INFINITY will be returned immediately if found.
- Specified by:
searchNearestin interfaceRTreeInterface<T extends RNode>- Parameters:
sortMetric- indicates the "distance" to the target as a double value. See note on distance metric in the javadoc for this interface.- Returns:
- the closest leaf data in the tree (according to sortMetric), or null if the tree is empty.
-
join
public <Q extends RNode> java.util.stream.Stream<Pair<T,Q>> join(RTreeInterface<Q> rtree1, java.util.function.Predicate<? super Mer> merFilter)
Description copied from interface:RTreeInterfaceDo a join of this RTree with rtree1. Only areas touching merFilter are joined. See note on merFilter in the javadoc for this interface.- Specified by:
joinin interfaceRTreeInterface<T extends RNode>- Type Parameters:
Q- the type of the joined rtree- Parameters:
rtree1- the tree to joinmerFilter- restricts the area of the join- Returns:
- pairs of items whose Mers interact
-
contains
public boolean contains(java.lang.Object obj)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
forEach
public void forEach(java.util.function.Predicate<? super Mer> merFilter, java.util.function.Consumer<? super T> action)
Description copied from interface:RTreeInterfaceThe specified action is applied to every node that touches the search mer. The merFilter is used to reduce the search space. See note on merFilter in the javadoc for this interface.- Specified by:
forEachin interfaceRTreeInterface<T extends RNode>- Parameters:
merFilter- selects the objects to be processed.action- the action to apply objects of interest.
-
-