james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [08/21] james-project git commit: JAMES-2044 Sort order should be an enum
Date Wed, 07 Jun 2017 10:46:18 GMT
JAMES-2044 Sort order should be an enum


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4f1ff45d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4f1ff45d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4f1ff45d

Branch: refs/heads/master
Commit: 4f1ff45de005081980bfa3eb0cd4680049c78d3b
Parents: 1026070
Author: benwa <btellier@linagora.com>
Authored: Tue Jun 6 16:44:17 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Jun 7 17:34:32 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/model/SearchQuery.java |  23 ++--
 .../LuceneMailboxMessageSearchIndexTest.java    | 120 ++++++++++---------
 .../search/AbstractMessageSearchIndexTest.java  |  32 ++---
 .../store/search/CombinedComparatorTest.java    |  28 +++--
 .../apache/james/jmap/utils/SortConverter.java  |  23 ++--
 .../james/jmap/utils/SortConverterTest.java     |  18 +--
 6 files changed, 129 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
index 9888f15..d81b74d 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
@@ -71,6 +71,11 @@ public class SearchQuery implements Serializable {
     public static class Sort implements Serializable {
         private static final long serialVersionUID = 1L;
 
+        public enum Order {
+            REVERSE,
+            NATURAL
+        }
+
         /**
          * Specify on what to sort
          */
@@ -158,21 +163,21 @@ public class SearchQuery implements Serializable {
             Id
         }
 
-        private final boolean reverse;
+        private final Order order;
         private final SortClause sortClause;
 
-        public Sort(SortClause sortClause, boolean reverse) {
-            this.reverse = reverse;
+        public Sort(SortClause sortClause, Order order) {
+            this.order = order;
             this.sortClause = sortClause;
         }
 
         /**
-         * Create a new {@link Sort} which is NOT {@link #reverse}
+         * Create a new {@link Sort} which is NOT {@link #order}
          * 
          * @param sortClause
          */
         public Sort(SortClause sortClause) {
-            this(sortClause, false);
+            this(sortClause, Order.NATURAL);
         }
 
         /**
@@ -181,7 +186,7 @@ public class SearchQuery implements Serializable {
          * @return reverse
          */
         public boolean isReverse() {
-            return reverse;
+            return order == Order.REVERSE;
         }
 
         /**
@@ -198,14 +203,14 @@ public class SearchQuery implements Serializable {
             if (o instanceof Sort) {
                 Sort that = (Sort) o;
                 return Objects.equal(this.sortClause, that.sortClause)
-                    && Objects.equal(this.reverse, that.reverse);
+                    && Objects.equal(this.order, that.order);
             }
             return false;
         }
 
         @Override
         public int hashCode() {
-            return Objects.hashCode(sortClause, reverse);
+            return Objects.hashCode(sortClause, order);
         }
     }
 
@@ -760,7 +765,7 @@ public class SearchQuery implements Serializable {
 
     private final List<Criterion> criterias;
 
-    private List<Sort> sorts = Collections.singletonList(new Sort(Sort.SortClause.Uid,
false));
+    private List<Sort> sorts = Collections.singletonList(new Sort(Sort.SortClause.Uid,
Sort.Order.NATURAL));
 
     public void andCriteria(Criterion crit) {
         criterias.add(crit);

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
index 413e4fb..15a9edb 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
@@ -21,7 +21,6 @@ package org.apache.james.mailbox.lucene.search;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.nio.charset.Charset;
-import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
@@ -44,7 +43,9 @@ import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.SearchQuery.AddressType;
 import org.apache.james.mailbox.model.SearchQuery.DateResolution;
+import org.apache.james.mailbox.model.SearchQuery.Sort;
 import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
+import org.apache.james.mailbox.model.SearchQuery.Sort.Order;
 import org.apache.james.mailbox.model.SimpleMailboxACL;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.TestMessageId;
@@ -55,6 +56,8 @@ import org.apache.lucene.store.RAMDirectory;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
+
 public class LuceneMailboxMessageSearchIndexTest {
 
     public static final long LIMIT = 100L;
@@ -457,171 +460,171 @@ public class LuceneMailboxMessageSearchIndexTest {
     
     @Test
     public void uidReverseSortShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.Uid, true)));
-        query.andCriteria(SearchQuery.all());
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.Uid, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid4, uid3, uid1);
     }
     
     @Test
     public void sortOnSentDateShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.SentDate, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.SentDate, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4, uid1);
     }
     
     @Test
     public void reverseSortOnSentDateShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.SentDate, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.SentDate, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid1, uid4, uid3);
     }
 
     @Test
     public void sortOnSubjectShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.BaseSubject, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.BaseSubject, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid1, uid4);
     }
     
     @Test
     public void reverseSortOnSubjectShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.BaseSubject, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.BaseSubject, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid4, uid1, uid3);
     }
     
     @Test
     public void sortOnMailboxFromShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxFrom, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxFrom, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4, uid1);
     }
     
     @Test
     public void reverseSortOnMailboxFromShouldReturnWellOrderedResults() throws Exception
{
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxFrom, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxFrom, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid1, uid4, uid3);
     }
     
     @Test
     public void sortOnMailboxCCShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxCc, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxCc, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid1, uid3, uid4);
     }
     
     @Test
     public void reverseSortOnMailboxCCShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxCc, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxCc, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4, uid1);
     }
     
     @Test
     public void sortOnMailboxToShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxTo, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxTo, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid4, uid1, uid3);
     }
     
     @Test
     public void reverseSortOnMailboxToShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.MailboxTo, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.MailboxTo, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid1, uid4);
     }
     
     @Test
     public void sortOnDisplayToShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.DisplayTo, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.DisplayTo, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid4, uid1, uid3);
     }
     
     @Test
     public void reverseSortOnDisplayToShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.DisplayTo, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.DisplayTo, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid1, uid4);
     }
     
     @Test
     public void sortOnDisplayFromShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.DisplayFrom, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.DisplayFrom, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4, uid1);
     }
     
     @Test
     public void reverseSortOnDisplayFromShouldReturnWellOrderedResults() throws Exception
{
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.DisplayFrom, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.DisplayFrom, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid1, uid4, uid3);
     }
     
     @Test
     public void sortOnArrivalDateShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.Arrival, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid1, uid4);
     }
     
     @Test
     public void reverseSortOnArrivalDateShouldReturnWellOrderedResults() throws Exception
{
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.Arrival, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid4, uid1, uid3);
     }
     
     @Test
     public void sortOnSizeShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.Size, false)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.Size, Order.NATURAL)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4, uid1);
     }
     
     @Test
     public void reverseSortOnSizeShouldReturnWellOrderedResults() throws Exception {
-        SearchQuery query = new SearchQuery();
-        query.andCriteria(SearchQuery.all());
-        query.setSorts(Arrays.asList(new SearchQuery.Sort(SortClause.Size, true)));
+        SearchQuery query = new SearchQuery(SearchQuery.all());
+        query.setSorts(ImmutableList.of(new Sort(SortClause.Size, Order.REVERSE)));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid1, uid3, uid4);
     }
@@ -630,6 +633,7 @@ public class LuceneMailboxMessageSearchIndexTest {
     public void notOperatorShouldReverseMatching() throws Exception {
         SearchQuery query = new SearchQuery();
         query.andCriteria(SearchQuery.not(SearchQuery.uid(new SearchQuery.UidRange[] { new
SearchQuery.UidRange(uid1)})));
+
         Iterator<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
index 6d622ee..c489d80 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
@@ -39,6 +39,7 @@ import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.SearchQuery.AddressType;
 import org.apache.james.mailbox.model.SearchQuery.DateResolution;
 import org.apache.james.mailbox.model.SearchQuery.Sort;
+import org.apache.james.mailbox.model.SearchQuery.Sort.Order;
 import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
@@ -61,7 +62,6 @@ public abstract class AbstractMessageSearchIndexTest {
     public static final long LIMIT = 100L;
     public static final boolean RECENT = true;
     public static final boolean NOT_RECENT = false;
-    public static final boolean REVERSE = true;
 
     protected MessageSearchIndex messageSearchIndex;
     protected StoreMailboxManager storeMailboxManager;
@@ -629,7 +629,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Date(1433408400000L),
             DateResolution.Second));
         // Date : 2015/06/04 11:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m3.getUid(), m2.getUid());
@@ -641,7 +641,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Date(1433109600000L),
             DateResolution.Day));
         // Date : 2015/06/01 00:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m5.getUid());
@@ -653,7 +653,7 @@ public abstract class AbstractMessageSearchIndexTest {
             new Date(1433224800000L),
             DateResolution.Day));
         // Date : 2015/06/02 08:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m4.getUid(), m9.getUid());
@@ -818,7 +818,7 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void revertSortingShouldReturnElementsInAReversedOrder() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m9.getUid(), m8.getUid(), m7.getUid(), m6.getUid(), m4.getUid(),
m5.getUid(), m3.getUid(), m2.getUid(), m1.getUid());
@@ -829,7 +829,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery(
             SearchQuery.headerDateAfter("sentDate", new Date(1433408400000L), DateResolution.Second));
         // Date : 2015/06/04 11:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m3.getUid(), m2.getUid());
@@ -840,7 +840,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery(
             SearchQuery.headerDateBefore("sentDate", new Date(1433109600000L), DateResolution.Day));
         // Date : 2015/06/01 00:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m5.getUid());
@@ -851,7 +851,7 @@ public abstract class AbstractMessageSearchIndexTest {
         SearchQuery searchQuery = new SearchQuery(
             SearchQuery.headerDateOn("sentDate", new Date(1433224800000L), DateResolution.Day));
         // Date : 2015/06/02 08:00:00.000 ( Paris time zone )
-        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, REVERSE)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m4.getUid(), m9.getUid());
@@ -897,7 +897,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnToShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxTo)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.MailboxTo)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m5.getUid(), m2.getUid(), m3.getUid(), m4.getUid());
@@ -911,7 +911,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnSubjectShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.BaseSubject)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.BaseSubject)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m4.getUid(), m3.getUid(), m2.getUid(), m5.getUid());
@@ -925,7 +925,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnSizeShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Size)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Size)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m2.getUid(), m3.getUid(), m5.getUid(), m4.getUid());
@@ -939,7 +939,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnDisplayFromShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayFrom)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.DisplayFrom)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m4.getUid(), m3.getUid(), m5.getUid(), m2.getUid());
@@ -953,7 +953,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnDisplayToShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayTo)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.DisplayTo)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m3.getUid(), m2.getUid(), m4.getUid(), m5.getUid());
@@ -967,7 +967,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnSentDateShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.SentDate)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m5.getUid(), m4.getUid(), m2.getUid(), m3.getUid());
@@ -981,7 +981,7 @@ public abstract class AbstractMessageSearchIndexTest {
     public void sortOnIdShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Uid)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Uid)));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsExactly(m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid());
@@ -1104,7 +1104,7 @@ public abstract class AbstractMessageSearchIndexTest {
     @Test
     public void sortShouldNotDiscardResultWhenSearchingFieldIsIdentical() throws Exception
{
         SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
-        searchQuery.setSorts(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival)));
+        searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival)));
 
         List<MessageId> actual = messageSearchIndex.search(session, MultimailboxesSearchQuery.from(searchQuery).build(),
LIMIT);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/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 fc2ceee..8376687 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
@@ -22,6 +22,9 @@ package org.apache.james.mailbox.store.search;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.SearchQuery.Sort;
+import org.apache.james.mailbox.model.SearchQuery.Sort.Order;
+import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
 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;
@@ -40,7 +43,6 @@ import com.google.common.collect.ImmutableList;
 
 public class CombinedComparatorTest {
 
-    public static final boolean REVERSE = true;
     @Rule
     public ExpectedException expectedException = ExpectedException.none();
 
@@ -61,84 +63,84 @@ public class CombinedComparatorTest {
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertInternalDate() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Arrival))).getComparators())
             .containsOnly(InternalDateComparator.INTERNALDATE);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertCc() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxCc))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.MailboxCc))).getComparators())
             .containsOnly(HeaderMailboxComparator.CC_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertFrom() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxFrom))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.MailboxFrom))).getComparators())
             .containsOnly(HeaderMailboxComparator.FROM_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertTo() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.MailboxTo))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.MailboxTo))).getComparators())
             .containsOnly(HeaderMailboxComparator.TO_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertSize() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Size))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Size))).getComparators())
             .containsOnly(SizeComparator.SIZE);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertBaseSubject() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.BaseSubject))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.BaseSubject))).getComparators())
             .containsOnly(BaseSubjectComparator.BASESUBJECT);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertUid() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Uid))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Uid))).getComparators())
             .containsOnly(UidComparator.UID);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertSentDate() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.SentDate))).getComparators())
             .containsOnly(SentDateComparator.SENTDATE);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertDisplayTo() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayTo))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.DisplayTo))).getComparators())
             .containsOnly(HeaderDisplayComparator.TO_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertDisplayFrom() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayFrom))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.DisplayFrom))).getComparators())
             .containsOnly(HeaderDisplayComparator.FROM_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldConvertId() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Id))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.Id))).getComparators())
             .containsOnly(MessageIdComparator.MESSAGE_ID_COMPARATOR);
     }
 
     @Test
     @SuppressWarnings("unchecked")
     public void createShouldReverse() {
-        assertThat(CombinedComparator.create(ImmutableList.of(new SearchQuery.Sort(SearchQuery.Sort.SortClause.DisplayFrom,
REVERSE))).getComparators())
+        assertThat(CombinedComparator.create(ImmutableList.of(new Sort(SortClause.DisplayFrom,
Order.REVERSE))).getComparators())
             .containsOnly(new ReverseComparator(HeaderDisplayComparator.FROM_COMPARATOR));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortConverter.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortConverter.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortConverter.java
index 2a97f46..5d5daac 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortConverter.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortConverter.java
@@ -23,6 +23,9 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.SearchQuery.Sort;
+import org.apache.james.mailbox.model.SearchQuery.Sort.Order;
+import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
 
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
@@ -35,19 +38,19 @@ public class SortConverter {
     private static final String DESC_ORDERING = "desc";
     private static final String ASC_ORDERING = "asc";
 
-    private static final Map<String, SearchQuery.Sort.SortClause> SORT_CLAUSE_MAP =
ImmutableMap.of(
-        "date", SearchQuery.Sort.SortClause.SentDate,
-        "id", SearchQuery.Sort.SortClause.Id);
+    private static final Map<String, SortClause> SORT_CLAUSE_MAP = ImmutableMap.of(
+        "date", SortClause.SentDate,
+        "id", SortClause.Id);
 
 
-    public static List<SearchQuery.Sort> convertToSorts(List<String> jmapSorts)
{
+    public static List<Sort> convertToSorts(List<String> jmapSorts) {
         Preconditions.checkNotNull(jmapSorts);
         return jmapSorts.stream()
             .map(SortConverter::toSort)
             .collect(Guavate.toImmutableList());
     }
 
-    private static SearchQuery.Sort toSort(String jmapSort) {
+    private static Sort toSort(String jmapSort) {
         Preconditions.checkNotNull(jmapSort);
         List<String> splitToList = Splitter.on(SEPARATOR).splitToList(jmapSort);
         checkField(splitToList);
@@ -55,23 +58,23 @@ public class SortConverter {
             isReverse(splitToList));
     }
 
-    private static SearchQuery.Sort.SortClause getSortClause(String field) {
+    private static SortClause getSortClause(String field) {
         if (! SORT_CLAUSE_MAP.containsKey(field)) {
             throw new IllegalArgumentException("Unknown sorting field: " + field + " should
be one of " + SORT_CLAUSE_MAP.keySet());
         }
         return SORT_CLAUSE_MAP.get(field);
     }
 
-    private static boolean isReverse(List<String> splitList) {
+    private static Order isReverse(List<String> splitList) {
         if (splitList.size() == 1) {
-            return true;
+            return Order.REVERSE;
         }
         String order = splitList.get(1);
         switch (order) {
             case DESC_ORDERING:
-                return true;
+                return Order.REVERSE;
             case ASC_ORDERING:
-                return false;
+                return Order.NATURAL;
         }
         throw new IllegalArgumentException("Unknown sorting order: " + order + " should be
one of [asc, desc]");
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4f1ff45d/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SortConverterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SortConverterTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SortConverterTest.java
index b30aeb2..af0686c 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SortConverterTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SortConverterTest.java
@@ -23,7 +23,9 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.List;
 
-import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.SearchQuery.Sort;
+import org.apache.james.mailbox.model.SearchQuery.Sort.Order;
+import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -33,8 +35,6 @@ import com.google.common.collect.Lists;
 
 public class SortConverterTest {
 
-    public static final boolean REVERSE = true;
-    public static final boolean NOT_REVERSE = !REVERSE;
     @Rule
     public ExpectedException expectedException = ExpectedException.none();
 
@@ -72,19 +72,19 @@ public class SortConverterTest {
     @Test
     public void convertToSortsShouldSupportDate() {
         assertThat(SortConverter.convertToSorts(ImmutableList.of("date desc")))
-            .containsExactly(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate, REVERSE));
+            .containsExactly(new Sort(SortClause.SentDate, Order.REVERSE));
     }
 
     @Test
     public void convertToSortsShouldSupportId() {
         assertThat(SortConverter.convertToSorts(ImmutableList.of("id desc")))
-            .containsExactly(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Id, REVERSE));
+            .containsExactly(new Sort(SortClause.Id, Order.REVERSE));
     }
 
     @Test
     public void convertToSortsShouldBeDescWhenNoOrderClause() {
         assertThat(SortConverter.convertToSorts(ImmutableList.of("date")))
-            .containsExactly(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate, REVERSE));
+            .containsExactly(new Sort(SortClause.SentDate, Order.REVERSE));
     }
 
     @Test
@@ -96,7 +96,7 @@ public class SortConverterTest {
     @Test
     public void convertToSortsShouldSupportAscOrder() {
         assertThat(SortConverter.convertToSorts(ImmutableList.of("date asc")))
-            .containsExactly(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate, NOT_REVERSE));
+            .containsExactly(new Sort(SortClause.SentDate, Order.NATURAL));
     }
 
     @Test
@@ -108,7 +108,7 @@ public class SortConverterTest {
     @Test
     public void convertToSortsShouldSupportMultipleSorts() {
         assertThat(SortConverter.convertToSorts(ImmutableList.of("date asc", "id desc")))
-            .containsExactly(new SearchQuery.Sort(SearchQuery.Sort.SortClause.SentDate, NOT_REVERSE),
-                new SearchQuery.Sort(SearchQuery.Sort.SortClause.Id, REVERSE));
+            .containsExactly(new Sort(SortClause.SentDate, Order.NATURAL),
+                new Sort(SortClause.Id, Order.REVERSE));
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message