Run thru the given array of messages, apply the given Condition on each message and generate sets of contiguous sequence-numbers for the successful messages. If a message in the given array is found to be expunged, it is ignored. ASSERT: Since this method uses and returns message sequence numbers,
(Message[] msgs, Condition cond)
| 53 | * @return the MessageSet array |
| 54 | */ |
| 55 | public static MessageSet[] toMessageSet(Message[] msgs, Condition cond) { |
| 56 | List<MessageSet> v = new ArrayList<>(1); |
| 57 | int current, next; |
| 58 | |
| 59 | IMAPMessage msg; |
| 60 | for (int i = 0; i < msgs.length; i++) { |
| 61 | msg = (IMAPMessage)msgs[i]; |
| 62 | if (msg.isExpunged()) // expunged message, skip it |
| 63 | continue; |
| 64 | |
| 65 | current = msg.getSequenceNumber(); |
| 66 | // Apply the condition. If it fails, skip it. |
| 67 | if ((cond != null) && !cond.test(msg)) |
| 68 | continue; |
| 69 | |
| 70 | MessageSet set = new MessageSet(); |
| 71 | set.start = current; |
| 72 | |
| 73 | // Look for contiguous sequence numbers |
| 74 | for (++i; i < msgs.length; i++) { |
| 75 | // get next message |
| 76 | msg = (IMAPMessage)msgs[i]; |
| 77 | |
| 78 | if (msg.isExpunged()) // expunged message, skip it |
| 79 | continue; |
| 80 | next = msg.getSequenceNumber(); |
| 81 | |
| 82 | // Does this message match our condition ? |
| 83 | if ((cond != null) && !cond.test(msg)) |
| 84 | continue; |
| 85 | |
| 86 | if (next == current+1) |
| 87 | current = next; |
| 88 | else { // break in sequence |
| 89 | // We need to reexamine this message at the top of |
| 90 | // the outer loop, so decrement 'i' to cancel the |
| 91 | // outer loop's autoincrement |
| 92 | i--; |
| 93 | break; |
| 94 | } |
| 95 | } |
| 96 | set.end = current; |
| 97 | v.add(set); |
| 98 | } |
| 99 | |
| 100 | if (v.isEmpty()) // No valid messages |
| 101 | return null; |
| 102 | else { |
| 103 | return v.toArray(new MessageSet[v.size()]); |
| 104 | } |
| 105 | } |
| 106 | /** |
| 107 | * Sort (a copy of) the given array of messages and then |
| 108 | * run thru the sorted array of messages, apply the given |
no test coverage detected