james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1131145 - in /james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator: CombinedComparator.java SizeComparator.java
Date Fri, 03 Jun 2011 19:07:35 GMT
Author: norman
Date: Fri Jun  3 19:07:35 2011
New Revision: 1131145

URL: http://svn.apache.org/viewvc?rev=1131145&view=rev
Log:
Add method to create the comparators for a List of Sort object. See MAILBOX-78

Modified:
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/CombinedComparator.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/SizeComparator.java

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/CombinedComparator.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/CombinedComparator.java?rev=1131145&r1=1131144&r2=1131145&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/CombinedComparator.java
(original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/CombinedComparator.java
Fri Jun  3 19:07:35 2011
@@ -18,8 +18,11 @@
  ****************************************************************/
 package org.apache.james.mailbox.store.search.comparator;
 
+import java.util.ArrayList;
 import java.util.Comparator;
+import java.util.List;
 
+import org.apache.james.mailbox.SearchQuery.Sort;
 import org.apache.james.mailbox.store.mail.model.Message;
 
 /**
@@ -47,5 +50,45 @@ public class CombinedComparator implemen
         }
         return i;
     }
+    
+    @SuppressWarnings("unchecked")
+    public Comparator<Message<?>> create(List<Sort> sorts) {
+        List<Comparator<?>> comps = new ArrayList<Comparator<?>>();
+        for (int i = 0; i < sorts.size(); i++) {
+            Sort sort = sorts.get(i);
+            boolean reverse = sort.isReverse();
+            Comparator<Message<?>> comparator = null;
+            
+            switch (sort.getSortClause()) {
+            case Arrival:
+                comparator = InternalDateComparator.internalDate(reverse);
+                break;
+            case Cc:
+                comparator = HeaderMailboxComparator.cc(reverse);
+                break;
+            case From:
+                comparator = HeaderMailboxComparator.from(reverse);
+                break;
+            case Size:
+                comparator = SizeComparator.size(reverse);
+                break;
+            case Subject:
+                // TODO: fix me
+                break;
+            case To:
+                comparator = HeaderMailboxComparator.to(reverse);
+                break;
+            case Uid:
+                comparator = UidComparator.uid(reverse);
+                break;
+            default:
+                break;
+            }
+            if (comparator != null) {
+                comps.add(comparator);
+            }
+        }
+        return new CombinedComparator(comps.toArray(new Comparator[0]));
+    }
 
 }

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/SizeComparator.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/SizeComparator.java?rev=1131145&r1=1131144&r2=1131145&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/SizeComparator.java
(original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/comparator/SizeComparator.java
Fri Jun  3 19:07:35 2011
@@ -38,7 +38,7 @@ public class SizeComparator implements C
         return (int) (o1.getFullContentOctets() - o2.getFullContentOctets());
     }
 
-    public Comparator<Message<?>> size(boolean reverse) {
+    public static Comparator<Message<?>> size(boolean reverse) {
         if (reverse) {
             return REVERSE_SIZE;
         } else {



---------------------------------------------------------------------
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