1 package org.columba.mail.gui.tree.comparator; 17 18 import java.util.Comparator ; 19 20 import org.columba.mail.folder.IMailFolder; 21 import org.columba.mail.folder.IMailbox; 22 import org.columba.mail.folder.virtual.VirtualFolder; 23 24 35 public class FolderComparator implements Comparator { 36 37 private boolean isAscending = true; 38 39 43 public FolderComparator(boolean ascending) { 44 isAscending = ascending; 45 } 46 47 48 public int compare(Object o1, Object o2) { 49 int compValue; 50 51 if ((o1 instanceof IMailFolder) && (o2 instanceof IMailFolder)) { 52 if (!(o1 instanceof IMailbox)) { 55 compValue = 0; 56 } else if (o1 instanceof VirtualFolder) { 57 compValue = 1; 58 } else { 59 IMailbox folder1 = (IMailbox) o1; 60 IMailbox folder2 = (IMailbox) o2; 61 62 boolean folder1IsInbox = folder1.isInboxFolder(); 63 boolean folder2IsInbox = folder2.isInboxFolder(); 64 65 if (folder1IsInbox) { 66 compValue = -1; 67 } else if (folder2IsInbox) { 68 compValue = 1; 69 } else if (folder2IsInbox && folder1IsInbox) { 70 compValue = 0; 71 } else { 72 compValue = compareFolders(folder1, folder2); 73 if (!isAscending) { 74 compValue *= -1; 75 } 76 } 77 } 78 } else { 79 compValue = o1.toString().toLowerCase().compareTo( 80 o2.toString().toLowerCase()); 81 if (!isAscending) { 82 compValue *= -1; 83 } 84 } 85 return compValue; 86 } 87 88 100 protected int compareFolders(IMailbox folder1, IMailbox folder2) { 101 return folder1.getName().toLowerCase().compareTo( 102 folder2.getName().toLowerCase()); 103 } 104 105 108 public boolean isAscending() { 109 return isAscending; 110 } 111 112 116 public void setAscending(boolean ascending) { 117 isAscending = ascending; 118 } 119 } | Popular Tags |