org.millstone.base.data.util
Class IndexedContainer

java.lang.Object
  |
  +--org.millstone.base.data.util.IndexedContainer
All Implemented Interfaces:
Container, Container.Indexed, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeNotifier, Property.ValueChangeNotifier
Direct Known Subclasses:
HierarchicalContainer

public class IndexedContainer
extends java.lang.Object
implements Container, Container.Indexed, Container.ItemSetChangeNotifier, Container.PropertySetChangeNotifier, Property.ValueChangeNotifier

A list implementation of the org.millstone.base.data.Container interface. A list is a ordered collection wherein the user has a precise control over where in the list each new Item is inserted. The user may access the Items by their integer index (position in the list) or by their Item ID.

Since:
3.0
Version:
3.0.3
Author:
IT Mill Ltd.
See Also:
Container

Nested Class Summary
 
Nested classes inherited from class org.millstone.base.data.Container
Container.Editor, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.Viewer
 
Field Summary
 
Fields inherited from interface org.millstone.base.data.Container
NULL_ITEM_ID
 
Constructor Summary
IndexedContainer()
           
 
Method Summary
 boolean addContainerProperty(java.lang.Object propertyId, java.lang.Class type, java.lang.Object defaultValue)
          Add a new Property to all Items in the list.
 java.lang.Object addItem()
          Create a new Item into the list, and assign it an automatic ID.
 Item addItem(java.lang.Object itemId)
          Create a new Item with the given ID into the list.
 java.lang.Object addItemAfter(java.lang.Object previousItemId)
          Add new item after the given item.
 Item addItemAfter(java.lang.Object previousItemId, java.lang.Object newItemId)
          Add new item after the given item.
 java.lang.Object addItemAt(int index)
          Add new item at given index.
 Item addItemAt(int index, java.lang.Object newItemId)
          Add new item at given index.
 void addListener(Container.ItemSetChangeListener listener)
          Adds a Item set change listener for the list.
 void addListener(Container.PropertySetChangeListener listener)
          Registers a new Property set change listener for this list.
 void addListener(Property.ValueChangeListener listener)
          Registers a new value change listener for this object.
 boolean containsId(java.lang.Object itemId)
          Tests if the list contains the specified Item
 java.lang.Object firstItemId()
          Gets the ID of the first Item in the list.
 Property getContainerProperty(java.lang.Object itemId, java.lang.Object propertyId)
          Gets the Property identified by the given Item ID and Property ID from the lsit.
 java.util.Collection getContainerPropertyIds()
          Gets the ID's of all Properties stored in the list.
 java.lang.Object getIdByIndex(int index)
          Get ID with the index.
 Item getItem(java.lang.Object itemId)
          Gets the Item with the given Item ID from the list.
 java.util.Collection getItemIds()
          Gets the ID's of all Items stored in the list.
 java.lang.Class getType(java.lang.Object propertyId)
          Gets the type of a Property stored in the list.
 int indexOfId(java.lang.Object itemId)
          Get the index of an id.
 boolean isFirstId(java.lang.Object itemId)
          Tests if the Item corresponding to the given Item ID is the first Item in the list.
 boolean isLastId(java.lang.Object itemId)
          Tests if the Item corresponding to the given Item ID is the last Item in the list.
 java.lang.Object lastItemId()
          Gets the ID of the last Item in the list.
 java.lang.Object nextItemId(java.lang.Object itemId)
          Gets the ID of the Item following the Item that corresponds to itemId.
 java.lang.Object prevItemId(java.lang.Object itemId)
          Gets the ID of the Item preceding the Item that corresponds to itemId.
 boolean removeAllItems()
          Remove all Items from the list.
 boolean removeContainerProperty(java.lang.Object propertyId)
          Remove a Property specified by the given Property ID from the list.
 boolean removeItem(java.lang.Object itemId)
          Remove the Item corresponding to the given Item ID from the list.
 void removeListener(Container.ItemSetChangeListener listener)
          Removes a Item set change listener from the object.
 void removeListener(Container.PropertySetChangeListener listener)
          Removes a previously registered Property set change listener.
 void removeListener(Property.ValueChangeListener listener)
          Removes a previously registered value change listener.
 int size()
          Gets the number of Items in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexedContainer

public IndexedContainer()
Method Detail

getItem

public Item getItem(java.lang.Object itemId)
Gets the Item with the given Item ID from the list. If the list does not contain the requested Item, null is returned.

