Class AbstractRTree<T extends RNode>

  • 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 the RTreeInterface interface 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)
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractRTree()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(java.lang.Object obj)  
      boolean containsAll​(java.util.Collection<?> c)  
      void forEach​(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()  
      boolean isEmpty()  
      <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.
      T searchNearest​(java.util.Comparator<? super RNode> compareFunc)
      Return the first data element as specified by the comparator.
      T searchNearest​(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
      • Methods inherited from interface java.util.Collection

        addAll, clear, equals, hashCode, iterator, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Field Detail

      • modCount

        protected transient int modCount
      • nodesVisited

        protected long nodesVisited
      • nodesReturned

        protected long nodesReturned
    • Constructor Detail

      • AbstractRTree

        public AbstractRTree()
    • Method Detail

      • getRoot

        protected abstract oracle.spatial.geometry.AbstractRTree.Internal<T> getRoot()
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<T extends RNode>
        Overrides:
        isEmpty in class java.util.AbstractCollection<T extends RNode>
      • searchMer

        public java.util.stream.Stream<T> searchMer​(java.util.function.Predicate<? super Mer> merFilter)
        Description copied from interface: RTreeInterface
        Return 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:
        searchMer in interface RTreeInterface<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: RTreeInterface
        Search 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:
        search in interface RTreeInterface<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: RTreeInterface
        Return 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:
        searchNearest in interface RTreeInterface<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: RTreeInterface
        Search 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:
        search in interface RTreeInterface<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: RTreeInterface
        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. 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:
        searchNearest in interface RTreeInterface<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: RTreeInterface
        Do 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:
        join in interface RTreeInterface<T extends RNode>
        Type Parameters:
        Q - the type of the joined rtree
        Parameters:
        rtree1 - the tree to join
        merFilter - restricts the area of the join
        Returns:
        pairs of items whose Mers interact
      • contains

        public boolean contains​(java.lang.Object obj)
        Specified by:
        contains in interface java.util.Collection<T extends RNode>
        Overrides:
        contains in class java.util.AbstractCollection<T extends RNode>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<T extends RNode>
        Overrides:
        containsAll in class java.util.AbstractCollection<T extends RNode>
      • forEach

        public void forEach​(java.util.function.Predicate<? super Mer> merFilter,
                            java.util.function.Consumer<? super T> action)
        Description copied from interface: RTreeInterface
        The 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:
        forEach in interface RTreeInterface<T extends RNode>
        Parameters:
        merFilter - selects the objects to be processed.
        action - the action to apply objects of interest.