@@ -0,0 +1,2170 @@
+package org.realityforge.replicant.example.server.service.tyrelll.replicate;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.Collections;%0Aimport java.util.Comparator;%0Aimport java.util.List;%0Aimport org.realityforge.replicant.server.EntityMessage;%0A%0A/**%0A * Provides ordering of EntityMessages so as to ensure their correct processing when retrieved from the database%0A * Order changes as they should be processed, so a to make subsequent retrieval and application easier.%0A * Ordering is:%0A * - Deletions, then updates%0A * - Within deletions, order by type, desc, so as to delete in the reverse order from the schema set%0A * - Within updates, order by type, as, so as to create in the order from the schema set%0A * - Within identical types, order by change time, desc on delete, asc on update.%0A */%0Apublic final class EntityMessageSorter%0A  implements Comparator%3CEntityMessage%3E%0A%7B%0A  private EntityMessageSorter()%0A  %7B%0A  %7D%0A%0A  public static List%3CEntityMessage%3E sort( final Collection%3CEntityMessage%3E messages )%0A  %7B%0A    final ArrayList%3CEntityMessage%3E sortedMessages = new ArrayList%3CEntityMessage%3E( messages );%0A    Collections.sort( sortedMessages, COMPARATOR );%0A    return sortedMessages;%0A  %7D%0A%0A  public static final EntityMessageSorter COMPARATOR = new EntityMessageSorter();%0A%0A  @Override%0A  public int compare( final EntityMessage o1, final EntityMessage o2 )%0A  %7B%0A    if ( o1.isDelete() )%0A    %7B%0A      if ( o2.isUpdate() )%0A      %7B%0A        return -1;%0A      %7D%0A      final int typeComparison = o2.getTypeID() - o1.getTypeID();%0A      if ( 0 != typeComparison )%0A      %7B%0A        return typeComparison;%0A      %7D%0A      if ( o2.getTimestamp() %3C o1.getTimestamp() )%0A      %7B%0A        return -1;%0A      %7D%0A      if ( o2.getTimestamp() %3E o1.getTimestamp() )%0A      %7B%0A        return 1;%0A      %7D%0A      return 0;%0A    %7D%0A    if ( o2.isDelete() )%0A    %7B%0A      return 1;%0A    %7D%0A    final int typeComparison = o1.getTypeID() - o2.getTypeID();%0A    if ( 0 != typeComparison )%0A    %7B%0A      return typeComparison;%0A    %7D%0A    if ( o1.getTimestamp() %3C o2.getTimestamp() )%0A    %7B%0A      return -1;%0A    %7D%0A    if ( o1.getTimestamp() %3E o2.getTimestamp() )%0A    %7B%0A      return 1;%0A    %7D%0A    return 0;%0A  %7D%0A%7D%0A

Add utility class to sort EntityMessages