Package muntjac :: Package data :: Package util :: Module abstract_in_memory_container :: Class AbstractInMemoryContainer
[hide private]
[frames] | no frames]

Class AbstractInMemoryContainer

source code

                      object --+        
                               |        
            container.IContainer --+    
                                   |    
abstract_container.AbstractContainer --+
                                       |
                          object --+   |
                                   |   |
    container.IItemSetChangeNotifier --+
                                       |
                  object --+           |
                           |           |
        container.IContainer --+       |
                               |       |
              container.IOrdered --+   |
                                   |   |
                  container.IIndexed --+
                                       |
                                      AbstractInMemoryContainer
Known Subclasses:

Abstract IContainer class that handles common functionality for in-memory containers. Concrete in-memory container classes can either inherit this class, inherit AbstractContainer, or implement the IContainer interface directly.

Adding and removing items (if desired) must be implemented in subclasses by overriding the appropriate add*Item() and remove*Item() and removeAllItems() methods, calling the corresponding internalAddItemAfter, internalAddItemAt, internalAddItemAtEnd, internalRemoveItem and internalRemoveAllItems methods.

By default, adding and removing container properties is not supported, and subclasses need to implement getContainerPropertyIds. Optionally, subclasses can override addContainerProperty and removeContainerProperty to implement them.

Features:

To implement ISortable, subclasses need to implement getSortablePropertyIds and call the superclass method sortContainer in the method sort(object[], bool[]).

To implement IFilterable, subclasses need to implement the methods Filterable.addContainerFilter (calling addFilter), Filterable.removeAllContainerFilters (calling removeAllFilters) and Filterable.removeContainerFilter (calling removeFilter).

To implement ISimpleFilterable, subclasses also need to implement the methods SimpleFilterable.addContainerFilter and SimpleFilterable.removeContainerFilters calling addFilter and removeFilters respectively.

<ITEMIDTYPE>: the class of item identifiers in the container, use object if can be any class

<PROPERTYIDCLASS>: the class of property identifiers for the items in the container, use Object if can be any class

<ITEMCLASS>: the (base) class of the Item instances in the container, use Item if unknown

Instance Methods [hide private]
 
__init__(self)
Constructor for an abstract in-memory container.
source code
 
getItem(self, itemId)
Gets the Item with the given Item ID from the IContainer.
source code
 
getUnfilteredItem(self, itemId)
Get an item even if filtered out.
source code
 
size(self)
Gets the number of visible Items in the IContainer.
source code
 
__len__(self) source code
 
containsId(self, itemId)
Tests if the IContainer contains the specified Item.
source code
 
getItemIds(self)
Gets the ID's of all visible (after filtering and sorting) Items stored in the IContainer.
source code
 
nextItemId(self, itemId)
Gets the ID of the Item following the Item that corresponds to itemId.
source code
 
prevItemId(self, itemId)
Gets the ID of the Item preceding the Item that corresponds to itemId.
source code
 
firstItemId(self)
Gets the ID of the first Item in the IContainer.
source code
 
lastItemId(self)
Gets the ID of the last Item in the IContainer..
source code
 
isFirstId(self, itemId)
Tests if the Item corresponding to the given Item ID is the first Item in the IContainer.
source code
 
isLastId(self, itemId)
Tests if the Item corresponding to the given Item ID is the last Item in the IContainer.
source code
 
getIdByIndex(self, index)
Gets the ID of an Item by an index number.
source code
 
indexOfId(self, itemId)
Gets the index of the Item corresponding to the itemId.
source code
 
addItemAt(self, index, newItemId=None)
Adds a new item at given index (in the filtered view).
source code
 
addItemAfter(self, previousItemId, newItemId=None)
Adds a new item after the given item.
source code
 
addItem(self, itemId=None)
Creates a new Item with the given ID in the IContainer.
source code
 
removeItem(self, itemId)
Removes the Item identified by ItemId from the IContainer.
source code
 
removeAllItems(self)
Removes all Items from the IContainer.
source code
 
