|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| MessageCountEvent.java | - | 88.2% | 60% | 81.8% |
|
||||||||||||||
| 1 | /** | |
| 2 | * | |
| 3 | * Copyright 2003-2006 The Apache Software Foundation | |
| 4 | * | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | ||
| 18 | package javax.mail.event; | |
| 19 | ||
| 20 | import javax.mail.Folder; | |
| 21 | import javax.mail.Message; | |
| 22 | ||
| 23 | /** | |
| 24 | * Event indicating a change in the number of messages in a folder. | |
| 25 | * | |
| 26 | * @version $Rev: 421852 $ $Date: 2006-07-14 03:02:19 -0700 (Fri, 14 Jul 2006) $ | |
| 27 | */ | |
| 28 | public class MessageCountEvent extends MailEvent { | |
| 29 | /** | |
| 30 | * Messages were added to the folder. | |
| 31 | */ | |
| 32 | public static final int ADDED = 1; | |
| 33 | ||
| 34 | /** | |
| 35 | * Messages were removed from the folder. | |
| 36 | */ | |
| 37 | public static final int REMOVED = 2; | |
| 38 | ||
| 39 | /** | |
| 40 | * The affected messages. | |
| 41 | */ | |
| 42 | protected transient Message msgs[]; | |
| 43 | ||
| 44 | /** | |
| 45 | * The event type. | |
| 46 | */ | |
| 47 | protected int type; | |
| 48 | ||
| 49 | /** | |
| 50 | * If true, then messages were expunged from the folder by this client | |
| 51 | * and message numbers reflect the deletion; if false, then the change | |
| 52 | * was the result of an expunge by a different client. | |
| 53 | */ | |
| 54 | protected boolean removed; | |
| 55 | ||
| 56 | /** | |
| 57 | * Construct a new event. | |
| 58 | * | |
| 59 | * @param folder the folder containing the messages | |
| 60 | * @param type the event type | |
| 61 | * @param removed indicator of whether messages were expunged by this client | |
| 62 | * @param messages the affected messages | |
| 63 | */ | |
| 64 | 3 | public MessageCountEvent(Folder folder, int type, boolean removed, Message messages[]) { |
| 65 | 3 | super(folder); |
| 66 | 3 | this.msgs = messages; |
| 67 | 3 | this.type = type; |
| 68 | 3 | this.removed = removed; |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * Return the event type. | |
| 73 | * | |
| 74 | * @return the event type | |
| 75 | */ | |
| 76 | 3 | public int getType() { |
| 77 | 3 | return type; |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * @return whether this event was the result of an expunge by this client | |
| 82 | * @see MessageCountEvent#removed | |
| 83 | */ | |
| 84 | 0 | public boolean isRemoved() { |
| 85 | 0 | return removed; |
| 86 | } | |
| 87 | ||
| 88 | /** | |
| 89 | * Return the affected messages. | |
| 90 | * | |
| 91 | * @return the affected messages | |
| 92 | */ | |
| 93 | 0 | public Message[] getMessages() { |
| 94 | 0 | return msgs; |
| 95 | } | |
| 96 | ||
| 97 | 3 | public void dispatch(Object listener) { |
| 98 | 3 | MessageCountListener l = (MessageCountListener) listener; |
| 99 | 3 | switch (type) { |
| 100 | 1 | case ADDED: |
| 101 | 1 | l.messagesAdded(this); |
| 102 | 1 | break; |
| 103 | 1 | case REMOVED: |
| 104 | 1 | l.messagesRemoved(this); |
| 105 | 1 | break; |
| 106 | 1 | default: |
| 107 | 1 | throw new IllegalArgumentException("Invalid type " + type); |
| 108 | } | |
| 109 | } | |
| 110 | } |
|
||||||||||