Class SortTool

java.lang.Object
java.util.Observable
com.nomagic.magicreport.engine.Tool
com.nomagic.magicreport.engine.tools.SortTool
All Implemented Interfaces:
ITool, IVariable, Serializable, Cloneable
Direct Known Subclasses:
SorterTool, SortTable

@OpenApiAll public class SortTool extends Tool
This class is use to sort the collection in template report.
Since:
Jul 13, 2007
See Also:
  • Field Details

  • Constructor Details

    • SortTool

      public SortTool()
  • Method Details

    • isForceNumber

      public boolean isForceNumber()
    • setForceNumber

      public void setForceNumber(boolean forceNumber)
    • defaultSort

      public Collection defaultSort(Collection collection)
    • sort

      public Collection sort(Collection collection)
      Sort function for template report. Context name of this class is "sorter". Public functions of this class are able to access via template by using $sorter
      For example:
       <code>
          #foreach ($rel in $sorter.sort($package))
             $rel.name
          #end
       </code>
       
      • $package is collection to sort
      Parameters:
      collection - collection collection to be sort
      Returns:
      sorted collection
    • sort

      public Collection sort(Collection collection, String propertyName)
      Sort function for template report. Context name of this class is "sorter". Public functions of this class are able to access via template by using $sorter. This function will sort case-insensitive by default
      For example:
       <code>
          #foreach ($rel in $sorter.sort($package, "name:desc"))
             $rel.name
          #end
       </code>
       
      • $package is collection to sort
      • "name:desc" separate by ":" in 2 part
      • first part to identify the property name to sorting
      • second part is option to identify type of sorting.
      • if type of sorting is not identified, the default value is ascending
      Parameters:
      collection - collection to be sort
      propertyName - identify property name to sorting and type of sorting
      Returns:
      sorted collection
    • sort

      public Collection sort(Collection collection, Collection<String> propertyNames)
      Sort function for template report.
      Parameters:
      collection - collection to be sort
      propertyNames - collection of property name to sorting
      Returns:
      sorted collection
    • sort

      public Collection sort(Collection collection, Collection<String> propertyNames, String direction)
      Sort function for template report.
      Parameters:
      collection - collection to be sort
      propertyNames - collection of property name to sorting
      direction - type of sorting
      Returns:
      sorted collection
    • sort

      public Collection sort(Collection collection, String propertyName, boolean isCaseInsensitive)
      Sort function for template report. Context name of this class is "sorter". Public functions of this class are able to access via template by using $sorter
      For example:
       <code>
          #foreach ($rel in $sorter.sort($package, "name:desc"))
             $rel.name
          #end
       </code>
       
      • $package is collection to sort
      • "name:desc" separate by ":" in 2 part
      • first part to identify the property name to sorting
      • second part is option to identify type of sorting.
      • if type of sorting is not identified, the default value is ascending
      Parameters:
      collection - collection to be sort
      propertyName - identify property name to sorting and type of sorting
      isCaseInsensitive - true to compare case-insensitive
      Returns:
      sorted collection
    • sort

      public Collection sort(Collection collection, Collection<String> propertyNames, String direction, boolean isCaseInsensitive)
      Sort function for template report.
      Parameters:
      collection - collection to be sort
      direction - type of sorting (asc, desc)
      isCaseInsensitive - true to compare case-insensitive
      propertyName - property name to sorting and type of sorting
      Returns:
      sorted collection
    • sortByLocale

      public Collection<Object> sortByLocale(Collection<?> collection, String locale)
      Sort the given collection by specified country code.

      For example:

       <code>
          #foreach ($rel in $sorter.sortByLocale($package, "DE"))
             $rel.name
          #end
       </code>
       
      • $package is collection to sort
      • "DE" is the country argument for GERMANY (ISO Country Code)
      Note: This method performs sorting by attribute "name" of each element by default.
      Parameters:
      collection - collection collection to be sort
      locale - identified country name
      Returns:
      sorted collection
    • sortByLocale

      public Collection<Object> sortByLocale(Collection<?> collection, String propertyName, String locale)
      Sort the given collection by specified country code.

      For example:

       <code>
          #foreach ($rel in $sorter.sortByLocale($package, "DE"))
             $rel.name
          #end
       </code>
       
      • $package is collection to sort
      • "DE" is the country argument for GERMANY (ISO Country Code)
      Parameters:
      collection - collection collection to be sort
      propertyName - identify property name to sorting
      locale - identified country name
      Returns:
      sorted collection
    • humanSort

      public Collection<?> humanSort(Collection<?> collection)
      Special sorting function with human order, which says to split the text to be sorted into numeric and non-numeric chunks, then sort so that the numeric chunks are treated as numbers. This makes "foo10" sort after "foo2"
      Parameters:
      collection - collection collection to be sort
      Returns:
      sorted collection
    • humanSort

      public Collection<?> humanSort(Collection<?> collection, boolean isCaseInsensitive)
      Special sorting function with human order, which says to split the text to be sorted into numeric and non-numeric chunks, then sort so that the numeric chunks are treated as numbers. This makes "foo10" sort after "foo2"
      Parameters:
      collection - collection collection to be sort
      isCaseInsensitive - true to sort case-insensitive
      Returns:
      sorted collection
    • humanSort

      public Collection<?> humanSort(Collection<?> collection, String propertyName)
      Special sorting function with human order, which says to split the text to be sorted into numeric and non-numeric chunks, then sort so that the numeric chunks are treated as numbers. This makes "foo10" sort after "foo2"
      Parameters:
      collection - collection collection to be sort
      propertyName - property name to sorting and type of sorting
      Returns:
      sorted collection
    • humanSort

      public Collection<?> humanSort(Collection<?> collection, Collection<String> propertyNames)
      Special sorting function with human order.
      Parameters:
      collection - collection collection to be sort
      propertyNames - collection of property name to sorting
      Returns:
      sorted collection
    • humanSort

      public Collection<?> humanSort(Collection<?> collection, Collection<String> propertyNames, String direction)
      Special sorting function with human order.
      Parameters:
      collection - collection collection to be sort
      propertyNames - collection of property name to sorting
      direction - type of sorting (asc, desc)
      Returns:
      sorted collection
    • humanSort

      public Collection<?> humanSort(Collection<?> collection, String propertyName, boolean isCaseInsensitive)
      Special sorting function with human order, which says to split the text to be sorted into numeric and non-numeric chunks, then sort so that the numeric chunks are treated as numbers. This makes "foo10" sort after "foo2"
      Parameters:
      collection - collection collection to be sort
      propertyName - identify property name to sorting and type of sorting
      isCaseInsensitive - true to sort case-insensitive
      Returns:
      sorted collection
    • humanSort

      public Collection<?> humanSort(Collection<?> collection, Collection<String> propertyNames, String direction, boolean isCaseInsensitive)
      Special sorting function with human order, which says to split the text to be sorted into numeric and non-numeric chunks, then sort so that the numeric chunks are treated as numbers. This makes "foo10" sort after "foo2"
      Parameters:
      collection - collection collection to be sort
      propertyNames - collection of property name to sorting
      direction - type of sorting (asc, desc)
      isCaseInsensitive - true to sort case-insensitive
      Returns:
      sorted collection
    • sortByFirstNumber

      public Collection<Object> sortByFirstNumber(Collection<?> collection)
      Sort function with special text ordering. This function will sort the collection by give the priority to first digit found in String.

      For example:

       <code>
       ["1abc", "2abc", "a1bc", "a2bc"]
       </code>
       
      The output order will be:
       <code>
       ["1abc", "a1bc", "2abc", "a2bc"]
       </code>
       
      Parameters:
      collection - collection collection to be sort
      Returns:
      sorted collection
    • sortByFirstNumber

      public Collection<Object> sortByFirstNumber(Collection<?> collection, Collection<String> propertyNames)
      Sort function with special text ordering. This function will sort the collection by give the priority to first digit found in String.
      Parameters:
      propertyNames - collection of property name
      Returns:
      sorted collection
    • sortByFirstNumber

      public Collection<Object> sortByFirstNumber(Collection<?> collection, String propertyName)
      Sort function with special text ordering. This function will sort the collection by give the priority to first digit found in String.

      For example:

       <code>
       ["1abc", "2abc", "a1bc", "a2bc"]
       </code>
       
      The output order will be:
       <code>
       ["1abc", "a1bc", "2abc", "a2bc"]
       </code>
       
      Parameters:
      collection - collection to be sort
      propertyName - identify property name to sorting and type of sorting
      Returns:
      sorted collection
    • sortByFirstNumber

      public Collection<Object> sortByFirstNumber(Collection<?> collection, Collection<String> propertyNames, String direction)
      Sort function with special text ordering. This function will sort the collection by give the priority to first digit found in String.
      Parameters:
      collection - collection to be sort
      propertyNames - collection of property name to be sort
      Returns:
      sorted collection
    • getNextToken

      protected String getNextToken(String str, int offset, int len)
      Return a next token of string from starting offset.
      Parameters:
      str - input string
      offset - starting offset
      len - string length
      Returns:
      next token.
    • getValue

      protected Object getValue(Object object, String propertyName)
      Look up a object value by property name.
      Parameters:
      object - target object.
      propertyName - property name
      Returns:
      the value.