Package org.bremersee.comparator.model
Class SortOrder
- java.lang.Object
-
- org.bremersee.comparator.model.SortOrder
-
@Valid public class SortOrder extends Object
This class defines the sort order of a field.--------------------------------------------------------------------------------------------- | Attribute | Description | Default | |--------------|-------------------------------------------------------------------|----------| | field | The field name (or method name) of the object. It can be a path. | null | | | The segments are separated by a dot (.): field0.field1.field2 | | | | It can be null. Then the object itself must be comparable. | | |--------------|-------------------------------------------------------------------|----------| | asc or desc | Defines ascending or descending ordering. | asc | |--------------|-------------------------------------------------------------------|----------| | ignoreCase | Makes a case ignoring comparison (only for strings). | true | |--------------|-------------------------------------------------------------------|----------| | nullIsFirst | Defines the ordering if one of the values is null. | false | ---------------------------------------------------------------------------------------------
These values have a 'sort oder text' representation. The values are concatenated with comma (,):
fieldNameOrPath,asc,ignoreCase,nullIsFirst
For example:
properties.customSettings.priority,asc,true,false
Defaults can be omitted. This is the same:
properties.customSettings.priority
The building of a chain is done by concatenate the fields with a semicolon (;):
field0,asc,ignoreCase,nullIsFirst;field1,asc,ignoreCase,nullIsFirst
- Author:
- Christian Bremer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSortOrder.CaseHandlingThe case handling.static classSortOrder.DirectionThe direction.static classSortOrder.NullHandlingThe null handling.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SortOrderby(String field)Creates a new sort order for the given field.static SortOrderfromSortOrderText(String source)From sort order text.static SortOrderfromSortOrderText(String source, SortOrdersTextProperties properties)From sort order text.StringgetField()Gets field name or path.booleanisAsc()Is ascending or descending order.booleanisIgnoreCase()Is case-insensitive or case-sensitive order.booleanisNullIsFirst()Is null is first.@NotEmpty StringtoSortOrderText()Creates the sort order text of this ordering description.@NotEmpty StringtoSortOrderText(SortOrdersTextProperties properties)Creates the sort order text of this ordering description.StringtoString()SortOrderwith(SortOrder.CaseHandling caseHandling)With given case handling.SortOrderwith(SortOrder.Direction direction)With given direction.SortOrderwith(SortOrder.NullHandling nullHandling)With given null handling.
-
-
-
Constructor Detail
-
SortOrder
protected SortOrder()
Instantiates a new sort order.
-
SortOrder
public SortOrder(String field, boolean asc, boolean ignoreCase, boolean nullIsFirst)
Instantiates a new sort order.- Parameters:
field- the field name or path (can benull)asc-truefor an ascending order,falsefor a descending orderignoreCase-truefor a case insensitive order,falsefor a case sensitive ordernullIsFirst- specifies the order ofnullvalues
-
-
Method Detail
-
getField
public String getField()
Gets field name or path.- Returns:
- the field name or path
-
isAsc
public boolean isAsc()
Is ascending or descending order.- Returns:
trueif ascending order,falseif descending order
-
isIgnoreCase
public boolean isIgnoreCase()
Is case-insensitive or case-sensitive order.- Returns:
trueif case insensitive order,falseif case sensitive order
-
isNullIsFirst
public boolean isNullIsFirst()
Is null is first.- Returns:
trueif null is first, otherwisefalse
-
with
public SortOrder with(SortOrder.Direction direction)
With given direction.- Parameters:
direction- the direction- Returns:
- the sort order
-
with
public SortOrder with(SortOrder.CaseHandling caseHandling)
With given case handling.- Parameters:
caseHandling- the case handling- Returns:
- the sort order
-
with
public SortOrder with(SortOrder.NullHandling nullHandling)
With given null handling.- Parameters:
nullHandling- the null handling- Returns:
- the sort order
-
toSortOrderText
@NotEmpty public @NotEmpty String toSortOrderText()
Creates the sort order text of this ordering description.The syntax of the ordering description is
fieldNameOrPath,asc,ignoreCase,nullIsFirst
For example
person.lastName,asc,true,false
- Returns:
- the sort order text
-
toSortOrderText
@NotEmpty public @NotEmpty String toSortOrderText(SortOrdersTextProperties properties)
Creates the sort order text of this ordering description.The syntax of the ordering description is
fieldNameOrPath,asc,ignoreCase,nullIsFirst
The separator (',') and the values of
direction,case-handlingandnull-handlingdepend on the givenSortOrdersTextProperties.For example with default properties:
person.lastName,asc,true,false
- Parameters:
properties- the properties (can benull- Returns:
- the sort order text
-
by
public static SortOrder by(String field)
Creates a new sort order for the given field.- Parameters:
field- the field- Returns:
- the sort order
-
fromSortOrderText
public static SortOrder fromSortOrderText(String source)
From sort order text.- Parameters:
source- the sort order text- Returns:
- the sort order
-
fromSortOrderText
public static SortOrder fromSortOrderText(String source, SortOrdersTextProperties properties)
From sort order text.- Parameters:
source- the sort order textproperties- the properties- Returns:
- the sort order
-
-