Interface NearestFinder<T>

Type Parameters:
T - The type of elements
All Known Implementing Classes:
ExhaustiveGeoLocationNearestFinderImpl, TwoDTree

public interface NearestFinder<T>
An object which can be used to find the nearest match within a predetermined set of elements. A NearestFinder cannot refer to an empty set.
Author:
Lee A. Christie
  • Method Summary

    Modifier and Type
    Method
    Description
    default NearestFinder<T>
    Returns a cached version of the finder.
    default NearestFinder<T>
    cache(Map<T,T> cache)
    Returns a cached version of the finder seeded with the specified starting map.
    default NearestFinder<T>
    Returns a thread-safe cached version of the finder.
    default NearestFinder<T>
    Returns a thread-safe cached version of the finder seeded with the specified starting map.
    default Map<T,T>
    nearest(Collection<T> targets)
    Returns the element which is nearest to a target, for a collection of specified targets.
    default Map<T,T>
    nearest(Collection<T> targets, ProgressListener progress, boolean subStageOnly)
    Returns the element which is nearest to a target, for a collection of specified targets.
    nearest(T target)
    Returns the element which is nearest to the specified target.
    default Optional<T>
    nearestOrEmpty(T target)
    Returns an optional containing the element which is nearest to a target, for a collection of specified targets.
  • Method Details

    • nearest

      T nearest(T target)
      Returns the element which is nearest to the specified target.
      Parameters:
      target - the target, not null
      Returns:
      the nearest match
      Throws:
      NoSuchElementException - if there is no nearest element
    • nearest

      default Map<T,T> nearest(Collection<T> targets) throws InterruptedException
      Returns the element which is nearest to a target, for a collection of specified targets.
      Parameters:
      targets - the targets, not null
      Returns:
      a mapping of targets to the nearest matches
      Throws:
      InterruptedException - if the thread is interrupted while matching the points to neighbours
    • nearestOrEmpty

      default Optional<T> nearestOrEmpty(T target)
      Returns an optional containing the element which is nearest to a target, for a collection of specified targets.
      Parameters:
      target - the target, not null
      Returns:
      a mapping of targets to the nearest matches or Optional.empty if there is no nearest element
    • nearest

      default Map<T,T> nearest(Collection<T> targets, ProgressListener progress, boolean subStageOnly) throws InterruptedException
      Returns the element which is nearest to a target, for a collection of specified targets.
      Parameters:
      targets - the targets, not null
      progress - listener for the progress between 0.0 and 1.0, not null
      subStageOnly - if ture, will not call onNewStage or onCompletion on the progress listener
      Returns:
      a mapping of targets to the nearest matches
      Throws:
      InterruptedException - if the thread is interrupted while matching the points to neighbours
    • cache

      default NearestFinder<T> cache()
      Returns a cached version of the finder.
      Returns:
      a cached version of the finder
    • cache

      default NearestFinder<T> cache(Map<T,T> cache)
      Returns a cached version of the finder seeded with the specified starting map. Elements in the starting map take priority over the backing finder.
      Parameters:
      cache - the cache to wrap, not null
      Returns:
      a cached version of the finder
    • concurrentCache

      default NearestFinder<T> concurrentCache()
      Returns a thread-safe cached version of the finder.
      Returns:
      a thread-safe cached version of the finder
    • concurrentCache

      default NearestFinder<T> concurrentCache(Map<T,T> cache)
      Returns a thread-safe cached version of the finder seeded with the specified starting map. Elements in the starting map take priority over the backing finder.
      Parameters:
      cache - the cache to wrap, not null
      Returns:
      a thread-safe cached version of the finder