addContainerProperty(self, propertyId, typ, defaultValue)
Adds a new Property to all Items in the IContainer.
source code
 
removeContainerProperty(self, propertyId)
Removes a Property specified by the given Property ID from the IContainer.
source code
 
addListener(self, listener, iface=None)
Implementation of the corresponding method in IPropertySetChangeNotifier and ItemSetChangeNotifier, override and implement the interface to use this.
source code
 
addCallback(self, callback, eventType=None, *args) source code
 
removeListener(self, listener, iface=None)
Implementation of the corresponding method in IPropertySetChangeNotifier and ItemSetChangeNotifier, override and implement the interface to use this.
source code
 
removeCallback(self, callback, eventType=None) source code
 
filterAll(self)
Filter the view to recreate the visible item list from the unfiltered items, and send a notification if the set of visible items changed in any way.
source code
 
doFilterContainer(self, hasFilters)
Filters the data in the container and updates internal data structures.
source code
 
passesFilters(self, itemId)
Checks if the given itemId passes the filters set for the container.
source code
 
addFilter(self, fltr)
Adds a container filter and re-filter the view.
source code
 
removeFilter(self, fltr)
Remove a specific container filter and re-filter the view (if necessary).
source code
 
removeAllFilters(self)
Remove all container filters for all properties and re-filter the view.
source code
 
isPropertyFiltered(self, propertyId)
Checks if there is a filter that applies to a given property.
source code
 
removeFilters(self, propertyId)
Remove all container filters for a given property identifier and re-filter the view.
source code
 
getItemSorter(self)
Returns the ItemSorter used for comparing items in a sort.
source code
 
setItemSorter(self, itemSorter)
Sets the ItemSorter used for comparing items in a sort.
source code
 
sortContainer(self, propertyId, ascending)
Sort base implementation to be used to implement ISortable.
source code
 
doSort(self)
Perform the sorting of the data structures in the container.
source code
 
getSortablePropertyIds(self)
Returns the sortable property identifiers for the container.
source code
 
internalRemoveAllItems(self)
Removes all items from the internal data structures of this class.
source code
 
internalRemoveItem(self, itemId)
Removes a single item from the internal data structures of this class.
source code
 
internalAddAt(self, position, itemId, item)
Adds the bean to all internal data structures at the given position.
source code
 
internalAddItemAtEnd(self, newItemId, item, fltr)
Add an item at the end of the container, and perform filtering if necessary.
source code
 
internalAddItemAfter(self, previousItemId, newItemId, item, fltr)
Add an item after a given (visible) item, and perform filtering.
source code
 
internalAddItemAt(self, index, newItemId, item, fltr)
Add an item at a given (visible after filtering) item index, and perform filtering.
source code
 
registerNewItem(self, position, itemId, item)
Registers a new item as having been added to the container.
source code
 
fireItemAdded(self, position, itemId, item)
Notify item set change listeners that an item has been added to the container.
source code
 
fireItemRemoved(self, position, itemId)
Notify item set change listeners that an item has been removed from the container.
source code
 
getVisibleItemIds(self)
Returns the internal list of visible item identifiers after filtering.
source code
 
isFiltered(self)
Returns true is the container has active filters.
source code
 
setFilteredItemIds(self, filteredItemIds)
Internal helper method to set the internal list of filtered item identifiers.
source code
 
getFilteredItemIds(self)
Internal helper method to get the internal list of filtered item identifiers.
source code
 
setAllItemIds(self, allItemIds)
Internal helper method to set the internal list of all item identifiers.
source code
 
getAllItemIds(self)
Internal helper method to get the internal list of all item identifiers.
source code
 
setFilters(self, filters)
Set the internal collection of filters without performing filtering.
source code
 
getFilters(self)
Returns the internal collection of filters.
source code

Inherited from abstract_container.AbstractContainer: fireContainerPropertySetChange, fireItemSetChange, getCallbacks, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, setItemSetChangeListeners, setPropertySetChangeListeners

Inherited from container.IContainer: getContainerProperty, getContainerPropertyIds, getType

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
  _allItemIds
