Class ResultSet<O>
- java.lang.Object
-
- com.googlecode.cqengine.resultset.ResultSet<O>
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<O>
- Direct Known Subclasses:
CloseableResultSet
,DeduplicatingResultSet
,FilteringResultSet
,ObjectStoreResultSet
,ResultSetDifference
,ResultSetIntersection
,ResultSetUnion
,ResultSetUnionAll
,StoredResultSet
,WrappedResultSet
public abstract class ResultSet<O> extends Object implements Iterable<O>, Closeable
- Author:
- Niall Gallagher
-
-
Constructor Summary
Constructors Constructor Description ResultSet()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
close()
Releases any resources or closes the transaction which was opened for this ResultSet.abstract boolean
contains(O object)
Returns true if thisResultSet
contains the given object, false if it does not.abstract int
getMergeCost()
Returns an estimate of the cost of merging (or otherwise processing) objects matching the query.abstract Query<O>
getQuery()
Returns the query for which this ResultSet provides results.abstract QueryOptions
getQueryOptions()
Returns the query options associated with the query.abstract int
getRetrievalCost()
Returns an estimate of the cost of looking up objects matching the query underlying thisResultSet
in the index.boolean
isEmpty()
Checks if thisResultSet
if iterated would not return any objects (i.e.boolean
isNotEmpty()
Checks if thisResultSet
if iterated would return some objects (i.e.abstract Iterator<O>
iterator()
abstract boolean
matches(O object)
Similar to thecontains(Object)
method, but checks for logical containment in the ResultSet as opposed to physical containment in the ResultSet.abstract int
size()
Returns the number of objects which would be returned by thisResultSet
if iterated.Spliterator<O>
spliterator()
Creates aSpliterator
over objects matching the query for which thisResultSet
was constructed.Stream<O>
stream()
O
uniqueResult()
Returns the first object returned by the iterator of thisResultSet
, and throws an exception if the iterator does not provide exactly one object.
-
-
-
Method Detail
-
contains
public abstract boolean contains(O object)
Returns true if thisResultSet
contains the given object, false if it does not. Note that the cost of calling this method will most likely be cheaper than iterating all results to check if an object is contained. If indexes are available to support the query, this method will query indexes to check if the object is contained, instead of actually retrieving any data. See also thematches(Object)
method, which provides a similar function but often with better performance than this method.
-
matches
public abstract boolean matches(O object)
Similar to thecontains(Object)
method, but checks for logical containment in the ResultSet as opposed to physical containment in the ResultSet. Determines if the given object would be contained in the ResultSet, by testing if the given object matches the query for which this ResultSet was generated, instead of actually checking if the object is contained in appropriate indexes. This method will typically make the determination by evaluating the query on the given object on-the-fly without accessing indexes, however in some cases this method might delegate to thecontains(Object)
method to make the determination. This method will perform better thancontains(Object)
in cases where querying indexes is more expensive than querying attributes, which is usually the case.
-
getQuery
public abstract Query<O> getQuery()
Returns the query for which this ResultSet provides results.- Returns:
- The query for which this ResultSet provides results.
-
getQueryOptions
public abstract QueryOptions getQueryOptions()
Returns the query options associated with the query.- Returns:
- The query options associated with the query.
-
uniqueResult
public O uniqueResult()
Returns the first object returned by the iterator of thisResultSet
, and throws an exception if the iterator does not provide exactly one object.- Returns:
- The first object returned by the iterator of this
ResultSet
- Throws:
NoSuchObjectException
- If the iterator indicates no object is availableNonUniqueObjectException
- If the iterator indicates more than one object is available
-
getRetrievalCost
public abstract int getRetrievalCost()
Returns an estimate of the cost of looking up objects matching the query underlying thisResultSet
in the index. The query engine will use this to select the index with the lowest cost, when more than one index supporting the query exists for the same attribute. An example: a single-level hash index will typically have a lower retrieval cost than a tree-based index. Of course a hash index only supports equality-based retrieval whereas a sorted tree-based index might support equality/less than/greater than or range based retrieval. But for an equality-based query, supported by both indexes, retrieval cost allows the query engine to prefer the hash index.- Returns:
- An estimate of the cost of looking up a particular query in the index
-
getMergeCost
public abstract int getMergeCost()
Returns an estimate of the cost of merging (or otherwise processing) objects matching the query. This will typically be based on the number of objects matching the query.- If the query specifies a simple retrieval from an index, this might be the number of objects matching the query
- If the query specifies a union between multiple other sub-queries, this might be the sum of their merge costs
- If the query specifies an intersection, this might be the based on the merge cost of the sub-query with the lowest merge cost
- Returns:
- An estimate of the cost of merging (or otherwise processing) objects matching a query
-
size
public abstract int size()
Returns the number of objects which would be returned by thisResultSet
if iterated. Note that the cost of calling this method depends on the query for which it was constructed. For simple queries where a single query is supplied and a matching index exists, or where several such simple queries are supplied and are connected using a simpleOr
query, calculating the size via this method will be cheaper than iterating through the ResultSet and counting the number of objects individually. For more complex queries, where intersections must be performed or where no suitable indexes exist, calling this method can be non-trivial, but it will always be at least as cheap as iterating through the ResultSet and counting the number of objects individually.- Returns:
- The number of objects which would be returned by this
ResultSet
if iterated
-
isEmpty
public boolean isEmpty()
Checks if thisResultSet
if iterated would not return any objects (i.e. the query does not match any objects). This method can be more efficient than calling#size()
to check simply if no objects would be returned.- Returns:
- True if this
ResultSet
if iterated would not return any objects; false if theResultSet
would return objects
-
isNotEmpty
public boolean isNotEmpty()
Checks if thisResultSet
if iterated would return some objects (i.e. the query matches some objects). This method can be more efficient than calling#size()
to check simply if some objects would be returned.- Returns:
- True if this
ResultSet
if iterated would return some objects; false if theResultSet
would not return any objects
-
close
public abstract void close()
Releases any resources or closes the transaction which was opened for this ResultSet. Whether or not it is necessary to close the ResultSet depends on which implementation of IndexedCollection is in use and the types of indexes added to it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
spliterator
public Spliterator<O> spliterator()
Creates aSpliterator
over objects matching the query for which thisResultSet
was constructed.- Specified by:
spliterator
in interfaceIterable<O>
- Returns:
- a
Spliterator
over objects matching the query for which thisResultSet
was constructed
-
-