Class StoredSetBasedResultSet<O>
- java.lang.Object
-
- com.googlecode.cqengine.resultset.ResultSet<O>
-
- com.googlecode.cqengine.resultset.stored.StoredResultSet<O>
-
- com.googlecode.cqengine.resultset.stored.StoredSetBasedResultSet<O>
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<O>
public class StoredSetBasedResultSet<O> extends StoredResultSet<O>
A ResultSet which is stored directly in an index, and supports additional methods to add and remove objects. This implementation wraps a backingSet
.- Author:
- Niall Gallagher
-
-
Constructor Summary
Constructors Constructor Description StoredSetBasedResultSet(Set<O> backingSet)
Constructor.StoredSetBasedResultSet(Set<O> backingSet, int retrievalCost)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(O o)
void
clear()
void
close()
Releases any resources or closes the transaction which was opened for this ResultSet.boolean
contains(O o)
Returns true if thisResultSet
contains the given object, false if it does not.int
getMergeCost()
Returns the size of the backing set.Query<O>
getQuery()
Returns the query for which this ResultSet provides results.QueryOptions
getQueryOptions()
Returns the query options associated with the query.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.Iterator<O>
iterator()
boolean
matches(O object)
Similar to theResultSet.contains(Object)
method, but checks for logical containment in the ResultSet as opposed to physical containment in the ResultSet.boolean
remove(O o)
int
size()
Returns the number of objects which would be returned by thisResultSet
if iterated.-
Methods inherited from class com.googlecode.cqengine.resultset.ResultSet
spliterator, stream, uniqueResult
-
-
-
-
Method Detail
-
contains
public boolean contains(O o)
Description copied from class:ResultSet
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 theResultSet.matches(Object)
method, which provides a similar function but often with better performance than this method.
-
matches
public boolean matches(O object)
Similar to theResultSet.contains(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 theResultSet.contains(Object)
method to make the determination. This method will perform better thanResultSet.contains(Object)
in cases where querying indexes is more expensive than querying attributes, which is usually the case. This implementation delegates tocontains(Object)
.
-
add
public boolean add(O o)
- Specified by:
add
in classStoredResultSet<O>
-
remove
public boolean remove(O o)
- Specified by:
remove
in classStoredResultSet<O>
-
isEmpty
public boolean isEmpty()
Description copied from class:ResultSet
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.- Specified by:
isEmpty
in classStoredResultSet<O>
- Returns:
- True if this
ResultSet
if iterated would not return any objects; false if theResultSet
would return objects
-
isNotEmpty
public boolean isNotEmpty()
Description copied from class:ResultSet
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.- Specified by:
isNotEmpty
in classStoredResultSet<O>
- Returns:
- True if this
ResultSet
if iterated would return some objects; false if theResultSet
would not return any objects
-
clear
public void clear()
- Specified by:
clear
in classStoredResultSet<O>
-
size
public int size()
Description copied from class:ResultSet
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.
-
getRetrievalCost
public int getRetrievalCost()
Description copied from class:ResultSet
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.- Specified by:
getRetrievalCost
in classResultSet<O>
- Returns:
- An estimate of the cost of looking up a particular query in the index
-
getMergeCost
public int getMergeCost()
Returns the size of the backing set.- Specified by:
getMergeCost
in classResultSet<O>
- Returns:
- the size of the backing set
-
close
public void close()
Description copied from class:ResultSet
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.
-
getQuery
public Query<O> getQuery()
Description copied from class:ResultSet
Returns the query for which this ResultSet provides results.
-
getQueryOptions
public QueryOptions getQueryOptions()
Description copied from class:ResultSet
Returns the query options associated with the query.- Specified by:
getQueryOptions
in classResultSet<O>
- Returns:
- The query options associated with the query.
-
-