An ordered List of all item identifiers in the container,
  _filteredItemIds
An ordered List of item identifiers in the container after
  _filters
Filters that are applied to the container to limit the items visible
  _itemSorter
The item sorter which is used for sorting the container.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

Constructor for an abstract in-memory container.

Overrides: object.__init__

getItem(self, itemId)

source code 

Gets the Item with the given Item ID from the IContainer. If the IContainer does not contain the requested Item, None is returned.

Containers should not return Items that are filtered out.

Parameters:
  • itemId - ID of the Item to retrieve
Returns:
the Item with the given ID or None if the Item is not found in the IContainer
Overrides: container.IContainer.getItem
(inherited documentation)

getUnfilteredItem(self, itemId)

source code 

Get an item even if filtered out.

For internal use only.

size(self)

source code 

Gets the number of visible Items in the IContainer.

Filtering can hide items so that they will not be visible through the container API.

Returns:
number of Items in the IContainer
Overrides: container.IContainer.size
(inherited documentation)

containsId(self, itemId)

source code 

Tests if the IContainer contains the specified Item.

Filtering can hide items so that they will not be visible through the container API, and this method should respect visibility of items (i.e. only indicate visible items as being in the container) if feasible for the container.

Parameters:
  • itemId - ID the of Item to be tested
Returns:
boolean indicating if the IContainer holds the specified Item
Overrides: container.IContainer.containsId
(inherited documentation)

getItemIds(self)

source code 

Gets the ID's of all visible (after filtering and sorting) Items stored in the IContainer. The ID's cannot be modified through the returned collection.

If the container is IOrdered, the collection returned by this method should follow that order. If the container is ISortable, the items should be in the sorted order.

Calling this method for large lazy containers can be an expensive operation and should be avoided when practical.

Returns:
unmodifiable collection of Item IDs
Overrides: container.IContainer.getItemIds
(inherited documentation)

nextItemId(self, itemId)

source code 

Gets the ID of the Item following the Item that corresponds to itemId. If the given Item is the last or not found in the IContainer, None is returned.

Parameters:
  • itemId - ID of a visible Item in the IContainer
Returns:
ID of the next visible Item or None
Overrides: container.IOrdered.nextItemId
(inherited documentation)

prevItemId(self, itemId)

source code 

Gets the ID of the Item preceding the Item that corresponds to itemId. If the given Item is the first or not found in the IContainer, None is returned.

Parameters:
  • itemId - ID of a visible Item in the IContainer
Returns:
ID of the previous visible Item or None
Overrides: container.IOrdered.prevItemId
(inherited documentation)

firstItemId(self)

source code 

Gets the ID of the first Item in the IContainer.

Returns:
ID of the first visible Item in the IContainer
Overrides: container.IOrdered.firstItemId
(inherited documentation)

lastItemId(self)

source code 

Gets the ID of the last Item in the IContainer..

Returns:
ID of the last visible Item in the IContainer
Overrides: container.IOrdered.lastItemId
(inherited documentation)

isFirstId(self, itemId)

source code 

Tests if the Item corresponding to the given Item ID is the first Item in the IContainer.

Parameters:
  • itemId - ID of an Item in the IContainer
Returns:
True if the Item is first visible item in the IContainer, False if not
Overrides: container.IOrdered.isFirstId
(inherited documentation)

isLastId(self, itemId)

source code 

Tests if the Item corresponding to the given Item ID is the last Item in the IContainer.

Returns:
True if the Item is last visible item in the IContainer, False if not
Overrides: container.IOrdered.isLastId
(inherited documentation)

getIdByIndex(self, index)

source code 

Gets the ID of an Item by an index number.

Parameters:
  • index - Index of the requested id in (the filtered and sorted view of) the IContainer
Returns:
ID of the Item in the given index
Overrides: container.IIndexed.getIdByIndex
(inherited documentation)

indexOfId(self, itemId)

source code 

Gets the index of the Item corresponding to the itemId. The following is True for the returned index: 0 <= index < size(), or index = -1 if there is no visible item with that id in the container.

