public interface Comparable { public int compareTo(Object pObject); }
public class Date implements Comparable { ... public int compareTo(final Object pObject) { final Date tDate = (Date)pObject; int tResult = iYear - tDate.iYear; if (tResult==0) { tResult = iMonth - tDate.iMonth; if (tResult==0) { tResult = iDay - tDate.iDay; } } return tResult; } }
final Set tOccurrences = new TreeSet(): tOccurrences.add(tDeathOfBach);