1 18 19 package sync4j.syncclient.demo; 20 21 import java.lang.reflect.Method ; 22 23 import java.util.Comparator ; 24 25 import sync4j.foundation.pdi.contact.Contact; 26 27 37 38 public class ContactComparator implements Comparator { 39 40 42 46 public ContactComparator() { 47 48 } 49 50 52 60 public int compare(Object o1, Object o2) { 61 62 String value1 = null; 63 String value2 = null; 64 65 String firstName = null; 66 String lastName = null; 67 68 69 70 value1 = (String ) ((DemoContact) o1).getContact().getName(). 71 getDisplayName().getPropertyValue(); 72 73 value2 = (String ) ((DemoContact) o2).getContact().getName(). 74 getDisplayName().getPropertyValue(); 75 76 77 if (value1 == null) { 78 79 value1 = (String ) ((DemoContact) o1).getContact().getName(). 80 getLastName().getPropertyValue(); 81 82 if (value1 != null && !value1.equals("")) { 83 value1 += ","; 84 } 85 86 value1 += (String ) ((DemoContact) o1).getContact().getName(). 87 getFirstName().getPropertyValue(); 88 89 if (value1 == null) { 90 value1 = ""; 91 } 92 93 } 94 95 if (value2 == null) { 96 97 value2 =(String ) ((DemoContact) o2).getContact().getName(). 98 getLastName().getPropertyValue(); 99 100 if (value2 != null && !value1.equals("")) { 101 value2 += ","; 102 } 103 104 value2 += (String ) ((DemoContact) o2).getContact().getName(). 105 getFirstName().getPropertyValue(); 106 107 if (value2 == null) { 108 value2 = ""; 109 } 110 111 } 112 113 return (value1.toUpperCase()).compareTo(value2.toUpperCase()); 114 115 } 116 117 119 } | Popular Tags |