You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/09/17 23:44:15 UTC
svn commit: r816391 -
/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowComparator.java
Author: gbrown
Date: Thu Sep 17 21:44:14 2009
New Revision: 816391
URL: http://svn.apache.org/viewvc?rev=816391&view=rev
Log:
Compare values that don't implement Comparable as strings in TableViewRowComparator.
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowComparator.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowComparator.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowComparator.java?rev=816391&r1=816390&r2=816391&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowComparator.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowComparator.java Thu Sep 17 21:44:14 2009
@@ -24,7 +24,9 @@
import org.apache.pivot.wtk.TableView;
/**
- * Compares two rows. The dictionary values are expected to implement {@link Comparable}.
+ * Compares two rows. If the column values implement {@link Comparable}, the
+ * {@link Comparable#compareTo(Object)} method will be used to compare the values.
+ * Otherwise, the values will be compared as strings using {@link Object#toString()}.
*/
public class TableViewRowComparator implements Comparator<Object> {
private TableView tableView;
@@ -71,11 +73,18 @@
String columnName = pair.key;
SortDirection sortDirection = sort.get(columnName);
- Comparable<Object> comparable = (Comparable<Object>)row1.get(columnName);
- Object value = row2.get(columnName);
+ Object value1 = row1.get(columnName);
+ Object value2 = row2.get(columnName);
- result = (comparable.compareTo(value))
- * (sortDirection == SortDirection.ASCENDING ? 1 : -1);
+ if (value1 instanceof Comparable<?>) {
+ result = ((Comparable<Object>)value1).compareTo(value2);
+ } else {
+ String s1 = value1.toString();
+ String s2 = value2.toString();
+ result = s1.compareTo(s2);
+ }
+
+ result *= (sortDirection == SortDirection.ASCENDING ? 1 : -1);
i++;
}