Path: blob/master/src/java.desktop/share/classes/java/beans/beancontext/BeanContextMembershipEvent.java
41159 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.beans.beancontext;2627import java.io.Serial;28import java.util.Arrays;29import java.util.Collection;30import java.util.Iterator;3132/**33* A {@code BeanContextMembershipEvent} encapsulates34* the list of children added to, or removed from,35* the membership of a particular {@code BeanContext}.36* An instance of this event is fired whenever a successful37* add(), remove(), retainAll(), removeAll(), or clear() is38* invoked on a given {@code BeanContext} instance.39* Objects interested in receiving events of this type must40* implement the {@code BeanContextMembershipListener}41* interface, and must register their intent via the42* {@code BeanContext}'s43* {@code addBeanContextMembershipListener(BeanContextMembershipListener bcml)}44* method.45*46* @author Laurence P. G. Cable47* @since 1.248* @see java.beans.beancontext.BeanContext49* @see java.beans.beancontext.BeanContextEvent50* @see java.beans.beancontext.BeanContextMembershipListener51*/52public class BeanContextMembershipEvent extends BeanContextEvent {5354/**55* Use serialVersionUID from JDK 1.7 for interoperability.56*/57@Serial58private static final long serialVersionUID = 3499346510334590959L;5960/**61* Contruct a BeanContextMembershipEvent62*63* @param bc The BeanContext source64* @param changes The Children affected65* @throws NullPointerException if {@code changes} is {@code null}66*/6768@SuppressWarnings("rawtypes")69public BeanContextMembershipEvent(BeanContext bc, Collection changes) {70super(bc);7172if (changes == null) throw new NullPointerException(73"BeanContextMembershipEvent constructor: changes is null.");7475children = changes;76}7778/**79* Contruct a BeanContextMembershipEvent80*81* @param bc The BeanContext source82* @param changes The Children effected83* @exception NullPointerException if changes associated with this84* event are null.85*/8687public BeanContextMembershipEvent(BeanContext bc, Object[] changes) {88super(bc);8990if (changes == null) throw new NullPointerException(91"BeanContextMembershipEvent: changes is null.");9293children = Arrays.asList(changes);94}9596/**97* Gets the number of children affected by the notification.98* @return the number of children affected by the notification99*/100public int size() { return children.size(); }101102/**103* Is the child specified affected by the event?104* @return {@code true} if affected, {@code false}105* if not106* @param child the object to check for being affected107*/108public boolean contains(Object child) {109return children.contains(child);110}111112/**113* Gets the array of children affected by this event.114* @return the array of children affected115*/116public Object[] toArray() { return children.toArray(); }117118/**119* Gets the array of children affected by this event.120* @return the array of children effected121*/122@SuppressWarnings("rawtypes")123public Iterator iterator() { return children.iterator(); }124125/*126* fields127*/128129/**130* The list of children affected by this131* event notification.132*/133@SuppressWarnings({"rawtypes",134"serial"}) // Not statically typed as Serializable135protected Collection children;136}137138139