@Test public void compare_twoMessages_shouldReturnOrderByUid() throws Exception { Message messageSmall = createMessageWithUid(5); Message messageLarge = createMessageWithUid(15); int resultOne = comparator.compare(messageSmall, messageLarge); int resultTwo = comparator.compare(messageLarge, messageSmall); assertTrue("result must be > 0 when right message has larger UID than left message", resultOne > 0); assertTrue("result must be < 0 when left message has larger UID than right message", resultTwo < 0); }
@Override public int compare(Message messageLeft, Message messageRight) { Long uidLeft = getUidForMessage(messageLeft); Long uidRight = getUidForMessage(messageRight); if (uidLeft == null && uidRight == null) { return 0; } else if (uidLeft == null) { return 1; } else if (uidRight == null) { return -1; } return uidRight.compareTo(uidLeft); }
UidReverseComparator implements Comparator<Message> { @Override public int compare(Message messageLeft, Message messageRight) { Long uidLeft = getUidForMessage(messageLeft); Long uidRight = getUidForMessage(messageRight); if (uidLeft == null && uidRight == null) { return 0; } else if (uidLeft == null) { return 1; } else if (uidRight == null) { return -1; } return uidRight.compareTo(uidLeft); } }
UidReverseComparator implements Comparator<Message> { @Override public int compare(Message messageLeft, Message messageRight) { Long uidLeft = getUidForMessage(messageLeft); Long uidRight = getUidForMessage(messageRight); if (uidLeft == null && uidRight == null) { return 0; } else if (uidLeft == null) { return 1; } else if (uidRight == null) { return -1; } return uidRight.compareTo(uidLeft); }  }
UidReverseComparator implements Comparator<Message> { @Override public int compare(Message messageLeft, Message messageRight) { Long uidLeft = getUidForMessage(messageLeft); Long uidRight = getUidForMessage(messageRight); if (uidLeft == null && uidRight == null) { return 0; } else if (uidLeft == null) { return 1; } else if (uidRight == null) { return -1; } return uidRight.compareTo(uidLeft); }  @Override int compare(Message messageLeft, Message messageRight); }
UidReverseComparator implements Comparator<Message> { @Override public int compare(Message messageLeft, Message messageRight) { Long uidLeft = getUidForMessage(messageLeft); Long uidRight = getUidForMessage(messageRight); if (uidLeft == null && uidRight == null) { return 0; } else if (uidLeft == null) { return 1; } else if (uidRight == null) { return -1; } return uidRight.compareTo(uidLeft); }  @Override int compare(Message messageLeft, Message messageRight);  }