001
014
015 package com.liferay.portlet.messageboards.util.comparator;
016
017 import com.liferay.portal.kernel.util.DateUtil;
018 import com.liferay.portlet.messageboards.model.MBMessage;
019
020 import java.io.Serializable;
021
022 import java.util.Comparator;
023
024
027 public class MessageThreadComparator
028 implements Comparator<MBMessage>, Serializable {
029
030 @Override
031 public int compare(MBMessage msg1, MBMessage msg2) {
032 Long parentMessageId1 = new Long(msg1.getParentMessageId());
033 Long parentMessageId2 = new Long(msg2.getParentMessageId());
034
035 int value = parentMessageId1.compareTo(parentMessageId2);
036
037 if (value == 0) {
038 value = DateUtil.compareTo(
039 msg1.getCreateDate(), msg2.getCreateDate());
040 }
041
042 if (value == 0) {
043 Long messageId1 = new Long(msg1.getMessageId());
044 Long messageId2 = new Long(msg2.getMessageId());
045
046 value = messageId1.compareTo(messageId2);
047 }
048
049 return value;
050 }
051
052 }