JAMES-1894 Support Id sorting for in memory implementation
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/dbf63003 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/dbf63003 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/dbf63003 Branch: refs/heads/master Commit: dbf63003f3b022cf25bb09014c11e613920d2aa0 Parents: 1732427 Author: Benoit Tellier <[email protected]> Authored: Mon Dec 26 11:28:56 2016 +0700 Committer: Benoit Tellier <[email protected]> Committed: Mon Jan 9 22:01:06 2017 +0700 ---------------------------------------------------------------------- .../search/comparator/CombinedComparator.java | 2 ++ .../search/comparator/MessageIdComparator.java | 35 ++++++++++++++++++++ .../store/search/CombinedComparatorTest.java | 9 +++-- 3 files changed, 41 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/dbf63003/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/CombinedComparator.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/CombinedComparator.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/CombinedComparator.java index 9295480..436fcea 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/CombinedComparator.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/CombinedComparator.java @@ -74,6 +74,8 @@ public class CombinedComparator implements Comparator<MailboxMessage>{ return HeaderDisplayComparator.FROM_COMPARATOR; case DisplayTo: return HeaderDisplayComparator.TO_COMPARATOR; + case Id: + return MessageIdComparator.MESSAGE_ID_COMPARATOR; default: throw new NotImplementedException("Combined comparator does not support sort " + sort.getSortClause()); } http://git-wip-us.apache.org/repos/asf/james-project/blob/dbf63003/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/MessageIdComparator.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/MessageIdComparator.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/MessageIdComparator.java new file mode 100644 index 0000000..f65064e --- /dev/null +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/MessageIdComparator.java @@ -0,0 +1,35 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mailbox.store.search.comparator; + +import java.util.Comparator; + +import org.apache.james.mailbox.store.mail.model.MailboxMessage; + +public class MessageIdComparator implements Comparator<MailboxMessage> { + public static final MessageIdComparator MESSAGE_ID_COMPARATOR = new MessageIdComparator(); + + @Override + public int compare(MailboxMessage mailboxMessage1, MailboxMessage mailboxMessage2) { + return mailboxMessage1.getMessageId() + .serialize() + .compareToIgnoreCase(mailboxMessage2.getMessageId().serialize()); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/dbf63003/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java index be69207..ae3177c 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/CombinedComparatorTest.java @@ -21,13 +21,13 @@ package org.apache.james.mailbox.store.search; import static org.assertj.core.api.Assertions.assertThat; -import org.apache.commons.lang.NotImplementedException; import org.apache.james.mailbox.model.SearchQuery; import org.apache.james.mailbox.store.search.comparator.BaseSubjectComparator; import org.apache.james.mailbox.store.search.comparator.CombinedComparator; import org.apache.james.mailbox.store.search.comparator.HeaderDisplayComparator; import org.apache.james.mailbox.store.search.comparator.HeaderMailboxComparator; import org.apache.james.mailbox.store.search.comparator.InternalDateComparator; +import org.apache.james.mailbox.store.search.comparator.MessageIdComparator; import org.apache.james.mailbox.store.search.comparator.ReverseComparator; import org.apache.james.mailbox.store.search.comparator.SentDateComparator; import org.apache.james.mailbox.store.search.comparator.SizeComparator; @@ -119,10 +119,9 @@ public class CombinedComparatorTest { } @Test - public void createShouldThrowOnIdConversion() { - expectedException.expect(NotImplementedException.class); - - CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Id))); + public void createShouldConvertId() { + assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Id))).getComparators()) + .containsOnly(MessageIdComparator.MESSAGE_ID_COMPARATOR); } @Test --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
