Package adams.data.spreadsheet
Class RowComparator
- java.lang.Object
-
- adams.data.spreadsheet.RowComparator
-
- All Implemented Interfaces:
Serializable,Comparator<Row>
public class RowComparator extends Object implements Serializable, Comparator<Row>
For comparing rows. It is assumed that the spreadsheets that the two rows belong to are compatible.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
SpreadSheet.equalsHeader(SpreadSheet), Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean[]m_Ascendingwhether to sort ascending or descending.protected int[]m_Indicesthe column indices to use in the comparison.
-
Constructor Summary
Constructors Constructor Description RowComparator(int[] indices)Initializes the comparator.RowComparator(int[] indices, boolean[] ascending)Initializes the comparator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(Row o1, Row o2)Compares its two arguments for order.boolean[]getAscending()Returns whether a column is sorted in ascending or descending order.int[]getIndices()Returns the indices used for sorting.StringtoString()Returns a short description of the comparator.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Constructor Detail
-
RowComparator
public RowComparator(int[] indices)
Initializes the comparator. Uses ascending sort order for all columns.- Parameters:
indices- the indices of the columns to compare
-
RowComparator
public RowComparator(int[] indices, boolean[] ascending)Initializes the comparator.- Parameters:
indices- the indices of the columns to compareascending- whether to sort ascending or descending, asending if null
-
-
Method Detail
-
getIndices
public int[] getIndices()
Returns the indices used for sorting.- Returns:
- the (0-based) indices
-
getAscending
public boolean[] getAscending()
Returns whether a column is sorted in ascending or descending order.- Returns:
- the sorting order
-
compare
public int compare(Row o1, Row o2)
Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.- Specified by:
comparein interfaceComparator<Row>- Parameters:
o1- the first object to be compared.o2- the second object to be compared.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
-