Class SortOrder

java.lang.Object
org.bremersee.comparator.model.SortOrder

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
  • Constructor Details

    • 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 be null)
      asc - true for an ascending order, false for a descending order
      ignoreCase - true for a case-insensitive order, false for a case-sensitive order
      nullIsFirst - specifies the order of null values
  • Method Details

    • with

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

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

      public SortOrder with(SortOrder.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,asc,ignoreCase,nullIsFirst
       

      For example

       person.lastName,asc,true,false
       
      Returns:
      the sort order text
    • toSortOrderText

      @Deprecated public String toSortOrderText()
      Deprecated.
      Use getSortOrderText() instead.
      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
    • getSortOrderText

      public String getSortOrderText(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-handling and null-handling** depend on the given SortOrdersTextProperties.

      For example with default properties:

       person.lastName,asc,true,false
       
      Parameters:
      properties - the properties (can be null
      Returns:
      the sort order text
    • toSortOrderText

      @Deprecated public 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-handling and null-handling** depend on the given SortOrdersTextProperties.

      For example with default properties:

       person.lastName,asc,true,false
       
      Parameters:
      properties - the properties (can be null
      Returns:
      the sort order text
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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 text
      properties - the properties
      Returns:
      the sort order