1 13 package com.tonbeller.wcf.table; 14 15 import java.util.Comparator ; 16 17 20 21 class RowComparator implements Comparator { 22 TableColumn column; 23 24 public RowComparator() { 25 column = new TableColumn(0); 26 } 27 28 public RowComparator(TableColumn column) { 29 this.column = column; 30 } 31 32 public int compare(Object o1, Object o2) { 33 TableRow tr1 = (TableRow)o1; 34 TableRow tr2 = (TableRow)o2; 35 int columnIndex = column.getColumnIndex(); 36 Object v1 = tr1.getValue(columnIndex); 37 Object v2 = tr2.getValue(columnIndex); 38 Comparator comp = column.getComparator(); 39 int res; 40 if (v1 == null && v2 == null) 41 res = 0; 42 else if (v1 == null) 43 res = 1; 44 else if (v2 == null) 45 res = -1; 46 else 47 res = comp.compare(v1, v2); 48 if (column.isDescending()) 49 return -res; 50 return res; 51 } 52 53 public TableColumn getColumn() { 54 return column; 55 } 56 57 public void setColumn(TableColumn column) { 58 this.column = column; 59 } 60 61 public int getColumnIndex() { 62 return column.getColumnIndex(); 63 } 64 65 } | Popular Tags |