Parameters:
  • itemId - ID of an Item in the IContainer
Returns:
index of the Item, or -1 if (the filtered and sorted view of) the IContainer does not include the Item
Overrides: container.IIndexed.indexOfId
(inherited documentation)

addItemAt(self, index, newItemId=None)

source code 

Adds a new item at given index (in the filtered view).

The indices of the item currently in the given position and all the following items are incremented.

This method should apply filters to the added item after inserting it, possibly hiding it immediately. If the container is being sorted, the item may be added at the correct sorted position instead of the given position. See IIndexed, IOrdered, IFilterable and ISortable for more information.

Parameters:
  • index - Index (in the filtered and sorted view) at which to add the new item.
  • newItemId - Id of the new item to be added.
Returns:
new Item or null if the operation fails.
Raises:
  • NotImplementedError - if the operation is not supported by the container
Overrides: container.IIndexed.addItemAt
(inherited documentation)

addItemAfter(self, previousItemId, newItemId=None)

source code 

Adds a new item after the given item.

Adding an item after null item adds the item as first item of the ordered container.

Parameters:
  • previousItemId - Id of the visible item in ordered container after which to insert the new item.
  • newItemId - Id of the new item to be added.
Returns:
new item or null if the operation fails.
Raises:
  • NotImplementedError - if the operation is not supported by the container
Overrides: container.IOrdered.addItemAfter
(inherited documentation)

addItem(self, itemId=None)

source code 

Creates a new Item with the given ID in the IContainer. Creates a new Item into the IContainer, and assign it an automatic ID if itemId is None.

The new Item is returned, and it is ready to have its Properties modified. Returns None if the operation fails or the IContainer already contains a Item with the given ID.

Parameters:
  • itemId - ID of the Item to be created
Returns:
Created new Item, or None in case of a failure
Raises:
  • NotImplementedError - if adding an item with an explicit item ID is not supported by the container
Overrides: container.IContainer.addItem
(inherited documentation)

removeItem(self, itemId)

source code 

Removes the Item identified by ItemId from the IContainer.

Containers that support filtering should also allow removing an item that is currently filtered out.

This functionality is optional.

Parameters:
  • itemId - ID of the Item to remove
Returns:
True if the operation succeeded, False if not
Raises:
  • NotImplementedError - if the container does not support removing individual items
Overrides: container.IContainer.removeItem
(inherited documentation)

removeAllItems(self)

source code 

Removes all Items from the IContainer.

Note that Property ID and type information is preserved. This functionality is optional.

Returns:
True if the operation succeeded, False if not
Raises:
  • NotImplementedError - if the container does not support removing all items
Overrides: container.IContainer.removeAllItems
(inherited documentation)

addContainerProperty(self, propertyId, typ, defaultValue)

source code 

Adds a new Property to all Items in the IContainer. The Property ID, data type and default value of the new Property are given as parameters.

This functionality is optional.

Parameters:
  • propertyId - ID of the Property
  • typ - Data type of the new Property
  • defaultValue - The value all created Properties are initialized to
Returns:
True if the operation succeeded, False if not
Raises:
  • NotImplementedError - if the container does not support explicitly adding container properties
Overrides: container.IContainer.addContainerProperty
(inherited documentation)

removeContainerProperty(self, propertyId)

source code 

Removes a Property specified by the given Property ID from the IContainer. Note that the Property will be removed from all Items in the IContainer.

This functionality is optional.

Parameters:
  • propertyId - ID of the Property to remove
Returns:
True if the operation succeeded, False if not
Raises:
  • NotImplementedError - if the container does not support removing container properties
Overrides: container.IContainer.removeContainerProperty
(inherited documentation)

addListener(self, listener, iface=None)

source code 

Implementation of the corresponding method in IPropertySetChangeNotifier and ItemSetChangeNotifier, override and implement the interface to use this.

Parameters:
  • listener - listener to be added
Overrides: container.IItemSetChangeNotifier.addListener
(inherited documentation)

addCallback(self, callback, eventType=None, *args)

source code 
Overrides: container.IItemSetChangeNotifier.addCallback

