org.springframework.data.domain

## 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
See Also:
  Serialized Form

### Nested Class Summary

Nested Classes
`static class` `Sort.Direction` Enumeration for sort directions.
`static class` `Sort.NullHandling` Enumeration for null handling hints that can be used in `Sort.Order` expressions.
`static class` `Sort.Order` PropertyPath implements the pairing of an `Sort.Direction` and a property.
`static class` `Sort.TypedSort<T>` Extension of Sort to use method handles to define properties to sort by.

### Field Summary

Fields
`static Sort.Direction` `DEFAULT_DIRECTION`

### Constructor Summary

Constructors
`protected` `Sort(List<Sort.Order> orders)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`Sort` `and(Sort sort)` Returns a new `Sort` consisting of the `Sort.Order`s of the current `Sort` combined with the given ones.
`Sort` `ascending()` Returns a new `Sort` with the current setup but ascending order direction.
`static Sort` `by(List<Sort.Order> orders)` Creates a new `Sort` for the given `Sort.Order`s.
`static Sort` `by(Sort.Direction direction, String... properties)` Creates a new `Sort` for the given `Sort.Order`s.
`static Sort` `by(Sort.Order... orders)` Creates a new `Sort` for the given `Sort.Order`s.
`static Sort` `by(String... properties)` Creates a new `Sort` for the given properties.
`Sort` `descending()` Returns a new `Sort` with the current setup but descending order direction.
`boolean` `equals(Object obj)`
`Sort.Order` `getOrderFor(String property)` Returns the order registered for the given property.
`int` `hashCode()`
`boolean` `isSorted()`
`boolean` `isUnsorted()`
`Iterator<Sort.Order>` `iterator()`
`static <T> Sort.TypedSort<T>` `sort(Class<T> type)` Creates a new `Sort.TypedSort` for the given type.
`String` `toString()`
`static Sort` `unsorted()` Returns a `Sort` instances representing no sorting setup at all.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.data.util.Streamable

`and, and, and, and, empty, filter, flatMap, get, isEmpty, map, of, of, of, stream, toList, toSet, toStreamable, toStreamable`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Field Detail

#### DEFAULT_DIRECTION

    public static final Sort.Direction DEFAULT_DIRECTION

### Constructor Detail

#### Sort

    protected Sort(List<Sort.Order> orders)

### Method Detail

#### 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.Order`s.

Parameters:
  `orders` - must not be null.
Returns:

#### by

    public static Sort by(Sort.Order... orders)

Creates a new `Sort` for the given `Sort.Order`s.

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.Order`s.

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()

#### isUnsorted

    public boolean isUnsorted()

#### and

    public Sort and(Sort sort)

Returns a new `Sort` consisting of the `Sort.Order`s 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`