com.groiss.ds
Class ListComparator

java.lang.Object
  extended by com.groiss.ds.ListComparator
All Implemented Interfaces:
java.io.Serializable, java.util.Comparator<java.util.List<java.lang.Object>>

public class ListComparator
extends java.lang.Object
implements java.util.Comparator<java.util.List<java.lang.Object>>, java.io.Serializable

Compare two lists. This class is used for sorting tables, where aech table row is a list.

See Also:
Serialized Form

Constructor Summary
ListComparator(int[] sortcols)
          Construct a list comparator with an array of sort columns.
ListComparator(int column, boolean ascending)
          Construct a list comparator with a sort column and a boolean for sort direction.
ListComparator(int column, boolean ascending, int column2, boolean ascending2)
          Construct a list comparator with two sort columns and booleans for sort direction.
 
Method Summary
 int compare(java.util.List<java.lang.Object> o1, java.util.List<java.lang.Object> o2)
          Compare two lists.
static int compareNumbers(java.lang.Number n1, java.lang.Number n2)
          Compares 2 Objects implementing Interface Number, even if they are different types
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

ListComparator

public ListComparator(int column,
                      boolean ascending)
Construct a list comparator with a sort column and a boolean for sort direction.

Parameters:
column - sort column
ascending - true if sort ascending

ListComparator

public ListComparator(int column,
                      boolean ascending,
                      int column2,
                      boolean ascending2)
Construct a list comparator with two sort columns and booleans for sort direction.

Parameters:
column - sort column
ascending - true if sort ascending
column2 - sort column2
ascending2 - true if sort column2 ascending

ListComparator

public ListComparator(int[] sortcols)
Construct a list comparator with an array of sort columns. Positive integers are used for sorting ascending, negative for sorting descending. The column numbers start with 1.
Example: the argument [-1,2] sorts first the colum with index zero descending, then the first column (index one in list) ascending.

Parameters:
sortcols - array of sort columns
Method Detail

compare

public int compare(java.util.List<java.lang.Object> o1,
                   java.util.List<java.lang.Object> o2)
Compare two lists.

Specified by:
compare in interface java.util.Comparator<java.util.List<java.lang.Object>>

compareNumbers

public static int compareNumbers(java.lang.Number n1,
                                 java.lang.Number n2)
Compares 2 Objects implementing Interface Number, even if they are different types



@enterprise 8.0.22989 Copyright © 2001-2017 Groiss Informatics GmbH. All Rights Reserved.