Specified by:
getItem in interface Container
Parameters:
itemId - ID of the Item to retrieve
Returns:
the Item with the given ID or null if the Item is not found in the list

getItemIds

public java.util.Collection getItemIds()
Gets the ID's of all Items stored in the list. The ID's are returned as a unmodifiable collection.

Specified by:
getItemIds in interface Container
Returns:
unmodifiable collection of Item IDs

getContainerPropertyIds

public java.util.Collection getContainerPropertyIds()
Gets the ID's of all Properties stored in the list. The ID's are returned as a unmodifiable collection.

Specified by:
getContainerPropertyIds in interface Container
Returns:
unmodifiable collection of Property IDs

getType

public java.lang.Class getType(java.lang.Object propertyId)
Gets the type of a Property stored in the list.

Specified by:
getType in interface Container
Parameters:
propertyId - ID identifying the Properties
Returns:
Type of the requested Property

getContainerProperty

public Property getContainerProperty(java.lang.Object itemId,
                                     java.lang.Object propertyId)
Gets the Property identified by the given Item ID and Property ID from the lsit. If the list does not contain the Property, null is returned.

Specified by:
getContainerProperty in interface Container
Parameters:
itemId - ID of the Item which contains the requested Property
propertyId - ID of the Property to retrieve
Returns:
Property with the given ID or null
See Also:
Container.getContainerProperty(Object, Object)

size

public int size()
Gets the number of Items in the list.

Specified by:
size in interface Container
Returns:
number of Items in the list

containsId

public boolean containsId(java.lang.Object itemId)
Tests if the list contains the specified Item

Specified by:
containsId in interface Container
Parameters:
itemId - ID the of Item to be tested for
Returns:
true if the operation succeeded, false if not

addContainerProperty

public boolean addContainerProperty(java.lang.Object propertyId,
                                    java.lang.Class type,
                                    java.lang.Object defaultValue)
Add a new Property to all Items in the list. The Property ID, data type and default value of the new Property are given as parameters.

Specified by:
addContainerProperty in interface Container
Parameters:
propertyId - ID of the new Property
type - Data type of the new Property
defaultValue - The value all created Properties are initialized to
Returns:
true if the operation succeeded, false if not

removeAllItems

public boolean removeAllItems()
Remove all Items from the list. Note that Property ID and type information is preserved.

Specified by:
removeAllItems in interface Container
Returns:
true if the operation succeeded, false if not

addItem

public java.lang.Object addItem()
Create a new Item into the list, and assign it an automatic ID. The new ID is returned, or null if the operation fails. After a successful call you can use the getItem method to fetch the Item.

Specified by:
addItem in interface Container
Returns:
ID of the newly created Item, or null in case of a failure

addItem

public Item addItem(java.lang.Object itemId)
Create a new Item with the given ID into the list. The new Item is returned, and it is ready to have its Properties modified. Returns null if the operation fails or the Container already contains a Item with the given ID.

Specified by:
addItem in interface Container
Parameters:
itemId - ID of the Item to be created
Returns:
Created new Item, or null in case of a failure

removeItem

public boolean removeItem(java.lang.Object itemId)
Remove the Item corresponding to the given Item ID from the list.

Specified by:
removeItem in interface Container
Parameters:
itemId - ID of the Item to remove
Returns:
true if the operation succeeded, false if not

removeContainerProperty

public boolean removeContainerProperty(java.lang.Object propertyId)
Remove a Property specified by the given Property ID from the list. Note that the Property will be removed from all Items in the list.

Specified by:
removeContainerProperty in interface Container
Parameters:
propertyId - ID of the Property to remove
Returns:
true if the operation succeeded, false if not

firstItemId

public java.lang.Object firstItemId()
Gets the ID of the first Item in the list.

Specified by:
firstItemId in interface Container.Ordered
Returns:
ID of the first Item in the list

lastItemId

public java.lang.Object lastItemId()
Gets the ID of the last Item in the list.

Specified by:
lastItemId in interface Container.Ordered
Returns:
ID of the last Item in the list

nextItemId

public java.lang.Object nextItemId(java.lang.Object itemId)
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 list, null is returned.

Specified by:
nextItemId in interface Container.Ordered
Parameters:
itemId - ID of an Item in the list
Returns:
ID of the next Item or null

prevItemId

public java.lang.Object prevItemId(java.lang.Object itemId)
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 list, null is returned.

