1 package net.sf.jga.util; 33 34 import java.io.Serializable ; 35 import java.util.Comparator ; 36 37 39 46 47 public class ChainedComparator<T> implements Comparator <T>, Serializable 48 { 49 static final long serialVersionUID = -8015644817201268699L; 50 51 private Comparator <T> _primary; 52 private Comparator <T> _secondary; 53 54 public ChainedComparator(Comparator <T> primary, Comparator <T> secondary) { 55 if (primary == null || secondary == null) { 56 String msg = "Two Comparators are required: at least one was null"; 57 throw new IllegalArgumentException (msg); 58 } 59 60 _primary = primary; 61 _secondary = secondary; 62 } 63 64 public int compare(T x, T y) { 65 int result = _primary.compare(x,y); 66 return (result == 0) ? _secondary.compare(x,y) : result; 67 } 68 } 69 | Popular Tags |