Class SortOrderItem

java.lang.Object
org.bremersee.comparator.model.SortOrderItem
All Implemented Interfaces:
Serializable

public class SortOrderItem extends Object implements 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:
  • Field Details

    • DEFAULT_SEPARATOR

      public static final String DEFAULT_SEPARATOR
      The constant DEFAULT_SEPARATOR.
      See Also:
    • DEFAULT_DIRECTION

      protected static final SortOrderItem.Direction DEFAULT_DIRECTION
      The constant DEFAULT_DIRECTION.
    • DEFAULT_CASE_HANDLING

      protected static final SortOrderItem.CaseHandling DEFAULT_CASE_HANDLING
      The constant DEFAULT_CASE_HANDLING.
    • DEFAULT_NULL_HANDLING

      protected static final SortOrderItem.NullHandling 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 be null)
      direction - the direction
      caseHandling - the case-handling
      nullHandling - the null-handling
  • Method Details

    • getField

      public String getField()
      Gets field (can be null).
      Returns:
      the field
    • with

      public SortOrderItem with(SortOrderItem.Direction direction)
      With given direction.
      Parameters:
      direction - the direction
      Returns:
      the new sort order
    • with

      public SortOrderItem with(SortOrderItem.CaseHandling caseHandling)
      With given case-handling.
      Parameters:
      caseHandling - the case-handling
      Returns:
      the new sort order
    • with

      public SortOrderItem with(SortOrderItem.NullHandling nullHandling)
      With given null-handling.
      Parameters:
      nullHandling - the null-handling
      Returns:
      the new sort order
    • getSortOrderText

      public String 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

      public String getSortOrderText(SortOrderTextSeparators separators)
      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

      public String toString()
      Overrides:
      toString in class Object
    • by

      public static SortOrderItem by(String field)
      Creates a new sort order for the given field.
      Parameters:
      field - the field
      Returns:
      the sort order
    • fromSortOrderText

      public static SortOrderItem fromSortOrderText(String source)
      From sort order text.
      Parameters:
      source - the sort order text
      Returns:
      the sort order
    • fromSortOrderText

      public static SortOrderItem fromSortOrderText(String source, SortOrderTextSeparators separators)
      From sort order text.
      Parameters:
      source - the sort order text
      separators - the separators
      Returns:
      the sort order