Class QueryResult<T>

java.lang.Object
com.helixframework.db.repository.QueryResult<T>
Type Parameters:
T - the type of elements in the query result
All Implemented Interfaces:
Iterable<T>

public class QueryResult<T> extends Object implements Iterable<T>
Represents a query result containing a list of results of type T.
  • Constructor Details

    • QueryResult

      public QueryResult(List<T> results)
      Constructs a QueryResult object with the provided list of results.
      Parameters:
      results - the list of results to be added to the QueryResult object
    • QueryResult

      public QueryResult(T result)
      Constructs a QueryResult object with a single result provided in the parameter.
      Parameters:
      result - the single result to be added to the QueryResult object
  • Method Details

    • iterator

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

      public List<T> getList()
      Returns the list of results contained in this QueryResult object.
      Returns:
      the list of results
    • getSingle

      public Optional<T> getSingle()
      Retrieves the single result from the QueryResult as an Optional. If there are no results, an empty Optional is returned. If there is more than one result, an IllegalStateException is thrown.
      Returns:
      an Optional containing the single result, empty if none
      Throws:
      IllegalStateException - if more than one result is present
    • isEmpty

      public boolean isEmpty()
      Checks if the QueryResult object is empty.
      Returns:
      true if the QueryResult object contains no results, false otherwise
    • size

      public int size()
      Returns the number of results in this QueryResult object.
      Returns:
      the size of the results list
    • stream

      public Stream<T> stream()
      Returns a Stream of elements contained in this QueryResult object.
      Returns:
      a stream of elements
    • toList

      public List<T> toList()
      Returns the results of this QueryResult object as a new ArrayList.
      Returns:
      a new ArrayList containing the results of this QueryResult object