001    /*
002     * Copyright 2003-2004 The Apache Software Foundation
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.apache.commons.events.observable.standard;
017    
018    import org.apache.commons.events.observable.ModificationHandler;
019    import org.apache.commons.events.observable.ObservableCollection;
020    
021    /**
022     * Event class that encapsulates all the event information for a
023     * standard collection event.
024     * <p>
025     * The information stored in this event is all that is available as
026     * parameters or return values.
027     * In addition, the <code>size</code> method is used on the collection.
028     * All objects used are the real objects from the method calls, not clones.
029     *
030     * @since Commons Events 1.0
031     * @version $Revision: 155443 $ $Date: 2005-02-26 13:19:51 +0000 (Sat, 26 Feb 2005) $
032     * 
033     * @author Stephen Colebourne
034     */
035    public class StandardPostModificationEvent extends StandardModificationEvent {
036    
037        /** The size after the event */
038        protected final int postSize;
039    
040        // Constructor
041        //-----------------------------------------------------------------------
042        /**
043         * Constructor.
044         * 
045         * @param obsCollection  the event source
046         * @param handler  the handler
047         * @param type  the event type
048         * @param preSize  the size before the change
049         * @param index  the index that changed
050         * @param object  the value that changed
051         * @param repeat  the number of repeats
052         * @param previous  the previous value being removed/replaced
053         * @param view  the view collection, null if event from main collection
054         * @param viewOffset  the offset within the main collection of the view, -1 if unknown
055         */
056        public StandardPostModificationEvent(
057            final ObservableCollection obsCollection,
058            final ModificationHandler handler,
059            final int type,
060            final int preSize,
061            final int index,
062            final Object object,
063            final int repeat,
064            final Object previous,
065            final ObservableCollection view,
066            final int viewOffset) {
067    
068            super(obsCollection, handler, type, preSize, index,
069                object, repeat, previous, view, viewOffset);
070            postSize = collection.size();
071        }
072    
073        // Size info
074        //-----------------------------------------------------------------------
075        /**
076         * Gets the size after the change.
077         * 
078         * @return the size after the change
079         */
080        public int getPostSize() {
081            return postSize;
082        }
083    
084        /**
085         * Gets the size change, negative for remove/clear.
086         * 
087         * @return the size before the change
088         */
089        public int getSizeChange() {
090            return postSize - preSize;
091        }
092    
093        /**
094         * Returns true if the size of the collection changed.
095         * 
096         * @return true is the size changed
097         */
098        public boolean isSizeChanged() {
099            return (preSize != postSize);
100        }
101    
102    }