Package adams.data.instances
Class InstanceComparator
- java.lang.Object
-
- adams.data.instances.InstanceComparator
-
- All Implemented Interfaces:
Serializable
,Comparator<weka.core.Instance>
public class InstanceComparator extends Object implements Serializable, Comparator<weka.core.Instance>
For comparing instance objects. It is assumed that the dataset that the two instance objects belong to are compatible.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean[]
m_Ascending
whether to sort ascending or descending.protected int[]
m_Indices
the column indices to use in the comparison.
-
Constructor Summary
Constructors Constructor Description InstanceComparator(int[] indices)
Initializes the comparator.InstanceComparator(int[] indices, boolean[] ascending)
Initializes the comparator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(weka.core.Instance o1, weka.core.Instance 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.String
toString()
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
-
InstanceComparator
public InstanceComparator(int[] indices)
Initializes the comparator. Uses ascending sort order for all columns.- Parameters:
indices
- the indices of the columns to compare
-
InstanceComparator
public InstanceComparator(int[] indices, boolean[] ascending)
Initializes the comparator.- Parameters:
indices
- the indices of the columns to compareascending
- whether to sort ascending or descending, ascending 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(weka.core.Instance o1, weka.core.Instance 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:
compare
in interfaceComparator<weka.core.Instance>
- 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.
-
-