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, Jan Kurella
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:
      Sort for the given properties.
    • 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:
      Sort for the given Sort.Orders.
    • by

      public static Sort by(Sort.Order... orders)
      Creates a new Sort for the given Sort.Orders.
      Parameters:
      orders - must not be null.
      Returns:
      Sort for the given Sort.Orders.
    • 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 for the given Sort.Direction and properties.
    • 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:
      Sort.TypedSort for the given type.
      Since:
      2.2
    • unsorted

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

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

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

      public boolean isSorted()
      Returns:
      true if this Sort instance is sorted, false otherwise.
    • 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()
      Returns:
      true if this Sort instance is unsorted, false otherwise.
    • 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:
      a new Sort consisting of the Sort.Orders of the current Sort combined with the given ones.
    • reverse

      public Sort reverse()
      Returns a new Sort with reversed sort Sort.Orders turning effectively asccending into descending sort order and vice versa.
      Returns:
      a new Sort object with reversed sort orders applied.
      Since:
      3.1
    • doReverse

      protected List<Sort.Order> doReverse()
    • getOrderFor

      @Nullable public Sort.Order getOrderFor(String property)
      Returns the order registered for the given property.
      Parameters:
      property - name of the property that should be sorted.
      Returns:
      the sort Sort.Order or null if the property is not sorted by.
    • 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