Class 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
    • 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 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 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:
        true if ascending order, false if descending order
      • isIgnoreCase

        public boolean isIgnoreCase()
        Is case-insensitive or case-sensitive order.
        Returns:
        true if case insensitive order, false if case sensitive order
      • isNullIsFirst

        public boolean isNullIsFirst()
        Is null is first.
        Returns:
        true if null is first, otherwise false
      • 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-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
      • 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