1 package xdoclet.modules.ojb.model; 2 3 17 18 import java.util.HashMap ; 19 import java.util.Comparator ; 20 21 28 public class FieldWithIdComparator implements Comparator 29 { 30 33 private HashMap _fields = null; 34 35 40 public FieldWithIdComparator(HashMap fields) 41 { 42 _fields = fields; 43 } 44 45 53 public int compare(Object objA, Object objB) 54 { 55 String idAStr = ((FieldDescriptorDef)_fields.get(objA)).getProperty("id"); 56 String idBStr = ((FieldDescriptorDef)_fields.get(objB)).getProperty("id"); 57 int idA; 58 int idB; 59 60 try 61 { 62 idA = Integer.parseInt(idAStr); 63 } 64 catch (Exception ex) 65 { 66 return 1; 67 } 68 try 69 { 70 idB = Integer.parseInt(idBStr); 71 } 72 catch (Exception ex) 73 { 74 return -1; 75 } 76 return idA < idB ? -1 : (idA > idB ? 1 : 0); 77 } 78 79 } 80 | Popular Tags |