01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16: package org.columba.mail.imap;
17:
18: import java.util.ArrayList;
19: import java.util.Arrays;
20: import java.util.Iterator;
21: import java.util.List;
22:
23: /**
24: * Cuts a list/array of uids in pieces of certain size.
25: *
26: * @author fdietz
27: */
28: public class MessageSetTokenizer implements Iterator {
29: Object[] uids;
30: List list;
31: int index;
32: int sizeOfPieces;
33: int count;
34: int rest;
35:
36: public MessageSetTokenizer(List l, int sizeOfPieces) {
37: this .uids = l.toArray();
38:
39: this .sizeOfPieces = sizeOfPieces;
40:
41: index = 0;
42:
43: count = uids.length / sizeOfPieces;
44: rest = uids.length % sizeOfPieces;
45:
46: list = new ArrayList(Arrays.asList(uids));
47: }
48:
49: public MessageSetTokenizer(Object[] uids, int sizeOfPieces) {
50: this .uids = uids;
51: this .sizeOfPieces = sizeOfPieces;
52:
53: index = 0;
54:
55: count = uids.length / sizeOfPieces;
56: rest = uids.length % sizeOfPieces;
57:
58: list = new ArrayList(Arrays.asList(uids));
59: }
60:
61: /* (non-Javadoc)
62: * @see java.util.Iterator#hasNext()
63: */
64: public boolean hasNext() {
65: if (index < uids.length) {
66: return true;
67: }
68:
69: return false;
70: }
71:
72: /* (non-Javadoc)
73: * @see java.util.Iterator#next()
74: */
75: public Object next() {
76: int i = sizeOfPieces;
77:
78: // calculate rest
79: if ((index + sizeOfPieces) > uids.length) {
80: i = uids.length - index;
81: }
82:
83: List sublist = list.subList(index, index + i);
84:
85: index = index + i;
86:
87: return sublist;
88: }
89:
90: /* (non-Javadoc)
91: * @see java.util.Iterator#remove()
92: */
93: public void remove() {
94: // not needed
95: }
96: }
|