Class Sort

  • All Implemented Interfaces:
    Iterable<Map.Entry<String,​Sort.Order>>

    public class Sort
    extends Object
    implements Iterable<Map.Entry<String,​Sort.Order>>
    Provides fine-grained control over sorting.

    Use:

    table.sortOn(first("Year", DESCEND).next("State", ASCEND));

    This sorts table on the column named year in descending order, such that the most recent years appear first, then on State, in ascending order so "AL" will appear before "CA". You can add additional instructions for multi-column sorts by chaining additional calls to next() with the appropriate column names and Order.

    • Constructor Detail

      • Sort

        public Sort​(String columnName,
                    Sort.Order order)
        Constructs a Sort specifying the order (ascending or descending) to apply to the column with the given name
    • Method Detail

      • on

        public static Sort on​(String columnName,
                              Sort.Order order)
        Returns a Sort specifying the order (ascending or descending) to apply to the column with the given name
      • next

        public Sort next​(String columnName,
                         Sort.Order order)
        Returns a Sort that concatenates a new sort on the given order (ascending or descending) and columnName onto the sort specified here. This method is used to construct complex sorts such as: Sort.on("foo", Order.ASCEND).next("bar", Order.DESCEND);
      • isEmpty

        public boolean isEmpty()
        Returns true if no order has been set
      • size

        public int size()
        Returns the number of columns used in this sort
      • create

        public static Sort create​(Table table,
                                  String... columnNames)
        Create a Sort object from the given table and sort column names. Does not sort the table.
        Parameters:
        table - to sort. Used only to pull the table's schema. Does not modify the table.
        columnNames - The columns to sort on. Can prefix column name with + for ascending, - for descending. Default to ascending if no prefix is added.
        Returns:
        a Sort(java.lang.String, tech.tablesaw.sorting.Sort.Order) Object.