Package 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
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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration for sort directions.static enum
Enumeration for null handling hints that can be used inSort.Order
expressions.static class
PropertyPath implements the pairing of anSort.Direction
and a property.static class
Extension of Sort to use method handles to define properties to sort by. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns a newSort
with the current setup but ascending order direction.static Sort
Creates a newSort
for the given properties.static Sort
by
(List<Sort.Order> orders) Creates a newSort
for the givenSort.Order
s.static Sort
by
(Sort.Direction direction, String... properties) Creates a newSort
for the givenSort.Direction
and properties.static Sort
by
(Sort.Order... orders) Creates a newSort
for the givenSort.Order
s.Returns a newSort
with the current setup but descending order direction.protected List<Sort.Order>
boolean
getOrderFor
(String property) Returns the order registered for the given property.int
hashCode()
boolean
isEmpty()
Returns whether the currentStreamable
is empty.boolean
isSorted()
boolean
iterator()
reverse()
Returns a newSort
with reversed sortSort.Order
s turning effectively asccending into descending sort order and vice versa.static <T> Sort.TypedSort<T>
Creates a newSort.TypedSort
for the given type.toString()
static Sort
unsorted()
Returns aSort
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 java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_DIRECTION
-
-
Constructor Details
-
Sort
-
-
Method Details
-
by
Creates a newSort
for the given properties.- Parameters:
properties
- must not be null.- Returns:
Sort
for the given properties.
-
by
Creates a newSort
for the givenSort.Order
s.- Parameters:
orders
- must not be null.- Returns:
Sort
for the givenSort.Order
s.
-
by
Creates a newSort
for the givenSort.Order
s.- Parameters:
orders
- must not be null.- Returns:
Sort
for the givenSort.Order
s.
-
by
Creates a newSort
for the givenSort.Direction
and properties.- Parameters:
direction
- must not be null.properties
- must not be null.- Returns:
Sort
for the givenSort.Direction
and properties.
-
sort
Creates a newSort.TypedSort
for the given type.- Parameters:
type
- must not be null.- Returns:
Sort.TypedSort
for the given type.- Since:
- 2.2
-
unsorted
Returns aSort
instances representing no sorting setup at all.- Returns:
- unsorted Sort instance.
-
descending
Returns a newSort
with the current setup but descending order direction.- Returns:
- a new
Sort
with the current setup but descending order direction.
-
ascending
Returns a newSort
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 currentStreamable
is empty.- Specified by:
isEmpty
in interfaceStreamable<Sort.Order>
- Returns:
-
isUnsorted
public boolean isUnsorted()- Returns:
- true if this Sort instance is unsorted, false otherwise.
-
and
- Parameters:
sort
- must not be null.- Returns:
- a new
Sort
consisting of theSort.Order
s of the currentSort
combined with the given ones.
-
reverse
Returns a newSort
with reversed sortSort.Order
s turning effectively asccending into descending sort order and vice versa.- Returns:
- a new
Sort
object with reversed sort orders applied. - Since:
- 3.1
-
doReverse
-
getOrderFor
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
- Specified by:
iterator
in interfaceIterable<Sort.Order>
-
equals
-
hashCode
public int hashCode() -
toString
-