Package org.bremersee.comparator.model
Class SortOrderItem
java.lang.Object
org.bremersee.comparator.model.SortOrderItem
- All Implemented Interfaces:
Serializable
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 | null | | | path. The segments are separated by a dot (.): | | | | field0.field1.field2 | | | | It can be null. Then the object itself must be comparable. | | |--------------|----------------------------------------------------------------|-------------| | direction | Defines ascending or descending ordering. | asc | |--------------|----------------------------------------------------------------|-------------| | caseHandling | Makes a case ignoring comparison (only for strings). | insensitive | |--------------|----------------------------------------------------------------|-------------| | nullHandling | Defines the ordering if one of the values is null. | last | ---------------------------------------------------------------------------------------------
These values have a 'sort order text' representation. The values are concatenated with comma ',' (default):
fieldNameOrPath,direction,caseHandling,nullHandling
For example:
properties.customSettings.priority,asc,insensitive,nulls-first
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 ';' (default):
field0,desc;field1,desc
- Author:
- Christian Bremer
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe case-handling.static enumThe direction.static enumThe null-handling. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final SortOrderItem.CaseHandlingThe constant DEFAULT_CASE_HANDLING.protected static final SortOrderItem.DirectionThe constant DEFAULT_DIRECTION.protected static final SortOrderItem.NullHandlingThe constant DEFAULT_NULL_HANDLING.static final StringThe constant DEFAULT_SEPARATOR. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiates a new sort order item.SortOrderItem(String field, SortOrderItem.Direction direction, SortOrderItem.CaseHandling caseHandling, SortOrderItem.NullHandling nullHandling) Instantiates a new sort order item. -
Method Summary
Modifier and TypeMethodDescriptionstatic SortOrderItemCreates a new sort order for the given field.static SortOrderItemfromSortOrderText(String source) From sort order text.static SortOrderItemfromSortOrderText(String source, SortOrderTextSeparators separators) From sort order text.getField()Gets field (can benull).Creates the sort order text of this ordering description.getSortOrderText(SortOrderTextSeparators separators) Creates the sort order text of this ordering description.toString()with(SortOrderItem.CaseHandling caseHandling) With given case-handling.with(SortOrderItem.Direction direction) With given direction.with(SortOrderItem.NullHandling nullHandling) With given null-handling.
-
Field Details
-
DEFAULT_SEPARATOR
The constant DEFAULT_SEPARATOR.- See Also:
-
DEFAULT_DIRECTION
The constant DEFAULT_DIRECTION. -
DEFAULT_CASE_HANDLING
The constant DEFAULT_CASE_HANDLING. -
DEFAULT_NULL_HANDLING
The constant DEFAULT_NULL_HANDLING.
-
-
Constructor Details
-
SortOrderItem
protected SortOrderItem()Instantiates a new sort order item. -
SortOrderItem
public SortOrderItem(String field, SortOrderItem.Direction direction, SortOrderItem.CaseHandling caseHandling, SortOrderItem.NullHandling nullHandling) Instantiates a new sort order item.- Parameters:
field- the field name or path (can benull)direction- the directioncaseHandling- the case-handlingnullHandling- the null-handling
-
-
Method Details
-
getField
Gets field (can benull).- Returns:
- the field
-
with
With given direction.- Parameters:
direction- the direction- Returns:
- the new sort order
-
with
With given case-handling.- Parameters:
caseHandling- the case-handling- Returns:
- the new sort order
-
with
With given null-handling.- Parameters:
nullHandling- the null-handling- Returns:
- the new sort order
-
getSortOrderText
Creates the sort order text of this ordering description.The syntax of the ordering description is
fieldNameOrPath;direction;caseHandling;nullHandling
For example
person.lastName;asc;sensitive;nulls-first
- Returns:
- the sort order text
-
getSortOrderText
Creates the sort order text of this ordering description.The syntax of the ordering description is
fieldNameOrPath;direction;caseHandling;nullHandling
For example
person.lastName;asc;sensitive;nulls-first
- Parameters:
separators- the separators- Returns:
- the sort order text
-
toString
-
by
Creates a new sort order for the given field.- Parameters:
field- the field- Returns:
- the sort order
-
fromSortOrderText
From sort order text.- Parameters:
source- the sort order text- Returns:
- the sort order
-
fromSortOrderText
From sort order text.- Parameters:
source- the sort order textseparators- the separators- Returns:
- the sort order
-