code: protected void sortAndMerge(List eventsToCompare) {
      Collections.sort(eventsToCompare);
      int numEvents = eventsToCompare.size();
      int numUniqueEvents = 1; // assertion: eventsToCompare.length >= 1
  
      if (numEvents <= 1) {
        return; // nothing to do; edge case (see assertion)
      }
  
      ComparableEvent ce = (ComparableEvent) eventsToCompare.get(0);
      for (int i = 1; i < numEvents; i++) {
        ComparableEvent ce2 = (ComparableEvent) eventsToCompare.get(i);
  
        if (ce.compareTo(ce2) == 0) {
          ce.seen++; // increment the seen count
          eventsToCompare.set(i, null); // kill the duplicate
        }
        else {
          ce = ce2; // a new champion emerges...
          numUniqueEvents++; // increment the # of unique events
        }
      }
  
      System.out.println("done. Reduced " + numEvents + " events to " + numUniqueEvents + ".");
  
      contexts = new int[numUniqueEvents][];
      outcomeList = new int[numUniqueEvents];
      numTimesEventsSeen = new int[numUniqueEvents];
  
      for (int i = 0, j = 0; i < numEvents; i++) {
        ComparableEvent evt = (ComparableEvent) eventsToCompare.get(i);
        if (null == evt) {
          continue; // this was a dupe, skip over it.
        }
        numTimesEventsSeen[j] = evt.seen;
        outcomeList[j] = evt.outcome;
        contexts[j] = evt.predIndexes;
        ++j;
      }
    }
docs: Sorts and uniques the array of comparable events.  This method
  will alter the eventsToCompare array -- it does an in place
  sort, followed by an in place edit to remove duplicates.
  
  @param eventsToCompare a <code>ComparableEvent[]</code> value
  @since maxent 1.2.6