Package tech.tablesaw.sorting
Class Sort
- java.lang.Object
-
- tech.tablesaw.sorting.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSort.Order
-
Constructor Summary
Constructors Constructor Description 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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Sortcreate(Table table, String... columnNames)Create a Sort object from the given table and sort column names.booleanisEmpty()Returns true if no order has been setIterator<Map.Entry<String,Sort.Order>>iterator()Returns an iterator over elements of typeT.Sortnext(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.static Sorton(String columnName, Sort.Order order)Returns a Sort specifying the order (ascending or descending) to apply to the column with the given nameintsize()Returns the number of columns used in this sortStringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
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.
-
iterator
public Iterator<Map.Entry<String,Sort.Order>> iterator()
Returns an iterator over elements of typeT.- Specified by:
iteratorin interfaceIterable<Map.Entry<String,Sort.Order>>- Returns:
- an Iterator.
-
-