removeListener(self, listener, iface=None)

source code 

Implementation of the corresponding method in IPropertySetChangeNotifier and ItemSetChangeNotifier, override and implement the interface to use this.

Parameters:
  • listener - listener to be removed
Overrides: container.IItemSetChangeNotifier.removeListener
(inherited documentation)

removeCallback(self, callback, eventType=None)

source code 
Overrides: container.IItemSetChangeNotifier.removeCallback

doFilterContainer(self, hasFilters)

source code 

Filters the data in the container and updates internal data structures. This method should reset any internal data structures and then repopulate them so getItemIds and other methods only return the filtered items.

Parameters:
  • hasFilters - true if filters has been set for the container, false otherwise
Returns:
true if the item set has changed as a result of the filtering

passesFilters(self, itemId)

source code 

Checks if the given itemId passes the filters set for the container. The caller should make sure the itemId exists in the container. For non-existing itemIds the behaviour is undefined.

Parameters:
  • itemId - An itemId that exists in the container.
Returns:
true if the itemId passes all filters or no filters are set, false otherwise.

addFilter(self, fltr)

source code 

Adds a container filter and re-filter the view.

The filter must implement Filter and its sub-filters (if any) must also be in-memory filterable.

This can be used to implement Filterable.addContainerFilter and optionally also SimpleFilterable.addContainerFilter (with SimpleStringFilter).

Note that in some cases, incompatible filters cannot be detected when added and an UnsupportedFilterException may occur when performing filtering.

Raises:

removeFilter(self, fltr)

source code 

Remove a specific container filter and re-filter the view (if necessary).

This can be used to implement Filterable.removeContainerFilter.

removeAllFilters(self)

source code 

Remove all container filters for all properties and re-filter the view.

This can be used to implement Filterable.removeAllContainerFilters.

isPropertyFiltered(self, propertyId)

source code 

Checks if there is a filter that applies to a given property.

Returns:
true if there is an active filter for the property

removeFilters(self, propertyId)

source code 

Remove all container filters for a given property identifier and re-filter the view. This also removes filters applying to multiple properties including the one identified by propertyId.

This can be used to implement Filterable.removeContainerFilters.

Returns:
Collection<Filter> removed filters

getItemSorter(self)

source code 

Returns the ItemSorter used for comparing items in a sort. See setItemSorter for more information.

Returns:
The ItemSorter used for comparing two items in a sort.

setItemSorter(self, itemSorter)

source code 

Sets the ItemSorter used for comparing items in a sort. The ItemSorter.compare method is called with item ids to perform the sorting. A default ItemSorter is used if this is not explicitly set.

Parameters:
  • itemSorter - The ItemSorter used for comparing two items in a sort (not null).

sortContainer(self, propertyId, ascending)

source code 

Sort base implementation to be used to implement ISortable.

Subclasses should call this from a public sort method when implementing ISortable.

See Also: ISortable.sort

doSort(self)

source code 

Perform the sorting of the data structures in the container. This is invoked when the itemSorter has been prepared for the sort operation. Typically this method calls sorted on all arrays (containing item ids) that need to be sorted.

getSortablePropertyIds(self)

source code 

Returns the sortable property identifiers for the container. Can be used to implement ISortable.getSortableContainerPropertyIds.

internalRemoveAllItems(self)

source code 

Removes all items from the internal data structures of this class. This can be used to implement removeAllItems in subclasses.

No notification is sent, the caller has to fire a suitable item set change notification.

internalRemoveItem(self, itemId)

source code 

Removes a single item from the internal data structures of this class. This can be used to implement removeItem in subclasses.

No notification is sent, the caller has to fire a suitable item set change notification.

Parameters:
  • itemId - the identifier of the item to remove
Returns:
true if an item was successfully removed, false if failed to remove or no such item

internalAddAt(self, position, itemId, item)

source code 

Adds the bean to all internal data structures at the given position. Fails if an item with itemId is already in the container. Returns a the item if it was added successfully, null otherwise.

Caller should initiate filtering after calling this method.

