1 16 package org.apache.commons.collections.comparators; 17 18 import java.util.Comparator ; 19 20 import org.apache.commons.collections.Transformer; 21 22 33 public class TransformingComparator implements Comparator { 34 35 36 protected Comparator decorated; 37 38 protected Transformer transformer; 39 40 47 public TransformingComparator(Transformer transformer) { 48 this(transformer, new ComparableComparator()); 49 } 50 51 57 public TransformingComparator(Transformer transformer, Comparator decorated) { 58 this.decorated = decorated; 59 this.transformer = transformer; 60 } 61 62 70 public int compare(Object obj1, Object obj2) { 71 Object value1 = this.transformer.transform(obj1); 72 Object value2 = this.transformer.transform(obj2); 73 return this.decorated.compare(value1, value2); 74 } 75 76 } 77 78 | Popular Tags |