1 16 17 package org.apache.commons.codec; 18 19 import java.util.Comparator ; 20 21 33 public class StringEncoderComparator implements Comparator { 34 35 38 private StringEncoder stringEncoder; 39 40 43 public StringEncoderComparator() { 44 } 46 47 51 public StringEncoderComparator(StringEncoder stringEncoder) { 52 this.stringEncoder = stringEncoder; 53 } 54 55 68 public int compare(Object o1, Object o2) { 69 70 int compareCode = 0; 71 72 try { 73 Comparable s1 = (Comparable ) ((Encoder) this.stringEncoder).encode(o1); 74 Comparable s2 = (Comparable ) ((Encoder) this.stringEncoder).encode(o2); 75 compareCode = s1.compareTo(s2); 76 } 77 catch (EncoderException ee) { 78 compareCode = 0; 79 } 80 return compareCode; 81 } 82 83 } 84 | Popular Tags |