Specified by:
prevItemId in interface Container.Ordered
Parameters:
itemId - ID of an Item in the list
Returns:
ID of the previous Item or null

isFirstId

public boolean isFirstId(java.lang.Object itemId)
Tests if the Item corresponding to the given Item ID is the first Item in the list.

Specified by:
isFirstId in interface Container.Ordered
Parameters:
itemId - ID of an Item in the list
Returns:
true if the Item is first in the list, false if not

isLastId

public boolean isLastId(java.lang.Object itemId)
Tests if the Item corresponding to the given Item ID is the last Item in the list.

Specified by:
isLastId in interface Container.Ordered
Parameters:
itemId - ID of an Item in the list
Returns:
true if the Item is last in the list, false if not

addItemAfter

public Item addItemAfter(java.lang.Object previousItemId,
                         java.lang.Object newItemId)
Description copied from interface: Container.Ordered
Add new item after the given item.

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

Specified by:
addItemAfter in interface Container.Ordered
Parameters:
previousItemId - Id of the previous item in ordered container.
newItemId - Id of the new item to be added.
Returns:
Returns new item or null if the operation fails.
See Also:
Container.Ordered.addItemAfter(Object, Object)

addItemAfter

public java.lang.Object addItemAfter(java.lang.Object previousItemId)
Description copied from interface: Container.Ordered
Add new item after the given item.

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

Specified by:
addItemAfter in interface Container.Ordered
Parameters:
previousItemId - Id of the previous item in ordered container.
Returns:
Returns item id the the created new item or null if the operation fails.
See Also:
Container.Ordered.addItemAfter(Object)

getIdByIndex

public java.lang.Object getIdByIndex(int index)
Get ID with the index. The following is true for the index: 0 <= index < size().

Specified by:
getIdByIndex in interface Container.Indexed
Parameters:
index - Index of the requested ID in the container.
Returns:
ID in the given index.

indexOfId

public int indexOfId(java.lang.Object itemId)
Get the index of an id. The following is true for the index: 0 <= index < size().

Specified by:
indexOfId in interface Container.Indexed
Parameters:
itemId - ID of an Item in the collection
Returns:
Index of the Item or -1 if the Item is not in the container.

addItemAt

public Item addItemAt(int index,
                      java.lang.Object newItemId)
Description copied from interface: Container.Indexed
Add new item at given index.

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

Specified by:
addItemAt in interface Container.Indexed
Parameters:
index - Index to add the new item.
newItemId - Id of the new item to be added.
Returns:
Returns new item or null if the operation fails.
See Also:
Container.Indexed.addItemAt(int, Object)

addItemAt

public java.lang.Object addItemAt(int index)
Description copied from interface: Container.Indexed
Add new item at given index.

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

Specified by:
addItemAt in interface Container.Indexed
Parameters:
index - Index to add the new item.
Returns:
Returns item id the the created new item or null if the operation fails.
See Also:
Container.Indexed.addItemAt(int)

addListener

public void addListener(Container.PropertySetChangeListener listener)
Registers a new Property set change listener for this list.

Specified by:
addListener in interface Container.PropertySetChangeNotifier
Parameters:
listener - the new Listener to be registered

removeListener

public void removeListener(Container.PropertySetChangeListener listener)
Removes a previously registered Property set change listener.

Specified by:
removeListener in interface Container.PropertySetChangeNotifier
Parameters:
listener - listener to be removed

addListener

public void addListener(Container.ItemSetChangeListener listener)
Adds a Item set change listener for the list.

Specified by:
addListener in interface Container.ItemSetChangeNotifier
Parameters:
listener - listener to be added

removeListener

public void removeListener(Container.ItemSetChangeListener listener)
Removes a Item set change listener from the object.

Specified by:
removeListener in interface Container.ItemSetChangeNotifier
Parameters:
listener - listener to be removed

addListener

public void addListener(Property.ValueChangeListener listener)
Registers a new value change listener for this object.

Specified by:
addListener in interface Property.ValueChangeNotifier
Parameters:
listener - the new Listener to be registered

removeListener

public void removeListener(Property.ValueChangeListener listener)
Removes a previously registered value change listener.

Specified by:
removeListener in interface Property.ValueChangeNotifier
Parameters:
listener - listener to be removed


Copyright © 2000,2001,2002 IT Mill Ltd. All Rights Reserved.