1 36 package org.columba.ristretto.imap; 37 38 import java.util.Arrays ; 39 import java.util.Collections ; 40 import java.util.Iterator ; 41 import java.util.List ; 42 43 48 public class MessageSet { 49 50 protected String messageSetString; 51 52 57 public MessageSet( Object [] uids) { 58 messageSetString = render( uids ); 59 } 60 61 66 public String getString() 67 { 68 return messageSetString; 69 } 70 71 protected String render(Object [] uids) { 72 StringBuffer result = new StringBuffer (); 73 74 List uidList = Arrays.asList(uids); 75 Collections.sort( uidList ); 76 Iterator it = uidList.iterator(); 77 boolean inRange = false; 78 int lastValue = ((Integer )it.next()).intValue(); 79 int nextValue; 80 81 result.append(lastValue); 83 84 while( it.hasNext() ) { 85 nextValue = ((Integer ) it.next()).intValue(); 86 if( nextValue == lastValue + 1) { 88 inRange = true; 89 } else { 90 if( inRange ) { 92 result.append(':'); 93 result.append(lastValue); 94 95 inRange = false; 96 } 97 98 result.append(','); 100 result.append(nextValue); 101 } 102 103 lastValue = nextValue; 104 } 105 106 if( inRange ) { 108 result.append(':'); 109 result.append(lastValue); 110 } 111 112 return result.toString(); 113 } 114 115 } 116 | Popular Tags |