| java.lang.Object java.util.EventObject java.beans.PropertyChangeEvent org.apache.commons.events.observable.CollectionChangeEvent
CollectionChangeEvent | public class CollectionChangeEvent extends PropertyChangeEvent (Code) | |
This event is fired to all registered listeners whenever an observed
collection is altered. The inherited oldValue and
newValue properties are almost always null, as populating
them normally requires that two nearly identical copies of the collection
be maintained. The sole exception to this rule are events which
replace a value in the collection with a different value (e.g., setting
a particular element of a List .)
Instead, this event maintains
information about how the collection was changed. This information
includes:
- The type of action performed on the collection (e.g., add,
remove, clear, etc.).
- The element participating in the action (e.g., the thing which
was added, removed, etc.)
- Whether or not the collection was changed as a result of the action.
For instance, attempting to remove an element which is not in a set does
not change the set.
- An optional parameter which serves as an index or as an
indicator of the number of copies affected, as appropriate for the
event type.
This event is always fired after the proposed action has taken place.
As such, it serves as a notification of an action, not
pre-notification of the action. This same event is fired to
subscribers of bound propertes and constrained
properties. Those who wish to affect whether or not the change
actually occurs should use a ConstrainedCollection. Those who merely wish
to be notified of changes should use an BoundCollection.
The parent of this event is designed to monitor arbitrary properties of
java beans. This class is designed to monitor only changes to
collections. Therefore, the "property" field of this
event is always set to "collection". Likewise, the
"source" property must always be a BoundCollection
or a ConstrainedCollection .
See Also: java.beans.PropertyChangeEvent See Also: BoundCollection See Also: ConstrainedCollection See Also: CollectionChangeType author: Bryce Nordgren / USDA Forest Service |
Field Summary | |
final public static int | NOT_SET A value for the "parameter" property which means
that the property has not been set. | final public static String | PROPERTY The value to which every "property" field is set. |
Constructor Summary | |
public | CollectionChangeEvent(Object source, CollectionChangeType type, boolean changed, Object element, int parameter) Public constructor for an event which monitors changes to
collections. | public | CollectionChangeEvent(Object source, CollectionChangeType type, boolean changed, Object element) | public | CollectionChangeEvent(Object source, CollectionChangeType type, boolean changed) | public | CollectionChangeEvent(Object source, CollectionChangeType type, boolean changed, Object element, Object oldElement, int parameter)
Public constructor which sets the oldValue and newValue properties
of the parent object. | public | CollectionChangeEvent(Object source, CollectionChangeType type, boolean changed, Object key, Object oldValue, Object newValue)
Public constructor which initializes the event appropriately for
reporting a put() event on a Map. |
Method Summary | |
public Object | getElement() A reference to the element participating in the action. | public int | getParameter() The "parameter" is an indication of the index into the
collection or the number of copies added or removed by the operation. | public CollectionChangeType | getType() Describes the action which caused this event. | public boolean | isChanged() Indicates whether the collection was changed as a result of the
action. |
NOT_SET | final public static int NOT_SET(Code) | | A value for the "parameter" property which means
that the property has not been set.
|
PROPERTY | final public static String PROPERTY(Code) | | The value to which every "property" field is set.
|
CollectionChangeEvent | public CollectionChangeEvent(Object source, CollectionChangeType type, boolean changed, Object element, int parameter)(Code) | | Public constructor for an event which monitors changes to
collections. This constructor ensures that the old and
new properties are set to null. It also ensures that the
property name is set to "collection", as specified
by the static PROPERTY field of this class.
Parameters: source - The collection which was modified. Parameters: type - The type of modification. Parameters: changed - Was the collection actually changed? Parameters: element - The element participating in the modification. Parameters: parameter - Used to indicate number of copies or index. |
CollectionChangeEvent | public CollectionChangeEvent(Object source, CollectionChangeType type, boolean changed, Object element, Object oldElement, int parameter)(Code) | |
Public constructor which sets the oldValue and newValue properties
of the parent object. This should be used only when an individual
element of a collection is changed from one value to another. This
is applicable, for instance, when a map entry is changed or a list
entry is set. The constructed object will have identical values for
the "element" property and the "newValue"
property.
Parameters: source - The collection which was modified. Parameters: type - The type of modification. Parameters: changed - Was the collection actually changed? Parameters: element - The new value of the element. Parameters: oldElement - the old value of the element. Parameters: parameter - The index of the changed element. |
CollectionChangeEvent | public CollectionChangeEvent(Object source, CollectionChangeType type, boolean changed, Object key, Object oldValue, Object newValue)(Code) | |
Public constructor which initializes the event appropriately for
reporting a put() event on a Map. The oldValue and
newValue properties are set to the former and current values mapped
to the key. The element property is set to the key.
Parameters: source - The collection which was modified. Parameters: type - The type of modification. Parameters: changed - Was the collection actually changed? Parameters: oldValue - The old value mapped to the key. Parameters: newValue - The new value mapped to the key. Parameters: key - The key which is being put in the Map. |
getElement | public Object getElement()(Code) | | A reference to the element participating in the action. This
may be null if the change was an operation like
clear() .
the element added or removed from the collection. |
getParameter | public int getParameter()(Code) | | The "parameter" is an indication of the index into the
collection or the number of copies added or removed by the operation.
In many cases, the "parameter" will not be set, in which
case it takes on the value NOT_SET .
the index, number of copies, or NOT_SET |
getType | public CollectionChangeType getType()(Code) | | Describes the action which caused this event.
type of action performed on the collection |
isChanged | public boolean isChanged()(Code) | | Indicates whether the collection was changed as a result of the
action.
true if the collection was changed, false otherwise. |
|
|