Package org.zkoss.zul

Class RowComparator

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator<java.lang.Object>

    public class RowComparator
    extends java.lang.Object
    implements java.util.Comparator<java.lang.Object>, java.io.Serializable
    A comparator used to compare Row, if not live data, or the data themselves, if live data.
    Since:
    3.6.0
    Author:
    jumperchen
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      RowComparator()
      Compares with Label.getValue().
      RowComparator​(int index)
      Compares with the column of the specified index.
      RowComparator​(int index, boolean ascending, boolean ignoreCase)
      Compares with the column of the specified index.
      RowComparator​(int index, boolean ascending, boolean ignoreCase, boolean nullAsMax)
      Compares with the column of the specified index.
      RowComparator​(Column header, boolean ascending, boolean ignoreCase, boolean nullAsMax)
      Compares with the column.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.Object o1, java.lang.Object o2)  
      boolean equals​(java.lang.Object o)  
      Column getColumn()
      Returns the column that this comparator is associated with, or null if not available.
      int hashCode()  
      boolean isAscending()
      Returns whether the order is ascending.
      boolean shallIgnoreCase()
      Returns whether to ignore case.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • RowComparator

        public RowComparator​(int index)
        Compares with the column of the specified index.

        0 for the first column, 1 for the second and so on

        Note: -1 for Row.getValue() and it assumes the value implements Comparable.

        Note: It assumes the ascending order, case-insensitive and comparing the returned values of Label.getValue(). If not, use RowComparator(int, boolean, boolean, boolean) instead.

        A null value is considered as the minimum value.

        Parameters:
        index - which column to compare. If -1, Row.getValue() is used.
      • RowComparator

        public RowComparator​(int index,
                             boolean ascending,
                             boolean ignoreCase)
        Compares with the column of the specified index.

        0 for the first column, 1 for the second and so on

        Note: -1 for Row.getValue() and it assumes the value implements Comparable.

        A null value is considered as the minimum value.

        Parameters:
        index - which column to compare. If -1, Label.getValue() is used.
        ascending - whether to sort as ascending (or descending).
        ignoreCase - whether to sort case-insensitive
      • RowComparator

        public RowComparator​(int index,
                             boolean ascending,
                             boolean ignoreCase,
                             boolean nullAsMax)
        Compares with the column of the specified index.

        0 for the first column, 1 for the second and so on

        Note: -1 for Row.getValue() and it assumes the value implements Comparable.

        Parameters:
        index - which column to compare. If -1, Row.getValue() is used.
        ascending - whether to sort as ascending (or descending).
        ignoreCase - whether to sort case-insensitive
        nullAsMax - whether to consider null as the maximum value. If false, null is considered as the minimum value.
      • RowComparator

        public RowComparator​(Column header,
                             boolean ascending,
                             boolean ignoreCase,
                             boolean nullAsMax)
        Compares with the column.
        Parameters:
        ascending - whether to sort as ascending (or descending).
        ignoreCase - whether to sort case-insensitive
        nullAsMax - whether to consider null as the maximum value. If false, null is considered as the minimum value.
    • Method Detail

      • getColumn

        public Column getColumn()
        Returns the column that this comparator is associated with, or null if not available.
      • isAscending

        public boolean isAscending()
        Returns whether the order is ascending.
      • shallIgnoreCase

        public boolean shallIgnoreCase()
        Returns whether to ignore case.
      • compare

        public int compare​(java.lang.Object o1,
                           java.lang.Object o2)
        Specified by:
        compare in interface java.util.Comparator<java.lang.Object>
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Comparator<java.lang.Object>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object