1 36 package org.columba.ristretto.imap; 37 38 import java.util.Arrays ; 39 import java.util.Iterator ; 40 import java.util.LinkedList ; 41 import java.util.List ; 42 43 48 public class SearchKey { 49 52 public static final String ALL = "ALL"; 53 56 public static final String ANSWERED = "ANSWERED"; 57 60 public static final String BCC = "BCC"; 61 64 public static final String BEFORE = "BEFORE"; 65 68 public static final String BODY = "BODY"; 69 72 public static final String CC = "CC"; 73 76 public static final String DELETED = "DELETED"; 77 80 public static final String FLAGGED = "FLAGGED"; 81 84 public static final String FROM = "FROM"; 85 88 public static final String KEYWORD = "KEYWORD"; 89 92 public static final String NEW = "NEW"; 93 96 public static final String OLD = "OLD"; 97 100 public static final String ON = "ON"; 101 104 public static final String RECENT = "RECENT"; 105 108 public static final String SEEN = "SEEN"; 109 112 public static final String SINCE = "SINCE"; 113 116 public static final String SUBJECT = "SUBJECT"; 117 120 public static final String TEXT = "TEXT"; 121 124 public static final String TO = "TO"; 125 128 public static final String UNANSWERED = "UNANSWERED"; 129 132 public static final String UNDELETED = "UNDELETED"; 133 136 public static final String UNFLAGGED = "UNFLAGGED"; 137 140 public static final String UNKEYWORD = "UNKEYWORD"; 141 144 public static final String UNSEEN = "UNSEEN"; 145 148 public static final String DRAFT = "DRAFT"; 149 152 public static final String HEADER = "HEADER"; 153 156 public static final String LARGER = "LARGER"; 157 160 public static final String NOT = "NOT"; 161 164 public static final String OR = "OR"; 165 168 public static final String SENTBEFORE = "SENTBEFORE"; 169 172 public static final String SENTON = "SENTON"; 173 176 public static final String SENTSINCE = "SENTSINCE"; 177 180 public static final String SMALLER = "SMALLER"; 181 184 public static final String UID = "UID"; 185 188 public static final String UNDRAFT = "UNDRAFT"; 189 190 191 192 private List list; 193 private String key; 194 private Object arg; 195 private Object arg2; 196 197 202 public SearchKey(String key) { 203 this.key = key; 204 } 205 206 212 public SearchKey(String key, String arg) { 213 this.key = key; 214 this.arg = arg; 215 } 216 217 223 public SearchKey(String key, Integer arg) { 224 this.key = key; 225 this.arg = arg; 226 } 227 228 234 public SearchKey(String key, IMAPDate arg) { 235 this.key = key; 236 this.arg = arg; 237 } 238 239 246 public SearchKey(String key, String arg, String arg2) { 247 this.key = key; 248 this.arg = arg; 249 this.arg2 = arg2; 250 } 251 252 258 public SearchKey(String key, SearchKey arg) { 259 this.key = key; 260 this.arg = arg; 261 } 262 263 270 public SearchKey(String key, SearchKey arg, SearchKey arg2) { 271 this.key = key; 272 this.arg = arg; 273 this.arg2 = arg2; 274 } 275 276 281 public void add( SearchKey key) { 282 if( list == null ) { 283 list = new LinkedList (); 284 } 285 286 list.add(key); 287 } 288 289 296 public String [] toStringArray() { 297 List result = new LinkedList (); 298 if( list != null ) { 299 result.add("("); 300 } 301 302 result.add(key); 303 if( arg != null ) { 304 if( arg instanceof SearchKey ) { 305 result.addAll(Arrays.asList(((SearchKey)arg).toStringArray())); 306 } else { 307 result.add(arg.toString()); 308 } 309 } 310 if( arg2 != null ) { 311 if( arg2 instanceof SearchKey ) { 312 result.addAll(Arrays.asList(((SearchKey)arg2).toStringArray())); 313 } else { 314 result.add(arg2.toString()); 315 } 316 } 317 if( list != null ) { 318 Iterator it = list.iterator(); 319 Object next; 320 while( it.hasNext() ) { 321 next = it.next(); 322 if( next instanceof SearchKey ) { 323 result.addAll(Arrays.asList(((SearchKey)next).toStringArray())); 324 } else { 325 result.add(next.toString()); 326 } 327 } 328 result.add(")"); 329 } 330 return (String []) result.toArray(new String []{}); 331 } 332 333 336 public String toString() { 337 StringBuffer result = new StringBuffer (); 338 339 if( list != null ) { 340 result.append('('); 341 } 342 result.append(key); 343 if( arg != null ) { 344 result.append(' '); 345 result.append(arg.toString()); 346 } 347 if( arg2 != null ) { 348 result.append(' '); 349 result.append(arg2.toString()); 350 } 351 if( list != null ) { 352 Iterator it = list.iterator(); 353 while( it.hasNext() ) { 354 result.append(' '); 355 result.append(it.next().toString()); 356 } 357 result.append(')'); 358 } 359 return result.toString(); 360 } 361 362 } 363 | Popular Tags |