Class RTree<T>

Object
RTree<T>
Type Parameters:
T - object-type stored in structure (the payload).
Direct Known Subclasses:
BoundingBoxRTree, IntervalRTree

public abstract class RTree<T> extends Object
Bases class for implementations of R-Trees that store objects with associated geometry.
Author:
Owen Feehan
See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    RTree(int numberDimensions)
    Creates an empty R-Tree.
    protected
    RTree(int numberDimensions, int maxNumberEntries)
    Creates an empty R-Tree with a specified number of children.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    add(com.github.davidmoten.rtreemulti.geometry.Rectangle rectangle, T payload)
    Adds a Rectangle with a corresponding payload.
    Any arbitrary element from the tree.
    All elements contained within the tree, as a Set.
    protected Stream<T>
    containsStream(com.github.davidmoten.rtreemulti.geometry.Point point)
    Which objects contain a particular point?
    protected Stream<T>
    intersectsWithStream(com.github.davidmoten.rtreemulti.geometry.Rectangle rectangle)
    A stream of the elements that a rectangle intersects with.
    boolean
    Returns true if and only if the R-tree is empty of entries.
    protected void
    remove(com.github.davidmoten.rtreemulti.geometry.Rectangle rectangle, T payload)
    Removes a particular item from the r-tree, identified by its Rectangle and payload.
    int
    The total number of items stored in the tree.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RTree

      protected RTree(int numberDimensions)
      Creates an empty R-Tree.
      Parameters:
      numberDimensions - the number of spatial dimensions that the bounding boxes are expected to support.
    • RTree

      protected RTree(int numberDimensions, int maxNumberEntries)
      Creates an empty R-Tree with a specified number of children.
      Parameters:
      numberDimensions - the number of spatial dimensions that the bounding boxes are expected to support.
      maxNumberEntries - maximum number of entries in the r-tree.
  • Method Details

    • size

      public int size()
      The total number of items stored in the tree.
      Returns:
      the total number of items.
    • asSet

      public Set<T> asSet()
      All elements contained within the tree, as a Set.
      Returns:
      a newly created Set of all the elements, reusing the existing element objects.
    • arbitraryElement

      public T arbitraryElement()
      Any arbitrary element from the tree.

      This method should never be called on an empty tree. Consider checking first with isEmpty().

      Returns:
      the element.
    • isEmpty

      public boolean isEmpty()
      Returns true if and only if the R-tree is empty of entries.
      Returns:
      is R-tree empty
    • add

      protected void add(com.github.davidmoten.rtreemulti.geometry.Rectangle rectangle, T payload)
      Adds a Rectangle with a corresponding payload.

      Note that the payload must not be unique, and multiple identical elements can exist with the same bounding-box and payload.

      Parameters:
      rectangle - the rectangle associated with the payload.
      payload - the payload associated with the rectangle.
    • containsStream

      protected Stream<T> containsStream(com.github.davidmoten.rtreemulti.geometry.Point point)
      Which objects contain a particular point?
      Parameters:
      point - the point.
      Returns:
      a stream of payloads for all objects that contain point.
    • intersectsWithStream

      protected Stream<T> intersectsWithStream(com.github.davidmoten.rtreemulti.geometry.Rectangle rectangle)
      A stream of the elements that a rectangle intersects with.
      Parameters:
      rectangle - the rectangle associated with the payload.
      Returns:
      the stream.
    • remove

      protected void remove(com.github.davidmoten.rtreemulti.geometry.Rectangle rectangle, T payload)
      Removes a particular item from the r-tree, identified by its Rectangle and payload.

      If no entry can be found matching exactly the rectangle and entry, no change happens to the r-tree. No error is reported.

      If multiple entries exist that match exactly the rectangle and entry, then all entries are removed.

      Parameters:
      rectangle - the rectangle.
      payload - the payload.