001    package users.events;
002    
003    import users.*;
004    
005    import java.util.*;
006    
007    /**
008     * An event indicating changes in a user's capabilities.
009     *
010     * @see User
011     * @see Capability
012     * @see CapabilityDataListener
013     *
014     * @author Steffen Zschaler
015     * @version 2.0 05/05/1999
016     * @since v2.0
017     */
018    public class CapabilityDataEvent extends EventObject {
019    
020        /**
021             * ID for serialization.
022             */
023            private static final long serialVersionUID = 7424718068336776722L;
024            
025            /**
026         * The capabilities that participated in the change.
027         *
028         * @serial
029         */
030        private Set<String> m_stCapNames;
031    
032        /**
033         * Create a new CapabilityDataEvent with a source and a set of affected capabilities
034         *
035         * @param source the source of the event, usually a User object.
036         * @param stCapNames the set of capabilities that changed.
037         */
038        public CapabilityDataEvent(Object source, Set<String> stCapNames) {
039            super(source);
040    
041            m_stCapNames = stCapNames;
042        }
043    
044        /**
045         * Test whether a given capability is affected by this event.
046         *
047         * @param sCapName the name of the capability to be tested
048         *
049         * @return true if the given capability is affected by this event.
050         *
051         * @override Never
052         */
053        public boolean affectsCapability(String sCapName) {
054            return m_stCapNames.contains(sCapName);
055        }
056    
057        /**
058         * Return a capability if it is affected by this event.
059         *
060         * @param sCapName the name of the capability to be returned.
061         *
062         * @return the capability with the given name, if it is affected by this event.
063         * <code>null</code> otherwise.
064         *
065         * @override Never
066         */
067        public Capability getCapability(String sCapName) {
068            return ((affectsCapability(sCapName)) ? (((User)getSource()).getCapability(sCapName)) : (null));
069        }
070    
071    }