1 12 package org.displaytag.model; 13 14 import java.text.Collator ; 15 import java.util.Comparator ; 16 17 18 24 public class DefaultComparator implements Comparator 25 { 26 27 30 private Collator collator; 31 32 35 public DefaultComparator() 36 { 37 this.collator = Collator.getInstance(); 38 collator.setStrength(Collator.PRIMARY); } 40 41 45 public DefaultComparator(Collator collatorToUse) 46 { 47 this.collator = collatorToUse; 48 } 49 50 57 public int compare(Object object1, Object object2) 58 { 59 int returnValue; 60 if (object1 instanceof String && object2 instanceof String ) 61 { 62 returnValue = collator.compare(object1, object2); 63 } 64 else if (object1 instanceof Comparable && object2 instanceof Comparable ) 65 { 66 returnValue = ((Comparable ) object1).compareTo(object2); 67 } 68 else 69 { 70 returnValue = collator.compare(object1.toString(), object2.toString()); 72 } 73 return returnValue; 74 } 75 } 76 | Popular Tags |