Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StandardPostModificationEvent |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright 2003-2004 The Apache Software Foundation | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.apache.commons.events.observable.standard; | |
17 | ||
18 | import org.apache.commons.events.observable.ModificationHandler; | |
19 | import org.apache.commons.events.observable.ObservableCollection; | |
20 | ||
21 | /** | |
22 | * Event class that encapsulates all the event information for a | |
23 | * standard collection event. | |
24 | * <p> | |
25 | * The information stored in this event is all that is available as | |
26 | * parameters or return values. | |
27 | * In addition, the <code>size</code> method is used on the collection. | |
28 | * All objects used are the real objects from the method calls, not clones. | |
29 | * | |
30 | * @since Commons Events 1.0 | |
31 | * @version $Revision: 155443 $ $Date: 2005-02-26 13:19:51 +0000 (Sat, 26 Feb 2005) $ | |
32 | * | |
33 | * @author Stephen Colebourne | |
34 | */ | |
35 | public class StandardPostModificationEvent extends StandardModificationEvent { | |
36 | ||
37 | /** The size after the event */ | |
38 | protected final int postSize; | |
39 | ||
40 | // Constructor | |
41 | //----------------------------------------------------------------------- | |
42 | /** | |
43 | * Constructor. | |
44 | * | |
45 | * @param obsCollection the event source | |
46 | * @param handler the handler | |
47 | * @param type the event type | |
48 | * @param preSize the size before the change | |
49 | * @param index the index that changed | |
50 | * @param object the value that changed | |
51 | * @param repeat the number of repeats | |
52 | * @param previous the previous value being removed/replaced | |
53 | * @param view the view collection, null if event from main collection | |
54 | * @param viewOffset the offset within the main collection of the view, -1 if unknown | |
55 | */ | |
56 | public StandardPostModificationEvent( | |
57 | final ObservableCollection obsCollection, | |
58 | final ModificationHandler handler, | |
59 | final int type, | |
60 | final int preSize, | |
61 | final int index, | |
62 | final Object object, | |
63 | final int repeat, | |
64 | final Object previous, | |
65 | final ObservableCollection view, | |
66 | final int viewOffset) { | |
67 | ||
68 | 0 | super(obsCollection, handler, type, preSize, index, |
69 | object, repeat, previous, view, viewOffset); | |
70 | 0 | postSize = collection.size(); |
71 | 0 | } |
72 | ||
73 | // Size info | |
74 | //----------------------------------------------------------------------- | |
75 | /** | |
76 | * Gets the size after the change. | |
77 | * | |
78 | * @return the size after the change | |
79 | */ | |
80 | public int getPostSize() { | |
81 | 0 | return postSize; |
82 | } | |
83 | ||
84 | /** | |
85 | * Gets the size change, negative for remove/clear. | |
86 | * | |
87 | * @return the size before the change | |
88 | */ | |
89 | public int getSizeChange() { | |
90 | 0 | return postSize - preSize; |
91 | } | |
92 | ||
93 | /** | |
94 | * Returns true if the size of the collection changed. | |
95 | * | |
96 | * @return true is the size changed | |
97 | */ | |
98 | public boolean isSizeChanged() { | |
99 | 0 | return (preSize != postSize); |
100 | } | |
101 | ||
102 | } |