@Test public void sort() { final EntityMessage m1 = newEntityMessage( 1, 1, 10L, false ); final EntityMessage m2 = newEntityMessage( 2, 2, 100L, false ); final EntityMessage m3 = newEntityMessage( 3, 2, 10L, false ); final EntityMessage m4 = newEntityMessage( 4, 3, 10L, true ); final EntityMessage m5 = newEntityMessage( 5, 3, 100L, true ); { final List<EntityMessage> l1 = Arrays.asList( m1, m2, m3, m4, m5 ); final List<EntityMessage> r1 = EntityMessageSorter.sort( l1 ); assertIndex( r1, 0, 5 ); assertIndex( r1, 1, 4 ); assertIndex( r1, 2, 1 ); assertIndex( r1, 3, 3 ); assertIndex( r1, 4, 2 ); } { final List<EntityMessage> l2 = Arrays.asList( m5, m4, m3, m2, m1 ); final List<EntityMessage> r2 = EntityMessageSorter.sort( l2 ); assertIndex( r2, 0, 5 ); assertIndex( r2, 1, 4 ); assertIndex( r2, 2, 1 ); assertIndex( r2, 3, 3 ); assertIndex( r2, 4, 2 ); } { final List<EntityMessage> l2 = Arrays.asList( m1, m1, m2, m2, m1 ); final List<EntityMessage> r2 = EntityMessageSorter.sort( l2 ); assertIndex( r2, 0, 1 ); assertIndex( r2, 1, 1 ); assertIndex( r2, 2, 1 ); assertIndex( r2, 3, 2 ); assertIndex( r2, 4, 2 ); } { final List<EntityMessage> l2 = Arrays.asList( m4, m4, m5, m5, m4 ); final List<EntityMessage> r2 = EntityMessageSorter.sort( l2 ); assertIndex( r2, 0, 5 ); assertIndex( r2, 1, 5 ); assertIndex( r2, 2, 4 ); assertIndex( r2, 3, 4 ); assertIndex( r2, 4, 4 ); } }
@Nonnull public static List<EntityMessage> sort( @Nonnull final Collection<EntityMessage> messages ) { final ArrayList<EntityMessage> sortedMessages = new ArrayList<>( messages ); sortedMessages.sort( COMPARATOR ); return sortedMessages; }
EntityMessageSorter implements Comparator<EntityMessage> { @Nonnull public static List<EntityMessage> sort( @Nonnull final Collection<EntityMessage> messages ) { final ArrayList<EntityMessage> sortedMessages = new ArrayList<>( messages ); sortedMessages.sort( COMPARATOR ); return sortedMessages; } }
EntityMessageSorter implements Comparator<EntityMessage> { @Nonnull public static List<EntityMessage> sort( @Nonnull final Collection<EntityMessage> messages ) { final ArrayList<EntityMessage> sortedMessages = new ArrayList<>( messages ); sortedMessages.sort( COMPARATOR ); return sortedMessages; } private  EntityMessageSorter(); }
EntityMessageSorter implements Comparator<EntityMessage> { @Nonnull public static List<EntityMessage> sort( @Nonnull final Collection<EntityMessage> messages ) { final ArrayList<EntityMessage> sortedMessages = new ArrayList<>( messages ); sortedMessages.sort( COMPARATOR ); return sortedMessages; } private  EntityMessageSorter(); @Nonnull static List<EntityMessage> sort( @Nonnull final Collection<EntityMessage> messages ); @Override int compare( @Nonnull final EntityMessage o1, @Nonnull final EntityMessage o2 ); }
EntityMessageSorter implements Comparator<EntityMessage> { @Nonnull public static List<EntityMessage> sort( @Nonnull final Collection<EntityMessage> messages ) { final ArrayList<EntityMessage> sortedMessages = new ArrayList<>( messages ); sortedMessages.sort( COMPARATOR ); return sortedMessages; } private  EntityMessageSorter(); @Nonnull static List<EntityMessage> sort( @Nonnull final Collection<EntityMessage> messages ); @Override int compare( @Nonnull final EntityMessage o1, @Nonnull final EntityMessage o2 ); static final EntityMessageSorter COMPARATOR; }