|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.collections.collection.AbstractCollectionDecorator org.apache.commons.events.observable.ObservableCollection org.apache.commons.events.observable.ObservableBag
public class ObservableBag
Decorates a Bag
implementation to observe modifications.
Each modifying method call made on this Bag
is forwarded to a
ModificationHandler
.
The handler manages the event, notifying listeners and optionally vetoing changes.
The default handler is
StandardModificationHandler
.
See this class for details of configuration available.
NOTE: The uniqueSet()
method returns a Set
that is
NOT observed. This is because the set should be unmodifiable.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.apache.commons.events.observable.ObservableCollection |
---|
ObservableCollection.ObservableIterator |
Field Summary |
---|
Fields inherited from class org.apache.commons.events.observable.ObservableCollection |
---|
handler |
Fields inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator |
---|
collection |
Constructor Summary | |
---|---|
protected |
ObservableBag(org.apache.commons.collections.Bag bag,
Object listener)
Constructor that wraps (not copies). |
Method Summary | |
---|---|
boolean |
add(Object object)
|
boolean |
add(Object object,
int nCopies)
|
static ObservableBag |
decorate(org.apache.commons.collections.Bag bag)
Factory method to create an observable bag. |
static ObservableBag |
decorate(org.apache.commons.collections.Bag bag,
Object listener)
Factory method to create an observable bag using a listener or a handler. |
int |
getCount(Object object)
|
boolean |
remove(Object object,
int nCopies)
|
Set |
uniqueSet()
|
Methods inherited from class org.apache.commons.events.observable.ObservableCollection |
---|
addAll, clear, createHandler, decorate, decorate, getHandler, iterator, registerFactory, remove, removeAll, retainAll |
Methods inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator |
---|
contains, containsAll, equals, getCollection, hashCode, isEmpty, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.apache.commons.collections.Bag |
---|
containsAll, iterator, remove, removeAll, retainAll, size |
Methods inherited from interface java.util.Collection |
---|
addAll, clear, contains, equals, hashCode, isEmpty, toArray, toArray |
Constructor Detail |
---|
protected ObservableBag(org.apache.commons.collections.Bag bag, Object listener)
The handler implementation is determined by the listener parameter via
the registered factories. The listener may be a manually configured
ModificationHandler
instance.
bag
- the bag to decorate, must not be nulllistener
- the listener, may be null
IllegalArgumentException
- if the bag is nullMethod Detail |
---|
public static ObservableBag decorate(org.apache.commons.collections.Bag bag)
A StandardModificationHandler
will be created.
This can be accessed by ObservableCollection.getHandler()
to add listeners.
bag
- the bag to decorate, must not be null
IllegalArgumentException
- if the bag is nullpublic static ObservableBag decorate(org.apache.commons.collections.Bag bag, Object listener)
A lot of functionality is available through this method.
If you don't need the extra functionality, simply implement the
StandardModificationListener
interface and pass it in as the second parameter.
Internally, an ObservableBag
relies on a ModificationHandler
.
The handler receives all the events and processes them, typically by
calling listeners. Different handler implementations can be plugged in
to provide a flexible event system.
The handler implementation is determined by the listener parameter via
the registered factories. The listener may be a manually configured
ModificationHandler
instance.
The listener is defined as an Object for maximum flexibility. It does not have to be a listener in the classic JavaBean sense. It is entirely up to the factory and handler as to how the parameter is interpretted. An IllegalArgumentException is thrown if no suitable handler can be found for this listener.
A null
listener will create a
StandardModificationHandler
.
bag
- the bag to decorate, must not be nulllistener
- bag listener, may be null
IllegalArgumentException
- if the bag is null
IllegalArgumentException
- if there is no valid handler for the listenerpublic int getCount(Object object)
getCount
in interface org.apache.commons.collections.Bag
public Set uniqueSet()
uniqueSet
in interface org.apache.commons.collections.Bag
public boolean add(Object object)
add
in interface Collection
add
in interface org.apache.commons.collections.Bag
add
in class ObservableCollection
public boolean add(Object object, int nCopies)
add
in interface org.apache.commons.collections.Bag
public boolean remove(Object object, int nCopies)
remove
in interface org.apache.commons.collections.Bag
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |