package org.camunda.bpm.engine.test.util;

import org.camunda.bpm.engine.history.HistoricActivityInstance;

import java.util.Comparator;

/**
 * @author Martin Schimak <martin.schimak@plexiti.com>
 */
public class HistoricActivityInstanceComparator implements Comparator<HistoricActivityInstance> {

  @Override
  public int compare(HistoricActivityInstance instance1, HistoricActivityInstance instance2) {
    int compare = instance1.getEndTime().compareTo(instance2.getEndTime());
    if (compare == 0) {
      String string1 = instance1.getId().substring(instance1.getId().lastIndexOf(':') + 1);
      String string2 = instance2.getId().substring(instance2.getId().lastIndexOf(':') + 1);
      try {
        Long long1 = Long.parseLong(string1);
        Long long2 = Long.parseLong(string2);
        return long1.compareTo(long2);
      } catch (NumberFormatException e) {
        return string1.compareTo(string2);
      }
    }
    return compare;
  }
  
}

@@ -129,16 +129,80 @@
 parator;
+%0Aimport java.util.IllegalFormatException;%0Aimport java.util.UUID;
 %0A%0A/**%0A *
@@ -929,16 +929,17 @@
 eption e
+1
 ) %7B%0A    
@@ -946,22 +946,55 @@
     
-return 
+try %7B%0A          return UUID.fromString(
 string1
+)
 .com
@@ -1000,25 +1000,198 @@
 mpareTo(
-string2);
+UUID.fromString(string2));%0A        %7D catch (IllegalArgumentException e2) %7B%0A          throw new IllegalArgumentException(%22You seem to use an unsupported ID generator.%22, e2);%0A        %7D
 %0A      %7D

use default java UUID comparison