@Test public void testNullsShouldBeInTheEnd() throws Exception { final DateTime now = DateTime.now(); final List<Message> messages = new ArrayList<Message>(); for (int i = 0; i < 5; i++) { messages.add(newMockMessage(now.plusDays(i))); } for (int i = 5; i < 10; i++) { messages.add(null); } sort(messages, new Comparator<Message>() { @Override public int compare(Message lhs, Message rhs) { return compareSendDatesLatestFirst(lhs, rhs); } }); for (int i = 1; i < 5; i++) { assertTrue(messages.get(i - 1).getSendDate().isAfter(messages.get(i).getSendDate())); } for (int i = 5; i < 10; i++) { assertNull(messages.get(i)); } }
public static int compareSendDatesLatestFirst(@Nullable Message lm, @Nullable Message rm) { if (lm == null && rm == null) { return 0; } else if (lm == null) { return 1; } else if (rm == null) { return -1; } else { return -lm.getSendDate().compareTo(rm.getSendDate()); } }
Messages { public static int compareSendDatesLatestFirst(@Nullable Message lm, @Nullable Message rm) { if (lm == null && rm == null) { return 0; } else if (lm == null) { return 1; } else if (rm == null) { return -1; } else { return -lm.getSendDate().compareTo(rm.getSendDate()); } } }
Messages { public static int compareSendDatesLatestFirst(@Nullable Message lm, @Nullable Message rm) { if (lm == null && rm == null) { return 0; } else if (lm == null) { return 1; } else if (rm == null) { return -1; } else { return -lm.getSendDate().compareTo(rm.getSendDate()); } } private  Messages(); }
Messages { public static int compareSendDatesLatestFirst(@Nullable Message lm, @Nullable Message rm) { if (lm == null && rm == null) { return 0; } else if (lm == null) { return 1; } else if (rm == null) { return -1; } else { return -lm.getSendDate().compareTo(rm.getSendDate()); } } private  Messages(); @Nonnull static CharSequence getMessageTime(@Nonnull Message message); @Nonnull static CharSequence getMessageTitle(@Nonnull Chat chat, @Nonnull Message message, @Nonnull User user); @Nonnull static MutableMessage newEmptyMessage(@Nonnull String messageId); @Nonnull static MutableMessage newIncomingMessage(@Nonnull Account account, @Nonnull Chat chat, @Nonnull String message, @Nullable String title, @Nonnull Entity author); @Nonnull static MutableMessage newOutgoingMessage(@Nonnull Account account, @Nonnull Chat chat, @Nonnull String message, @Nullable String title); @Nonnull static MutableMessage newMessage(@Nonnull Entity entity); static int compareSendDatesLatestFirst(@Nullable Message lm, @Nullable Message rm); static int compareSendDatesLatestFirst(@Nullable DateTime lm, @Nullable DateTime rm); static int compareSendDates(@Nullable Message lm, @Nullable Message rm); @Nonnull static MutableMessage copySentMessage(@Nonnull Message message, @Nonnull Account account, @Nonnull String accountMessageId); }
Messages { public static int compareSendDatesLatestFirst(@Nullable Message lm, @Nullable Message rm) { if (lm == null && rm == null) { return 0; } else if (lm == null) { return 1; } else if (rm == null) { return -1; } else { return -lm.getSendDate().compareTo(rm.getSendDate()); } } private  Messages(); @Nonnull static CharSequence getMessageTime(@Nonnull Message message); @Nonnull static CharSequence getMessageTitle(@Nonnull Chat chat, @Nonnull Message message, @Nonnull User user); @Nonnull static MutableMessage newEmptyMessage(@Nonnull String messageId); @Nonnull static MutableMessage newIncomingMessage(@Nonnull Account account, @Nonnull Chat chat, @Nonnull String message, @Nullable String title, @Nonnull Entity author); @Nonnull static MutableMessage newOutgoingMessage(@Nonnull Account account, @Nonnull Chat chat, @Nonnull String message, @Nullable String title); @Nonnull static MutableMessage newMessage(@Nonnull Entity entity); static int compareSendDatesLatestFirst(@Nullable Message lm, @Nullable Message rm); static int compareSendDatesLatestFirst(@Nullable DateTime lm, @Nullable DateTime rm); static int compareSendDates(@Nullable Message lm, @Nullable Message rm); @Nonnull static MutableMessage copySentMessage(@Nonnull Message message, @Nonnull Account account, @Nonnull String accountMessageId);  }