org.apache.commons.events.observable.standard
Class StandardModificationEvent

java.lang.Object
  extended by java.util.EventObject
      extended by org.apache.commons.events.observable.ModificationEvent
          extended by org.apache.commons.events.observable.standard.StandardModificationEvent
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
StandardPostModificationEvent, StandardPreModificationEvent

public class StandardModificationEvent
extends ModificationEvent

Event class that encapsulates the event information for a standard collection event. Two subclasses are provided, one for pre and one for post events.

The information stored in this event is all that is available as parameters or return values. In addition, the size method is used on the collection. All objects used are the real objects from the method calls, not clones.

Since:
Commons Events 1.0
Version:
$Revision: 155443 $ $Date: 2005-02-26 13:19:51 +0000 (Sat, 26 Feb 2005) $
Author:
Stephen Colebourne
See Also:
Serialized Form

Field Summary
protected  int index
          The index of the change
protected  Object object
          The object of the change
protected  int preSize
          The size before the event
protected  Object previous
          The result of the method call
protected  int repeat
          The number of changes
protected  ObservableCollection view
          The view that the event came from, null if none
protected  int viewOffset
          The offset index within the main collection of the view, -1 if none
 
Fields inherited from class org.apache.commons.events.observable.ModificationEvent
collection, handler, type
 
Fields inherited from class java.util.EventObject
source
 
Constructor Summary
StandardModificationEvent(ObservableCollection obsCollection, ModificationHandler handler, int type, int preSize, int index, Object object, int repeat, Object previous, ObservableCollection view, int viewOffset)
          Constructor.
 
Method Summary
 Collection getChangeCollection()
          Gets the collection of changed objects.
 int getChangeIndex()
          Gets the index of the change.
 Object getChangeObject()
          Gets the object that was added/removed/set.
 int getChangeRepeat()
          Gets the number of times the object was added/removed.
 int getPreSize()
          Gets the size before the change.
 Object getPrevious()
          Gets the previous value that is being replaced or removed.
 ObservableCollection getView()
          Gets the view, null if none.
 int getViewOffset()
          Gets the view offset, -1 if no view or unknown offset.
 boolean isType(int eventType)
          Checks to see if the event is of the specified type.
 boolean isTypeAdd()
          Checks to see if the event is an add event (add/addAll).
 boolean isTypeBulk()
          Checks to see if the event is a bulk event (addAll/removeAll/retainAll/clear).
 boolean isTypeChange()
          Checks to see if the event is a change event (set).
 boolean isTypeReduce()
          Checks to see if the event is a remove event (remove/removeAll/retainAll/clear).
 boolean isView()
          Checks whether the event originated from a view.
 String toString()
          Gets a debugging string version of the event.
 
Methods inherited from class org.apache.commons.events.observable.ModificationEvent
getBaseCollection, getHandler, getObservedCollection, getType
 
Methods inherited from class java.util.EventObject
getSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

preSize

protected final int preSize
The size before the event


index

protected final int index
The index of the change


object

protected final Object object
The object of the change


repeat

protected final int repeat
The number of changes


previous

protected final Object previous
The result of the method call


view

protected final ObservableCollection view
The view that the event came from, null if none


viewOffset

protected final int viewOffset
The offset index within the main collection of the view, -1 if none

Constructor Detail

StandardModificationEvent

public StandardModificationEvent(ObservableCollection obsCollection,
                                 ModificationHandler handler,
                                 int type,
                                 int preSize,
                                 int index,
                                 Object object,
                                 int repeat,
                                 Object previous,
                                 ObservableCollection view,
                                 int viewOffset)
Constructor.

Parameters:
obsCollection - the event source
handler - the handler
type - the event type
preSize - the size before the change
index - the index that changed
object - the value that changed
repeat - the number of repeats
previous - the previous value being removed/replaced
view - the view collection, null if event from main collection
viewOffset - the offset within the main collection of the view, -1 if unknown
Method Detail

getChangeIndex

public int getChangeIndex()
Gets the index of the change.

This is -1 when not applicable. Typically only used for List events.

Returns:
the change index

getChangeObject

public Object getChangeObject()
Gets the object that was added/removed/set.

This is null when not applicable, such as for clear().

Returns:
the changing object

getChangeCollection

public Collection getChangeCollection()
Gets the collection of changed objects.

For clear, it is an empty list. For bulk operations, it is the collection. For non-bulk operations, it is a size one list.

Returns:
the changing collection, never null

getChangeRepeat

public int getChangeRepeat()
Gets the number of times the object was added/removed.

This is normally 1, but will be used for Bag events.

Returns:
the repeat

getPrevious

public Object getPrevious()
Gets the previous value that is being replaced or removed.

This is only returned if the value definitely was previously in the collection. Bulk operatons will not return this.

Returns:
the previous value that was removed/replaced

getPreSize

public int getPreSize()
Gets the size before the change.

Returns:
the size before the change

getView

public ObservableCollection getView()
Gets the view, null if none.

A view is a subSet, headSet, tailSet, subList and so on.

Returns:
the view

isView

public boolean isView()
Checks whether the event originated from a view.

Returns:
true if event came from a view

getViewOffset

public int getViewOffset()
Gets the view offset, -1 if no view or unknown offset.

This refers to the index of the start of the view within the main collection.

Returns:
the view offset

isTypeAdd

public boolean isTypeAdd()
Checks to see if the event is an add event (add/addAll).

Returns:
true if of the specified type

isTypeReduce

public boolean isTypeReduce()
Checks to see if the event is a remove event (remove/removeAll/retainAll/clear).

Returns:
true if of the specified type

isTypeChange

public boolean isTypeChange()
Checks to see if the event is a change event (set).

Returns:
true if of the specified type

isTypeBulk

public boolean isTypeBulk()
Checks to see if the event is a bulk event (addAll/removeAll/retainAll/clear).

Returns:
true if of the specified type

isType

public boolean isType(int eventType)
Checks to see if the event is of the specified type.

This is any combination of constants from ModificationEventType.

Parameters:
eventType - an event type constant
Returns:
true if of the specified type

toString

public String toString()
Gets a debugging string version of the event.

Overrides:
toString in class ModificationEvent
Returns:
a debugging string


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.