Class ObjectSorter

java.lang.Object
org.apache.juneau.objecttools.ObjectSorter
All Implemented Interfaces:
ObjectTool<SortArgs>

public final class ObjectSorter extends Object implements ObjectTool<SortArgs>
POJO model sorter.

This class is designed to sort arrays and collections of maps or beans.

Example:

MyBean[] arrayOfBeans = ...; ObjectSorter sorter = ObjectSorter.create(); // Returns a list of beans sorted accordingly. List<MyBean> result = sorter.run(arrayOfBeans, "foo,bar-");

The tool can be used against the following data types:

  • Arrays/collections of maps or beans.

The arguments are a simple comma-delimited list of property names optionally suffixed with '+' and '-' to denote ascending/descending order.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • create

      public static ObjectSorter create()
      Static creator.
      Returns:
      A new ObjectSorter object.
    • run

      public <R> List<R> run(Object input, String sortArgs)
      Convenience method for executing the sorter.
      Type Parameters:
      R - The return type.
      Parameters:
      input - The input.
      sortArgs - The sort arguments. See SortArgs for format.
      Returns:
      A list of maps/beans matching the
    • run

      public Object run(BeanSession session, Object input, SortArgs args)
      Description copied from interface: ObjectTool
      Converts the specified input to some other output.
      Specified by:
      run in interface ObjectTool<SortArgs>
      Parameters:
      session - The current bean session.
      input - The input POJO.
      args - The arguments.
      Returns:
      The output POJO.