public class SearchResults<E extends GeospatialPoint> extends PriorityQueue<E>
The SearchResults
class is a fixed-size PriorityQueue
subclass that may or may not accept points that are offered to it based on
several criteria. SearchResults
instances are always created with a
reference to a query point and a prescribed size; when points are offered via
the add(E)
or addAll(java.util.Collection<? extends E>)
methods, the
SearchResults
instance will accept the point if and only if the
following conditions are met:
SearchResults
instance contains fewer points than its
maximum capacity or the offered point is closer to the query point
than the most distant point already in the queue.SearchResults
objects use an internal reverse geospatial distance
comparator; this ensures that the point at the head of the queue is always
the most distant point from the query point.
Constructor and Description |
---|
SearchResults(GeospatialPoint queryPoint,
int maxSize)
Constructs a new search result collector that collects up to
maxSize points. |
SearchResults(GeospatialPoint queryPoint,
int maxSize,
double maxDistance)
Constructs a new search result collector that collects up to
maxSize points that fall within the given distance to the query
point. |
SearchResults(GeospatialPoint queryPoint,
int maxSize,
double maxDistance,
SearchCriteria<E> criteria)
Constructs a new search result collector that collects up to
maxSize points that fall within the given distance to the query
point and meet the given search criteria. |
SearchResults(GeospatialPoint queryPoint,
int maxSize,
SearchCriteria<E> criteria)
Constructs a new search result collector that collects up to
maxSize points that meet the given search criteria. |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E point)
Offers a point to this result set.
|
boolean |
addAll(Collection<? extends E> points)
Offers all of the points in the given collection to this result set.
|
double |
getLongestDistanceFromQueryPoint()
Returns the distance from the query point provided at construction time
to the most distant point in this result set.
|
List<E> |
toSortedList()
Returns a list of the points in this result set sorted in order of
increasing distance from the query point provided at construction time.
|
clear, comparator, contains, iterator, offer, peek, poll, remove, size, toArray, toArray
element, remove
containsAll, isEmpty, removeAll, retainAll, toString
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
containsAll, equals, hashCode, isEmpty, removeAll, retainAll
public SearchResults(GeospatialPoint queryPoint, int maxSize)
maxSize
points.queryPoint
- the point to use as the origin of all distance calculationsmaxSize
- the maximum number of points this result set may containpublic SearchResults(GeospatialPoint queryPoint, int maxSize, double maxDistance)
maxSize
points that fall within the given distance to the query
point.queryPoint
- the point to use as the origin of all distance calculationsmaxSize
- the maximum number of points this result set may containmaxDistance
- the maximum allowable distance from the query point; points
more distant than this threshold will always be rejectedpublic SearchResults(GeospatialPoint queryPoint, int maxSize, SearchCriteria<E> criteria)
maxSize
points that meet the given search criteria.queryPoint
- the point to use as the origin of all distance calculationsmaxSize
- the maximum number of points this result set may containcriteria
- the search criteria to be met by all points included in this
result set; points that do not meet the search criteria will
always be rejectedpublic SearchResults(GeospatialPoint queryPoint, int maxSize, double maxDistance, SearchCriteria<E> criteria)
maxSize
points that fall within the given distance to the query
point and meet the given search criteria.queryPoint
- the point to use as the origin of all distance calculationsmaxSize
- the maximum number of points this result set may containmaxDistance
- the maximum allowable distance from the query point; points
more distant than this threshold will always be rejectedcriteria
- the search criteria to be met by all points included in this
result set; points that do not meet the search criteria will
always be rejectedpublic boolean add(E point)
add
in interface Collection<E extends GeospatialPoint>
add
in interface Queue<E extends GeospatialPoint>
add
in class PriorityQueue<E extends GeospatialPoint>
point
- the point to offer to this result settrue
if the point was added to this result set or
false
otherwisepublic boolean addAll(Collection<? extends E> points)
addAll
in interface Collection<E extends GeospatialPoint>
addAll
in class AbstractQueue<E extends GeospatialPoint>
points
- the collection of points to add to this queuetrue
if any of the offered points were added to this
result set or false
otherwiseIllegalArgumentException
- if the specified collection is this result setadd(GeospatialPoint)
public double getLongestDistanceFromQueryPoint()
Double.POSITIVE_INFINITY
if
this result set is emptyjeospatial is an open-source library hosted at https://github.com/jchambers/jeospatial.