com.sun.data.provider.impl
Class BasicTableDataSorter

java.lang.Object
  extended bycom.sun.data.provider.impl.BasicTableDataSorter
All Implemented Interfaces:
TableDataSorter

public class BasicTableDataSorter
extends java.lang.Object
implements TableDataSorter

The BasicTableDataSorter utilizes the Comparable interface on data objects in the specified TableDataProvider to provide a sorted version of the data based on the specified sort criteria.

Author:
Joe Nuxoll, Dan Labracque

Field Summary
protected  SortCriteria[] sortCriteria
          Storage for the sort criteria
protected  java.util.Locale sortLocale
          Storage for the sort locale
 
Constructor Summary
BasicTableDataSorter()
          Constructs a BasicTableDataSorter with no sort criteria or locale setting.
BasicTableDataSorter(java.util.Locale sortLocale)
          Constructs a BasicTableDataSorter with the specified locale with no initial sort criteria.
BasicTableDataSorter(SortCriteria[] sortCriteria)
          Constructs a BasicTableDataSorter with the specified initial sort criteria and no locale setting.
BasicTableDataSorter(SortCriteria[] sortCriteria, java.util.Locale sortLocale)
          Constructs a BasicTableDataSorter with the specified initial sort criteria and sort locale.
 
Method Summary
 SortCriteria[] getSortCriteria()
          

Returns the current sort criteria on this data sorter.

 java.util.Locale getSortLocale()
          

Gets the sort locale used when comparing objects. If none is set, the default locale should be used via Locale.getDefault().

 void setSortCriteria(SortCriteria[] sortCriteria)
          

Sets the sort criteria on this data sorter.

 void setSortLocale(java.util.Locale sortLocale)
          

Sets the sort locale to use when comparing objects. If none is set, the default locale should be used via Locale.getDefault().

 RowKey[] sort(TableDataProvider provider, RowKey[] rows)
          Get an array containing an row of sorted rows.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sortCriteria

protected SortCriteria[] sortCriteria
Storage for the sort criteria


sortLocale

protected java.util.Locale sortLocale
Storage for the sort locale

Constructor Detail

BasicTableDataSorter

public BasicTableDataSorter()
Constructs a BasicTableDataSorter with no sort criteria or locale setting.


BasicTableDataSorter

public BasicTableDataSorter(SortCriteria[] sortCriteria)
Constructs a BasicTableDataSorter with the specified initial sort criteria and no locale setting.

Parameters:
sortCriteria - The desired initial sort criteria

BasicTableDataSorter

public BasicTableDataSorter(java.util.Locale sortLocale)
Constructs a BasicTableDataSorter with the specified locale with no initial sort criteria.

Parameters:
sortLocale - The desired sort locale

BasicTableDataSorter

public BasicTableDataSorter(SortCriteria[] sortCriteria,
                            java.util.Locale sortLocale)
Constructs a BasicTableDataSorter with the specified initial sort criteria and sort locale.

Parameters:
sortCriteria - The desired initial sort criteria
sortLocale - The desired sort locale
Method Detail

setSortCriteria

public void setSortCriteria(SortCriteria[] sortCriteria)

Sets the sort criteria on this data sorter.

Specified by:
setSortCriteria in interface TableDataSorter
Parameters:
sortCriteria - An array of SortCriteria objects defining the sort order on this TableDataSorter

getSortCriteria

public SortCriteria[] getSortCriteria()

Returns the current sort criteria on this data sorter.

Specified by:
getSortCriteria in interface TableDataSorter
Returns:
SortCriteria[] defining the sort order on this TableDataSorter

setSortLocale

public void setSortLocale(java.util.Locale sortLocale)

Sets the sort locale to use when comparing objects. If none is set, the default locale should be used via Locale.getDefault().

Specified by:
setSortLocale in interface TableDataSorter
Parameters:
sortLocale - The desired Locale to use for sort comparisons

getSortLocale

public java.util.Locale getSortLocale()

Gets the sort locale used when comparing objects. If none is set, the default locale should be used via Locale.getDefault().

Specified by:
getSortLocale in interface TableDataSorter
Returns:
The Locale used for comparing objects, or null if the default Locale is used.

sort

public RowKey[] sort(TableDataProvider provider,
                     RowKey[] rows)
              throws DataProviderException

Get an array containing an row of sorted rows. This method does not modify the model, but creates an rowed array of sorted rows. The returned array is typically used to row through model rows to obtain the next sorted object.

The sorting algorithms selected for this method are based on the merge sort and radix sort. The radix sort, always sorts on the least significant object. For example, we could sort information three times with a stable sort: first on day, next on month, and finally on year. The analysis of the running time depends on the stable sort used as the intermediate sorting algorithm. If there are m passes, and m is constant, the radix sort runs in linear time. The total time for the merge sort algorithm is O(n log n) in the worst case.

Sorts the rows from the specified TableDataProvider based on the current sort criteria, and returns an array of RowKeys representing the sorted row order. Any excluded rows from the return value of sort(...) should be considered unsortable, and thus should be displayed at the end of whatever UI is presenting these items.

NOTE: If a component is bound to a TableDataProvider and an TableDataSorter, which are the *same* instance, this method is never called. The sort order is assumed to be intrinsic in the row key order of the TableDataProvider, based on the currently set sort criteria.

Specified by:
sort in interface TableDataSorter
Parameters:
provider - The TableDataProvider to sort
rows - The array of RowKeys to sort. If this is null then the return value should be null or an empty array of RowKeys.
Returns:
An array of RowKeys representing the sorted rows from the specified TableDataProvider. Any excluded rows from the return value of this method should be considered unsortable, and thus should be displayed at the end of whatever UI is presenting these items. null may be returned to indicate that sorting is not possible.
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException) rather than simply returning null or an empty array. A DPE may also indicate that the passed TableDataProvider or RowKeys are not valid. Consult the documentation of the specific TableDataSorter implementation for details on what exceptions might be wrapped by a DPE.