Package dev.morphia.query
Class Sort
- java.lang.Object
-
- dev.morphia.query.Sort
-
public class Sort extends Object
Used for sorting query results or defining a sort stage in an aggregation pipeline- Since:
- 1.3
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Sort
ascending(String field)
Creates an ascending sort on a fieldstatic Sort
descending(String field)
Creates a descending sort on a fieldString
getField()
int
getOrder()
Returns the sort order.static Sort
naturalAscending()
Creates an ascending sort on a fieldstatic Sort
naturalDescending()
Creates a descending natural sort on a field
-
-
-
Constructor Detail
-
Sort
protected Sort(String field, int order)
Creates a sort on a field with a direction.- 1 to specify ascending order.
- -1 to specify descending order.
- Parameters:
field
- the fieldorder
- the order
-
-
Method Detail
-
ascending
public static Sort ascending(String field)
Creates an ascending sort on a field- Parameters:
field
- the field- Returns:
- the Sort instance
-
descending
public static Sort descending(String field)
Creates a descending sort on a field- Parameters:
field
- the field- Returns:
- the Sort instance
-
naturalAscending
public static Sort naturalAscending()
Creates an ascending sort on a field- Returns:
- the Sort instance
-
naturalDescending
public static Sort naturalDescending()
Creates a descending natural sort on a field- Returns:
- the Sort instance
-
getOrder
public int getOrder()
Returns the sort order.- 1 for ascending order.
- -1 for descending order.
- Returns:
- the sort order
-
getField
public String getField()
- Returns:
- the sort field
-
-