Abstract sets of items
July 22nd, 2005 at 9:00 am (2 years, 11 months ago) by Andi Vajda under chandlerdbA new type of value was added to the data model that combines sets of items using set arithmetic. Abstract sets of items do not store any item references but evaluate their operator against the sets or collections they wrap to implement appartenance tests and iteration. In addition, abstract sets notify their owner item whenever an item is added or removed from a backing collection.
Because it doesn’t actually store any items, an abstract set is considered to be a regular ‘literal’ value owned by an attribute on an item, expressed by the set owner tuple(item, attribute).
An abstract set is constructed around other sets and ultimately around concrete item sets, that is, ref collections. An abstract set can be nested in another set by value (same set owners) or by reference (different set owners).For example, the Chandler content model item collection is defined as the combination of three ref collections: results, inclusions and exclusions. Let
ic be an ItemCollection item, a functionally equivalent set can be constructed as follows:
Difference(Union((ic, 'results'), (ic, 'inclusions')), (ic, 'exclusions'))
The outer set - the difference - wraps the inner set - the union - by value and the ‘exclusions’ ref collection by reference. The inner set wraps the ‘results’ and ‘inclusions’ ref collections by reference as well.
The outer set can then be stored in an attribute on an item, which becomes its owner. From that point on, whenever an item is added to or removed from any of the concrete collections backing the set, a notification is sent to its owner item by invoking its collectionChanged() method. As a notification travels up the set tree from its source, it is evaluated against the node’s operator and is either discarded, inverted or passed on.For example, in the above set, if an item is added to
ic.results and it already belongs to ic.inclusions, the corresponding ‘add’ notification is discarded. Similarly, if an item is added to ic.exclusions and it belongs to the union, the corresponding ‘add’ notification is changed into a ‘remove’ notification.
As with ref collections, one or more indexes can be added to abstract sets so that they can be iterated over in a particular order or so that item references can be retrieved by a numeric location.
All abstract set implementations are located in the repository.item.Sets module: - Union, wraps two sets or collections and represents the set of items that belong to one or the other, inclusively.
- Intersection, wraps two sets or collections and represents the set of items that belong to both.
- Difference, wraps two sets or collections and represents the set of items that belong to the first but not to the second.
- KindSet, wraps no set or collection but represents the set of all items of a given kind, exactly or recursively. Whenever an item is created, deleted or stamped to that kind, the corresponding ‘add’ or ‘remove’ notification is sent to the owner item’s collectionChanged() method.
- FilterSet, wraps another set or collection and represents the set of all the items of that set that pass the filter test.








