1 package xdoclet.modules.ojb.model; 2 3 17 18 import java.util.Comparator ; 19 20 27 public class ColumnWithIdComparator implements Comparator 28 { 29 32 private TableDef _table = null; 33 34 39 public ColumnWithIdComparator(TableDef table) 40 { 41 _table = table; 42 } 43 44 52 public int compare(Object objA, Object objB) 53 { 54 String idAStr = _table.getColumn((String )objA).getProperty("id"); 55 String idBStr = _table.getColumn((String )objB).getProperty("id"); 56 int idA; 57 int idB; 58 59 try { 60 idA = Integer.parseInt(idAStr); 61 } 62 catch (Exception ex) { 63 return 1; 64 } 65 try { 66 idB = Integer.parseInt(idBStr); 67 } 68 catch (Exception ex) { 69 return -1; 70 } 71 return idA < idB ? -1 : (idA > idB ? 1 : 0); 72 } 73 74 } 75 | Popular Tags |