au.com.zip.cs
Class AbstractEntityTable

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractList
          extended by au.com.zip.cs.AbstractEntityTable
All Implemented Interfaces:
EntityTable, Iterable, Collection, List, TreeNode
Direct Known Subclasses:
WrappedEntityTable

public abstract class AbstractEntityTable
extends AbstractList
implements EntityTable

A base class with utility routines (so they can be extended).

Author:
Cameron Simpson <cs@zip.com.au> 18jul2003

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
AbstractEntityTable()
           
 
Method Summary
 Entity byIndex(int index)
          Return the nth Entity in the table.
 Enumeration children()
           
 Object get(int ndx)
          Implementation of List.get(int) that calls EntityTable.byIndex(int).
 boolean getAllowsChildren()
           
 int getAttributeIndex(String name)
          Return the index of the supplied attribute name.
static List getBetween(EntityTable t, long start, long end)
          Static version of EntityTable.getBetween(long,long) to aid @{link EntityTable} implementors.
 List getBetween(long start, long end)
          Return an List where each Entity's start and end overlap the period specified.
 TreeNode getChildAt(int childIndex)
           
 int getChildCount()
           
static int getIDIndex(Iterator iter, long id)
          Return the index if the supplied id is in an ID Iterator.
 IDMap getIDMap()
           
 int getIndex(Entity e)
          Return the index of this Entity within the table.
 int getIndex(TreeNode node)
           
 TreeNode getParent()
           
static long idByIndex(EntityTable t, int index)
          Return the id whose index is specified.
 boolean isLeaf()
           
 void preload()
          Preload the table in one go.
 int size()
          Returns the number of elements in this list.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface au.com.zip.cs.EntityTable
byAttribute, byID, byShortName, getAttributeNames, getIDAttributeName, getIDIterator, getTableSize, iterator, setIDAttributeName
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

AbstractEntityTable

public AbstractEntityTable()
Method Detail

getIndex

public int getIndex(Entity e)
Description copied from interface: EntityTable
Return the index of this Entity within the table.

Specified by:
getIndex in interface EntityTable
Parameters:
e - the Entity to locate
Returns:
the index, or -1 if the Entity is not in this table

getIDIndex

public static final int getIDIndex(Iterator iter,
                                   long id)
Return the index if the supplied id is in an ID Iterator. The Iterator returns Numbers as with EntityTable.getIDIterator().

Parameters:
iter - the Iterator
id - the id sought
Returns:
the index, or -1 if not found

idByIndex

public static long idByIndex(EntityTable t,
                             int index)
Return the id whose index is specified.

Parameters:
index - the index of the id
Returns:
the id, or -1 if the index does not map to an Entity

getIDMap

public IDMap getIDMap()

byIndex

public Entity byIndex(int index)
Description copied from interface: EntityTable
Return the nth Entity in the table. For tables which are mappings of other data structures this may be an expensive operation.

Specified by:
byIndex in interface EntityTable
Parameters:
index - the index of the Entity to obtain, counting from 0
Returns:
the Entity or null if the index is unmapped

preload

public void preload()
Description copied from interface: EntityTable
Preload the table in one go. For database tables this should be much faster than the "record at a time" loading done by the normal "at need" fetches, and thus may be a win when you know you'll be accessing most of the table anyway. Of course a big table might not fit into memory.

Specified by:
preload in interface EntityTable

getBetween

public List getBetween(long start,
                       long end)
Description copied from interface: EntityTable
Return an List where each Entity's start and end overlap the period specified.

Specified by:
getBetween in interface EntityTable
Parameters:
start - the start of the specified period
end - the end of the specified period
Returns:
the matching entities

getBetween

public static List getBetween(EntityTable t,
                              long start,
                              long end)
Static version of EntityTable.getBetween(long,long) to aid @{link EntityTable} implementors.

Parameters:
t - the EntityTable to peruse
start - the start date
end - the end date
Returns:
the matching entities

getAttributeIndex

public int getAttributeIndex(String name)
Description copied from interface: EntityTable
Return the index of the supplied attribute name. Note that for EntityTables which do not have rigid column definitions this need not return consistent values.

Specified by:
getAttributeIndex in interface EntityTable
Parameters:
name - the attribute
Returns:
the index, counting from 0; -1 if the name is unknown

get

public Object get(int ndx)
Implementation of List.get(int) that calls EntityTable.byIndex(int).

Specified by:
get in interface List
Specified by:
get in class AbstractList
Parameters:
ndx - the Entity to get
Returns:
the Entity

size

public int size()
Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface Collection
Specified by:
size in interface List
Specified by:
size in class AbstractCollection
Returns:
the number of elements in this list

children

public Enumeration children()
Specified by:
children in interface TreeNode

getAllowsChildren

public boolean getAllowsChildren()
Specified by:
getAllowsChildren in interface TreeNode

getChildAt

public TreeNode getChildAt(int childIndex)
Specified by:
getChildAt in interface TreeNode

getChildCount

public int getChildCount()
Specified by:
getChildCount in interface TreeNode

getIndex

public int getIndex(TreeNode node)
Specified by:
getIndex in interface TreeNode

getParent

public TreeNode getParent()
Specified by:
getParent in interface TreeNode

isLeaf

public boolean isLeaf()
Specified by:
isLeaf in interface TreeNode