Class Sort

java.lang.Object
org.springframework.data.domain.Sort
All Implemented Interfaces:
Serializable, Iterable<Sort.Order>, Supplier<Stream<Sort.Order>>, Streamable<Sort.Order>
Direct Known Subclasses:
QSort, RevisionSort, Sort.TypedSort

public class Sort extends Object implements Streamable<Sort.Order>, Serializable
Sort option for queries. You have to provide at least a list of properties to sort for that must not include null or empty strings. The direction defaults to DEFAULT_DIRECTION.
Author:
Oliver Gierke, Thomas Darimont, Mark Paluch, Johannes Englmeier
See Also:
  • Field Details

    • DEFAULT_DIRECTION

      public static final Sort.Direction DEFAULT_DIRECTION
  • Constructor Details

  • Method Details

    • by

      public static Sort by(String... properties)
      Creates a new Sort for the given properties.
      Parameters:
      properties - must not be null.
      Returns:
    • by

      public static Sort by(List<Sort.Order> orders)
      Creates a new Sort for the given Sort.Orders.
      Parameters:
      orders - must not be null.
      Returns:
    • by

      public static Sort by(Sort.Order... orders)
      Creates a new Sort for the given Sort.Orders.
      Parameters:
      orders - must not be null.
      Returns:
    • by

      public static Sort by(Sort.Direction direction, String... properties)
      Creates a new Sort for the given Sort.Direction and properties.
      Parameters:
      direction - must not be null.
      properties - must not be null.
      Returns:
    • sort

      public static <T> Sort.TypedSort<T> sort(Class<T> type)
      Creates a new Sort.TypedSort for the given type.
      Parameters:
      type - must not be null.
      Returns:
      Since:
      2.2
    • unsorted

      public static Sort unsorted()
      Returns a Sort instances representing no sorting setup at all.
      Returns:
    • descending

      public Sort descending()
      Returns a new Sort with the current setup but descending order direction.
      Returns:
    • ascending

      public Sort ascending()
      Returns a new Sort with the current setup but ascending order direction.
      Returns:
    • isSorted

      public boolean isSorted()
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Streamable
      Returns whether the current Streamable is empty.
      Specified by:
      isEmpty in interface Streamable<Sort.Order>
      Returns:
    • isUnsorted

      public boolean isUnsorted()
    • and

      public Sort and(Sort sort)
      Returns a new Sort consisting of the Sort.Orders of the current Sort combined with the given ones.
      Parameters:
      sort - must not be null.
      Returns:
    • getOrderFor

      @Nullable public Sort.Order getOrderFor(String property)
      Returns the order registered for the given property.
      Parameters:
      property -
      Returns:
    • iterator

      public Iterator<Sort.Order> iterator()
      Specified by:
      iterator in interface Iterable<Sort.Order>
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object