Class Cursor

java.lang.Object
com.helixframework.pagination.cursor.Cursor
All Implemented Interfaces:
Serializable, Iterable<Criterion>

public class Cursor extends Object implements Iterable<Criterion>, Serializable
Bidirectional pagination cursor that supports multiple key and sorting criteria.
See Also:
  • Method Details

    • builder

      public static Cursor.Builder builder()
      Returns a builder for Cursor.
      Returns:
      builder
    • builder

      public static Cursor.Builder builder(Cursor prevCursor)
      Returns a builder for Cursor configured with the previous cursor's criteria.
      Parameters:
      prevCursor - previous cursor
      Returns:
      builder
    • parse

      public static Cursor parse(String token)
      Parses a token and returns a Cursor.
      Parameters:
      token - the token to parse
      Returns:
      the parsed Cursor object
      Throws:
      IllegalArgumentException - if there is an error parsing the token
    • next

      public static <T> Optional<Cursor> next(Cursor prevCursor, int limit, Class<T> resultType, List<T> results)
      Retrieves the next cursor given the previous cursor, limit, result type, and results list.
      Type Parameters:
      T - The type of the results
      Parameters:
      prevCursor - The previous cursor
      limit - The limit of results per page
      resultType - The type of the result
      results - The list of results
      Returns:
      An Optional wrapping the next cursor if it exists, otherwise Optional.empty()
    • next

      public static <T> Optional<Cursor> next(Cursor prevCursor, int limit, Class<T> resultType, List<T> results, Function<T,List<Criterion>> fn)
      Retrieves the next cursor given the previous cursor, limit, results, function, and class.
      Type Parameters:
      T - The type of the results
      Parameters:
      prevCursor - The previous cursor
      limit - The limit of results per page
      resultType - The type of the result
      results - The list of results
      fn - The function to generate the next cursor
      Returns:
      An Optional wrapping the next cursor if it exists, otherwise Optional.empty()
    • getCriteria

      public Map<String,Criterion> getCriteria()
      Returns an unmodifiable map of criteria stored in the Cursor.
      Returns:
      an unmodifiable map of criteria
    • getCriterion

      public Optional<Criterion> getCriterion(String name)
      Retrieves a criterion with the given name.
      Parameters:
      name - the name of the criterion to retrieve
      Returns:
      an Optional wrapping the criterion if it exists, otherwise Optional.empty()
    • getCriterionValue

      public Optional<String> getCriterionValue(String name)
      Retrieves the value of the criterion with the given name.
      Parameters:
      name - the name of the criterion to retrieve the value for
      Returns:
      an Optional wrapping the criterion value if the criterion exists, otherwise Optional.empty()
    • getCriterionSortOrder

      public Optional<com.helixframework.pagination.sort.SortOrder> getCriterionSortOrder(String name)
      Retrieves the sort order associated of the criterion with the given name.
      Parameters:
      name - the name of the criterion
      Returns:
      an Optional object wrapping the SortOrder if the criterion exists, otherwise Optional.empty()
    • keySet

      public Set<String> keySet()
      Returns a set of keys representing the criteria.
      Returns:
      a set of keys representing the criteria
    • size

      public long size()
      Returns the number of criteria.
      Returns:
      the size of the criteria
    • getDirection

      public Cursor.Direction getDirection()
      Returns the direction of the cursor.
      Returns:
      the direction of the cursor
    • iterator

      public Iterator<Criterion> iterator()
      Specified by:
      iterator in interface Iterable<Criterion>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object