For internal use only - subclasses should use internalAddItemAtEnd, internalAddItemAt and internalAddItemAfter instead.

Parameters:
  • position - The position at which the item should be inserted in the unfiltered collection of items
  • itemId - The item identifier for the item to insert
  • item - The item to insert
Returns:
ITEMCLASS if the item was added successfully, null otherwise

internalAddItemAtEnd(self, newItemId, item, fltr)

source code 

Add an item at the end of the container, and perform filtering if necessary. An event is fired if the filtered view changes.

Parameters:
  • newItemId
  • item - new item to add
  • fltr - true to perform filtering and send event after adding the item, false to skip these operations for batch inserts - if false, caller needs to make sure these operations are performed at the end of the batch
Returns:
item added or null if no item was added

internalAddItemAfter(self, previousItemId, newItemId, item, fltr)

source code 

Add an item after a given (visible) item, and perform filtering. An event is fired if the filtered view changes.

The new item is added at the beginning if previousItemId is null.

Parameters:
  • previousItemId - item id of a visible item after which to add the new item, or null to add at the beginning
  • newItemId
  • item - new item to add
  • fltr - true to perform filtering and send event after adding the item, false to skip these operations for batch inserts - if false, caller needs to make sure these operations are performed at the end of the batch
Returns:
item added or null if no item was added

internalAddItemAt(self, index, newItemId, item, fltr)

source code 

Add an item at a given (visible after filtering) item index, and perform filtering. An event is fired if the filtered view changes.

Parameters:
  • index - position where to add the item (visible/view index)
  • newItemId
  • item - new item to add
  • fltr - true to perform filtering and send event after adding the item, false to skip these operations for batch inserts - if false, caller needs to make sure these operations are performed at the end of the batch
Returns:
item added or null if no item was added

registerNewItem(self, position, itemId, item)

source code 

Registers a new item as having been added to the container. This can involve storing the item or any relevant information about it in internal container-specific collections if necessary, as well as registering listeners etc.

The full identifier list in AbstractInMemoryContainer has already been updated to reflect the new item when this method is called.

fireItemAdded(self, position, itemId, item)

source code 

Notify item set change listeners that an item has been added to the container.

Unless subclasses specify otherwise, the default notification indicates a full refresh.

Parameters:
  • position - position of the added item in the view (if visible)
  • itemId - id of the added item
  • item - the added item

fireItemRemoved(self, position, itemId)

source code 

Notify item set change listeners that an item has been removed from the container.

Unless subclasses specify otherwise, the default notification indicates a full refresh.

Parameters:
  • position - position of the removed item in the view prior to removal (if was visible)
  • itemId - id of the removed item, of type object to satisfy IContainer.removeItem API

getVisibleItemIds(self)

source code 

Returns the internal list of visible item identifiers after filtering.

For internal use only.

isFiltered(self)

source code 

Returns true is the container has active filters.

Returns:
true if the container is currently filtered

setFilteredItemIds(self, filteredItemIds)

source code 

Internal helper method to set the internal list of filtered item identifiers. Should not be used outside this class except for implementing clone(), may disappear from future versions.

getFilteredItemIds(self)

source code 

Internal helper method to get the internal list of filtered item identifiers. Should not be used outside this class except for implementing clone(), may disappear from future versions - use getVisibleItemIds in other contexts.

Returns:
List<ITEMIDTYPE>

setAllItemIds(self, allItemIds)

source code 

Internal helper method to set the internal list of all item identifiers. Should not be used outside this class except for implementing clone(), may disappear from future versions.

getAllItemIds(self)

source code 

Internal helper method to get the internal list of all item identifiers. Avoid using this method outside this class, may disappear in future versions.

Returns:
List<ITEMIDTYPE>

setFilters(self, filters)

source code 

Set the internal collection of filters without performing filtering.

This method is mostly for internal use, use addFilter and remove*Filter* (which also re-filter the container) instead when possible.

getFilters(self)

source code 

Returns the internal collection of filters. The returned collection should not be modified by callers outside this class.

Returns:
Set<Filter>