Sort (a copy of) the given array of messages and then run thru the sorted 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
(Message[] msgs, Condition cond)
| 120 | * @since JavaMail 1.5.4 |
| 121 | */ |
| 122 | public static MessageSet[] toMessageSetSorted(Message[] msgs, |
| 123 | Condition cond) { |
| 124 | /* |
| 125 | * XXX - This is quick and dirty. A more efficient strategy would be |
| 126 | * to generate an array of message numbers by applying the condition |
| 127 | * (with zero indicating the message doesn't satisfy the condition), |
| 128 | * sort it, and then convert it to a MessageSet skipping all the zeroes. |
| 129 | */ |
| 130 | msgs = msgs.clone(); |
| 131 | Arrays.sort(msgs, |
| 132 | new Comparator<Message>() { |
| 133 | @Override |
| 134 | public int compare(Message msg1, Message msg2) { |
| 135 | return msg1.getMessageNumber() - msg2.getMessageNumber(); |
| 136 | } |
| 137 | }); |
| 138 | return toMessageSet(msgs, cond); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Return UIDSets for the messages. Note that the UIDs |