Class 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 Detail

      • m_Indices

        protected int[] m_Indices
        the column indices to use in the comparison.
      • m_Ascending

        protected boolean[] m_Ascending
        whether to sort ascending or descending.
    • 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 compare
        ascending - 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 interface Comparator<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.
      • toString

        public String toString()
        Returns a short description of the comparator.
        Overrides:
        toString in class Object
        Returns:
        the description