1 9 package com.sun.mail.imap.protocol; 10 11 import java.util.Vector ; 12 13 17 public class UIDSet { 18 19 public long start; 20 public long end; 21 22 public UIDSet() { } 23 24 public UIDSet(long start, long end) { 25 this.start = start; 26 this.end = end; 27 } 28 29 32 public long size() { 33 return end - start + 1; 34 } 35 36 39 public static UIDSet[] createUIDSets(long[] msgs) { 40 Vector v = new Vector (); 41 int i,j; 42 43 for (i=0; i < msgs.length; i++) { 44 UIDSet ms = new UIDSet(); 45 ms.start = msgs[i]; 46 47 for (j=i+1; j < msgs.length; j++) { 49 if (msgs[j] != msgs[j-1] +1) 50 break; 51 } 52 ms.end = msgs[j-1]; 53 v.addElement(ms); 54 i = j-1; } 56 UIDSet[] msgsets = new UIDSet[v.size()]; 57 v.copyInto(msgsets); 58 return msgsets; 59 } 60 61 64 public static String toString(UIDSet[] msgsets) { 65 if (msgsets == null || msgsets.length == 0) return null; 67 68 int i = 0; StringBuffer s = new StringBuffer (); 70 int size = msgsets.length; 71 long start, end; 72 73 for (;;) { 74 start = msgsets[i].start; 75 end = msgsets[i].end; 76 77 if (end > start) 78 s.append(start).append(':').append(end); 79 else s.append(start); 81 82 i++; if (i >= size) break; 85 else 86 s.append(','); 87 } 88 return s.toString(); 89 } 90 91 92 95 public static long size(UIDSet[] msgsets) { 96 long count = 0; 97 98 if (msgsets == null) return 0; 100 101 for (int i=0; i < msgsets.length; i++) 102 count += msgsets[i].size(); 103 104 return count; 105 } 106 } 107 | Popular Tags |