Search in sources :

Example 1 with IntComparatorChain

use of tech.tablesaw.sorting.comparators.IntComparatorChain in project symja_android_library by axkr.

the class TableSlice method sortOn.

/**
 * Sort this view in place without modifying or copying the underlying source table. Unlike {@link
 * Table#sortOn(Sort)} which returns a copy of the table, this method sorts the view in place.
 *
 * @param key to sort on.
 */
public void sortOn(Sort key) {
    Preconditions.checkArgument(!key.isEmpty());
    if (key.size() == 1) {
        IntComparator comparator = SortUtils.getComparator(table, key);
        this.sortOrder = sortOn(comparator);
    } else {
        IntComparatorChain chain = SortUtils.getChain(table, key);
        this.sortOrder = sortOn(chain);
    }
}
Also used : IntComparatorChain(tech.tablesaw.sorting.comparators.IntComparatorChain) IntComparator(it.unimi.dsi.fastutil.ints.IntComparator)

Example 2 with IntComparatorChain

use of tech.tablesaw.sorting.comparators.IntComparatorChain in project symja_android_library by axkr.

the class Table method sortOn.

/**
 * Returns a copy of this table sorted using the given sort key.
 *
 * @param key to sort on.
 * @return a sorted copy of this table.
 */
public Table sortOn(Sort key) {
    Preconditions.checkArgument(!key.isEmpty());
    if (key.size() == 1) {
        IntComparator comparator = SortUtils.getComparator(this, key);
        return sortOn(comparator);
    }
    IntComparatorChain chain = SortUtils.getChain(this, key);
    return sortOn(chain);
}
Also used : IntComparatorChain(tech.tablesaw.sorting.comparators.IntComparatorChain) IntComparator(it.unimi.dsi.fastutil.ints.IntComparator)

Example 3 with IntComparatorChain

use of tech.tablesaw.sorting.comparators.IntComparatorChain in project symja_android_library by axkr.

the class SortUtils method getChain.

/**
 * Returns a comparator chain for sorting according to the given key
 */
public static IntComparatorChain getChain(Table table, Sort key) {
    Iterator<Map.Entry<String, Sort.Order>> entries = key.iterator();
    Map.Entry<String, Sort.Order> sort = entries.next();
    Column<?> column = table.column(sort.getKey());
    IntComparator comparator = rowComparator(column, sort.getValue());
    IntComparatorChain chain = new IntComparatorChain(comparator);
    while (entries.hasNext()) {
        sort = entries.next();
        chain.addComparator(rowComparator(table.column(sort.getKey()), sort.getValue()));
    }
    return chain;
}
Also used : IntComparatorChain(tech.tablesaw.sorting.comparators.IntComparatorChain) IntComparator(it.unimi.dsi.fastutil.ints.IntComparator) ReversingIntComparator(tech.tablesaw.sorting.comparators.ReversingIntComparator) Map(java.util.Map)

Aggregations

IntComparator (it.unimi.dsi.fastutil.ints.IntComparator)3 IntComparatorChain (tech.tablesaw.sorting.comparators.IntComparatorChain)3 Map (java.util.Map)1 ReversingIntComparator (tech.tablesaw.sorting.comparators.ReversingIntComparator)1