livespace.services
Class EntityList

java.lang.Object
  extended by dsto.dfc.databeans.AbstractDataObject
      extended by dsto.dfc.databeans.SimpleDataObject
          extended by dsto.dfc.databeans.FancyDataObject
              extended by livespace.services.EntityList
All Implemented Interfaces:
IDataObject, IDataObjectChildListener, Cloneable
Direct Known Subclasses:
EntityQueue, EntityStack

public class EntityList
extends FancyDataObject

An ordered list of entities. This list allows duplicate entities to be added to the list.

This uses an EntityRegistry to store the entities and includes an 'index' attribute with each entity to order the actual contained entities.

Rolling indexes are used internally for maintaining the order of entities within the list to reduce the property change events that occur when manipulating the list. This means adding to the end of the list, or removing from either ends of the list, only results in one property change event for the list. Adding or removing in the middle of the list will trigger multiple property change events as the indexes of the entities in the list above the modified index will need to be modified also.

Author:
Steven Johnson Created on 2/06/2006

Nested Class Summary
 class EntityList.ListEntity
          Wraps an Entity and adds an index attribute to maintain the index of an entity within an EntityList.
 
Field Summary
 int endIndex
           
 EntityRegistry entities
           
 int startIndex
           
 
Fields inherited from class dsto.dfc.databeans.AbstractDataObject
listeners
 
Fields inherited from interface dsto.dfc.databeans.IDataObject
OVERRIDE, PERSISTENT, PERSISTENT_OVERRIDE, TRANSIENT, TRANSIENT_OVERRIDE
 
Constructor Summary
EntityList()
           
 
Method Summary
 void add(Entity e)
          Adds the specified entity to the end of the list.
 void add(int index, Entity e)
          Inserts the specified entity at the specified position in the list.
 void clear()
           
 Entity get(int index)
          Returns the entity at the specified position in this list.
 boolean isEmpty()
          Returns true if this list contains no entities.
 Iterator<Entity> iterator()
          Returns an iterator of EntityList.ListEntity's contained within this list.
 boolean remove(Entity e)
          Removes the first occurrence in this list of the specified entity.
 Entity remove(int index)
          Removes the entity at the specified position in the list.
 Entity remove(String id)
          Removes the first occurrence in this list of an entity with the specified id.
 int size()
          Returns the number of entities in the list.
 List<Entity> snapshot()
          Returns a snapshot of the EntityList.ListEntity's within this list.
 
Methods inherited from class dsto.dfc.databeans.FancyDataObject
childPropertyChanged, getValue, isTransient, propertyIterator, setValue, shallowClone
 
Methods inherited from class dsto.dfc.databeans.SimpleDataObject
getFieldNames, getTypeInfo, setValue
 
Methods inherited from class dsto.dfc.databeans.AbstractDataObject
addFirstPropertyListener, addPropertyListener, firePropertyChangedEvent, firePropertyChangedEvent, firePropertyChangedEvent, firePropertyChangedEvent, firePropertyChangedEvent, firePropertyChangedEvent, getBeanValue, getBooleanValue, getBooleanValue, getCharValue, getCharValue, getDoubleValue, getDoubleValue, getFloatValue, getFloatValue, getIntValue, getIntValue, getLongValue, getLongValue, getObjectValue, getPropertyListeners, getShortValue, getStringValue, registerValue, removePropertyListener, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, toString, unregisterValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

entities

public EntityRegistry entities

startIndex

public int startIndex

endIndex

public int endIndex
Constructor Detail

EntityList

public EntityList()
Method Detail

isEmpty

public boolean isEmpty()
Returns true if this list contains no entities.

Returns:
true of this list contains no entities

size

public int size()
Returns the number of entities in the list.

Returns:
the number of entities in the list.

add

public void add(Entity e)
Adds the specified entity to the end of the list.

Parameters:
e - the Entity to add to the end of the list.

add

public void add(int index,
                Entity e)
         throws IndexOutOfBoundsException
Inserts the specified entity at the specified position in the list.

Parameters:
index - index at which the specified entity is to be inserted
e - the entity to be inserted
Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size())

remove

public Entity remove(int index)
              throws IllegalStateException,
                     IndexOutOfBoundsException
Removes the entity at the specified position in the list.

Parameters:
index - the index of the entity to be removed
Returns:
the entity previously at the specified position
Throws:
IllegalStateException - if there was no entity found at the specified position
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())

remove

public boolean remove(Entity e)
Removes the first occurrence in this list of the specified entity. If this list does not contain the entity then the list will be unchanged and false will be returned, otherwise true will be returned.

Parameters:
e - the entity to remove
Returns:
true if this list contained the entity and the entity was removed, false otherwise

remove

public Entity remove(String id)
Removes the first occurrence in this list of an entity with the specified id. If this list does not contain an entity with the specified id then the list will be unchanged and null will be returned, otherwise the entity will be returned.

Parameters:
id - the id of the entity to remove
Returns:
the removed entity if this list contained an entity with the id and the entity was removed, null otherwise

get

public Entity get(int index)
Returns the entity at the specified position in this list.

Parameters:
index - the index of the entity to return
Returns:
the entity at the specified position in the list

iterator

public Iterator<Entity> iterator()
Returns an iterator of EntityList.ListEntity's contained within this list. This will be from a snapshot of the list so changes to the underlying list will not be reflected in this iterator once it is created.


clear

public void clear()

snapshot

public List<Entity> snapshot()
Returns a snapshot of the EntityList.ListEntity's within this list.



Copyright © 2008 Commonwealth of Australia