This is a much updated submission of the event-based notifying
decorator mechanism for collections, as discussed on the list last
month.

The package is too big to be posted to this list. The source, javadoc,
and pre-built jar can be downloaded from:

 http://nettool.sourceforge.net/nc
 
The javadoc can be viewed online:
 
 http://nettool.sourceforge.net/nc/api
 
The best place to start is the package description for
o.a.c.collections.notifying. Either navigate from above, or directly
via:

http://nettool.sourceforge.net/nc/api/org/apache/commons/collections/notifying/package-summary.html#package_description
 

This release provides notifying decorators for Collection, Set,
SortedSet, List, Bag and SortedBag. Map and SortedMap implementations
are present, but are not completed.

NotifyingCollections uses pluggable event factories to generate its
events. There are three such "event packages" included: 'simple',
'rich', and 'monolithic'. The 'simple' package is a bare-bones
implementation (one event class) that is fast and light. The 'rich'
package defines an event hierarchy (with AddEvent, RemoveEvent etc.)
that tracks all delta data necessary to reconstruct a collection's
entire history. In particular, RichCollectionEvent implements
ReplayableEvent (see below). The 'monolithic' event package is (like
'rich') a heavyweight package that implements ReplayableEvent, but has
only one event class (MonolithicCollectionEvent) instead of an
hierarchy. This package is an implementation of the Heuer/mailing-list
design that we discussed some time ago, and is basically intended as a
dis-proof-of-concept. I will discuss this in a follow-on email.

Probably the most interesting new feature is the "ReplayableEvent"
interface. This interface defines two methods, #replay and #undo (may
rename), and is implemented by the 'rich' and 'monolithic' package. An
example of usage is below.


#############################

class MyListener implements CollectionListener
{
        CollectionEvent event;

        public void collectionEventOccurred(CollectionEvent event)
        {
                this.event = event;
        }
}

NotifyingList nl = NotifyingCollectionsUtils.notifyingList(new
ArrayList());

MyListener listener = new MyListener();
nl.addCollectionListener(listener);

String s = "hello";

nl.add(s);
assertTrue(nl.size() == 1);

AddEvent event = (AddEvent) listener.event;
assertTrue(event.getAddedItem() == s);

// now for the fun part
event.undo(nl); // undoes the add action
assertTrue(nl.size() == 0);

// replay the action
event.replay(nl);
assertTrue(nl.size() == 1 && nl.contains(s));

// replay the action on a different target
List list = new ArrayList();

event.replay(list);
assertTrue(list.equals(nl));

############################

More comments in follow-on email.

Neil



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to