Class CollectionCursor<T>

java.lang.Object
com.datastax.astra.client.collections.commands.cursor.CollectionCursor<T>
Type Parameters:
T - type of the table
All Implemented Interfaces:
Closeable, AutoCloseable, Cloneable, Iterable<T>

public class CollectionCursor<T> extends Object implements Iterable<T>, Closeable, Cloneable
Implementation of a cursor across the find items
  • Constructor Details

    • CollectionCursor

      public CollectionCursor(Collection<T> col, Filter filter, CollectionFindOptions options)
      Cursor to iterate on the result of a query.
      Parameters:
      col - source collection
      filter - current filter
      options - options of the find operation
  • Method Details

    • clone

      public CollectionCursor<T> clone()
      Overrides:
      clone in class Object
    • filter

      public CollectionCursor<T> filter(Filter newFilter)
      Immutable methods that return a new Cursor instance.
      Parameters:
      newFilter - a new filter
      Returns:
      a new CollectionCursor instance with the filter applied
    • project

      public CollectionCursor<T> project(Projection... newProjection)
      Immutable methods that return a new Cursor instance.
      Parameters:
      newProjection - a new projection
      Returns:
      a new CollectionCursor instance with the projection applied
    • sort

      public CollectionCursor<T> sort(Sort... sort)
      Applies a sorting order to the cursor. Creates a new instance of the cursor with the specified sort options applied.
      Parameters:
      sort - the sort options to apply
      Returns:
      a new CollectionCursor instance with the sorting applied
      Throws:
      IllegalStateException - if the cursor is not in an idle state
    • limit

      public CollectionCursor<T> limit(int newLimit)
      Sets a limit on the number of results returned by the cursor. Creates a new instance of the cursor with the specified limit applied.
      Parameters:
      newLimit - the maximum number of results to return
      Returns:
      a new CollectionCursor instance with the limit applied
      Throws:
      IllegalStateException - if the cursor is not in an idle state
    • skip

      public CollectionCursor<T> skip(int newSkip)
      Skips the specified number of results. Creates a new instance of the cursor with the specified skip applied.
      Parameters:
      newSkip - the number of results to skip
      Returns:
      a new CollectionCursor instance with the skip applied
      Throws:
      IllegalStateException - if the cursor is not in an idle state
    • includeSimilarity

      public CollectionCursor<T> includeSimilarity()
      Includes similarity information in the results. Creates a new instance of the cursor with similarity information included.
      Returns:
      a new CollectionCursor instance with similarity information included
      Throws:
      IllegalStateException - if the cursor is not in an idle state
    • includeSortVector

      public CollectionCursor<T> includeSortVector()
      Includes sort vector information in the results. Creates a new instance of the cursor with sort vector information included.
      Returns:
      a new CollectionCursor instance with sort vector information included
      Throws:
      IllegalStateException - if the cursor is not in an idle state
    • close

      public void close()
      Change the state of the cursor to close.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • consumeBuffer

      public List<T> consumeBuffer(int n)
      Consume the buffer and return the results.
      Parameters:
      n - consume n elements from the buffer
      Returns:
      list of results
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • hasNext

      public boolean hasNext()
      Check if there is a next element.
      Returns:
      true if there is a next element
    • next

      public T next()
      Retrieve the next element.
      Returns:
      next element
    • toList

      public List<T> toList()
      Retrieve all the elements in a list.
      Returns:
      list of elements
    • getBufferedCount

      public int getBufferedCount()
      Access the size of the buffer.
      Returns:
      buffer count
    • getKeyspace

      public String getKeyspace()
      Retrieve keyspace name.
      Returns:
      keyspace name