au.com.zip.cs
Class EntityAdaptor

java.lang.Object
  extended by au.com.zip.cs.CachableAdaptor
      extended by au.com.zip.cs.AsyncObject
          extended by au.com.zip.cs.EntityAdaptor
All Implemented Interfaces:
Cachable, Dated, Entity, HasID, Comparable, TreeNode
Direct Known Subclasses:
Group, WrappedEntity

public class EntityAdaptor
extends AsyncObject
implements Entity, Dated

A basic implementation of Entity.

Author:
Cameron Simpson <cs@zip.com.au> 22jun2003

Field Summary
static String DEFAULT_LONGNAME_ATTRIBUTENAME
          The default attribute name for an Entity's long name: NAME_LONG.
static String DEFAULT_SHORTNAME_ATTRIBUTENAME
          The default attribute name for an Entity's short name: NAME_SHORT.
 
Fields inherited from class au.com.zip.cs.AsyncObject
CLEAN, DELETED, MODIFIED, NEW
 
Fields inherited from interface au.com.zip.cs.Entity
DEFAULT_ID_ATTRIBUTENAME, ID_NULL
 
Fields inherited from interface au.com.zip.cs.Dated
DATE_NOW, DATE_NULL, DFLT_END_DATE_ATTRIBUTE, DFLT_START_DATE_ATTRIBUTE
 
Method Summary
 Enumeration children()
           
 void commit()
          Apply any pending changes to the persistent store.
static int compareIDTo(long id, Object o)
          Static access to the Comparable compareTo(Object) method.
 int compareTo(Object o)
           
static boolean currentAt(Entity e, long when)
           
 boolean currentAt(long when)
           
static long datedToLong(Object dated)
          Convert a dated Object to a long time.
 boolean getAllowsChildren()
           
 Object getAttribute(String name)
          Return the named attribute value from this entity.
 Map getAttributes()
          Return the attributes and values of this Entity.
 TreeNode getChildAt(int childIndex)
           
 int getChildCount()
           
 long getDatedAttribute(String name)
          Return the milliseconds value corresponding to the named attribute value from this entity.
 long getEndDate()
          Return the end date of this Entity from its Dated.DFLT_START_DATE_ATTRIBUTE attribute.
static long getEndDate(Entity e)
          Return the end date of an Entity obtained from its Dated.DFLT_START_DATE_ATTRIBUTE attribute.
 EntityTable getEntityTable()
          Return this entity's enclosing EntityTable.
 long getID()
          Return the unique numeric identifier of this Entity.
 int getIndex()
          Return the index of this Entity in the enclosing EntityTable.
 int getIndex(TreeNode node)
           
 String getLongName()
          Return the long (descriptive) name for this entity.
 long getNumericAttribute(String name)
          Return the numeric value of the named attribute value from this entity, which must be a Number.
 TreeNode getParent()
           
 String getShortName()
          Return the short name for this entity.
 long getStartDate()
          Return the start date of this Entity from the Dated.DFLT_START_DATE_ATTRIBUTE attribute.
static long getStartDate(Entity e)
          Return the start date of an Entity from its Dated.DFLT_START_DATE_ATTRIBUTE attribute.
static boolean isBetween(long when, long start, long end)
           
 boolean isLeaf()
           
 long longValue()
           
static long now()
          Return the current date in milliseconds since midnight, January 1, 1970 UTC.
static boolean overlaps(Entity e, long start, long end)
          Check that the start and end dates for the supplied Entity overlay the date range specified by the start and end parameters.
static boolean overlaps(long start1, long end1, long start2, long end2)
          Check that the start and end dates for the supplied ranges overlap.
 void setAttribute(String name, Object value)
          Set the named attribute value from this entity.
static void setEndDate(Entity e, long when)
          Set the end date of an Entity stored in its Dated.DFLT_START_DATE_ATTRIBUTE attribute.
 void setEndDate(long when)
          Set the end date of this Entity stored in its Dated.DFLT_START_DATE_ATTRIBUTE attribute.
 void setLongName(String name)
          Set the Entity's long name.
 void setShortName(String name)
          Set the Entity's short name.
static void setStartDate(Entity e, long when)
          Set the start date of an Entity stored in its Dated.DFLT_START_DATE_ATTRIBUTE attribute.
 void setStartDate(long when)
          Set the start date of this Entity stored in its Dated.DFLT_START_DATE_ATTRIBUTE attribute.
 
Methods inherited from class au.com.zip.cs.AsyncObject
bgCommit, cacheFlush, delete, getAsyncState, getBgCommitFIFO, setAsyncState, setBgCommitFIFO, setChanged
 
Methods inherited from class au.com.zip.cs.CachableAdaptor
addSubCache, removeSubCache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SHORTNAME_ATTRIBUTENAME

public static final String DEFAULT_SHORTNAME_ATTRIBUTENAME
The default attribute name for an Entity's short name: NAME_SHORT.

See Also:
Constant Field Values

DEFAULT_LONGNAME_ATTRIBUTENAME

public static final String DEFAULT_LONGNAME_ATTRIBUTENAME
The default attribute name for an Entity's long name: NAME_LONG.

See Also:
Constant Field Values
Method Detail

getEntityTable

public EntityTable getEntityTable()
Description copied from interface: Entity
Return this entity's enclosing EntityTable.

Specified by:
getEntityTable in interface Entity
Returns:
the table

getID

public long getID()
Return the unique numeric identifier of this Entity.

Specified by:
getID in interface Entity
Specified by:
getID in interface HasID
Returns:
the id

getIndex

public int getIndex()
Description copied from interface: Entity
Return the index of this Entity in the enclosing EntityTable.

Specified by:
getIndex in interface Entity
Returns:
the Entity index

getShortName

public String getShortName()
Description copied from interface: Entity
Return the short name for this entity.

Specified by:
getShortName in interface Entity
Returns:
the short name

setShortName

public void setShortName(String name)
Description copied from interface: Entity
Set the Entity's short name. Normally it will be forbidden to set this to a name already in use. In many EntityTables this may be unimplemented.

Specified by:
setShortName in interface Entity
Parameters:
name - the new short name

getLongName

public String getLongName()
Description copied from interface: Entity
Return the long (descriptive) name for this entity.

Specified by:
getLongName in interface Entity
Returns:
the long name

setLongName

public void setLongName(String name)
Description copied from interface: Entity
Set the Entity's long name.

Specified by:
setLongName in interface Entity
Parameters:
name - the new long name

getAttributes

public Map getAttributes()
Return the attributes and values of this Entity. For example, these would be database table column names and values for a database record. Note that these are values associated with the Entity. The set of defined attributes (if such a thing even exists) is obtained from the Entity's enclosing EntityTable.

Specified by:
getAttributes in interface Entity
Returns:
the attributes
See Also:
getEntityTable()

getAttribute

public Object getAttribute(String name)
Return the named attribute value from this entity.

Specified by:
getAttribute in interface Entity
Parameters:
name - the attribute name
Returns:
the value

getNumericAttribute

public long getNumericAttribute(String name)
Return the numeric value of the named attribute value from this entity, which must be a Number.

Specified by:
getNumericAttribute in interface Entity
Parameters:
name - the attribute name
Returns:
the value

setAttribute

public void setAttribute(String name,
                         Object value)
Set the named attribute value from this entity.

Specified by:
setAttribute in interface Entity
Parameters:
name - the attribute name
value - the new value

getDatedAttribute

public long getDatedAttribute(String name)
Description copied from interface: Entity
Return the milliseconds value corresponding to the named attribute value from this entity. The attribute value must be a Number (if the date is stored as milliseconds) or a Date.

Specified by:
getDatedAttribute in interface Entity
Parameters:
name - the attribute name
Returns:
the value

datedToLong

public static long datedToLong(Object dated)
Convert a dated Object to a long time.

Parameters:
dated - the Object, which may be null
Returns:
the time in milliseconds
See Also:
Date

getStartDate

public long getStartDate()
Return the start date of this Entity from the Dated.DFLT_START_DATE_ATTRIBUTE attribute.

Specified by:
getStartDate in interface Dated
Returns:
the start date

getStartDate

public static long getStartDate(Entity e)
Return the start date of an Entity from its Dated.DFLT_START_DATE_ATTRIBUTE attribute.

Parameters:
e - the Entity to inspect
Returns:
the start date

setStartDate

public void setStartDate(long when)
Set the start date of this Entity stored in its Dated.DFLT_START_DATE_ATTRIBUTE attribute.

Specified by:
setStartDate in interface Dated
Parameters:
when - the start date

setStartDate

public static void setStartDate(Entity e,
                                long when)
Set the start date of an Entity stored in its Dated.DFLT_START_DATE_ATTRIBUTE attribute.

Parameters:
e - the Entity to inspect
when - the start date

getEndDate

public long getEndDate()
Return the end date of this Entity from its Dated.DFLT_START_DATE_ATTRIBUTE attribute.

Specified by:
getEndDate in interface Dated
Returns:
the end date

getEndDate

public static long getEndDate(Entity e)
Return the end date of an Entity obtained from its Dated.DFLT_START_DATE_ATTRIBUTE attribute.

Parameters:
e - the Entity to inspect
Returns:
the end date

setEndDate

public void setEndDate(long when)
Set the end date of this Entity stored in its Dated.DFLT_START_DATE_ATTRIBUTE attribute.

Specified by:
setEndDate in interface Dated
Parameters:
when - the end date

setEndDate

public static void setEndDate(Entity e,
                              long when)
Set the end date of an Entity stored in its Dated.DFLT_START_DATE_ATTRIBUTE attribute.

Parameters:
e - the Entity to inspect
when - the end date

currentAt

public static boolean currentAt(Entity e,
                                long when)

currentAt

public boolean currentAt(long when)

now

public static long now()
Return the current date in milliseconds since midnight, January 1, 1970 UTC.

Returns:
the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC
See Also:
System.currentTimeMillis()

overlaps

public static boolean overlaps(Entity e,
                               long start,
                               long end)
Check that the start and end dates for the supplied Entity overlay the date range specified by the start and end parameters.

Parameters:
e - the Entity to check
start - the start date
end - the end date
Returns:
whether the date ranges overlap

overlaps

public static boolean overlaps(long start1,
                               long end1,
                               long start2,
                               long end2)
Check that the start and end dates for the supplied ranges overlap.

Parameters:
start1 - the start date of the first range
end1 - the end date of the first range
start2 - the start date of the second range
end2 - the end date of the second range
Returns:
whether the date ranges overlap

isBetween

public static boolean isBetween(long when,
                                long start,
                                long end)

commit

public void commit()
Description copied from class: AsyncObject
Apply any pending changes to the persistent store. If AsyncObject.getAsyncState() returns AsyncObject.CLEAN this method is normally a no-op.

Specified by:
commit in class AsyncObject

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

longValue

public long longValue()

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable

compareIDTo

public static int compareIDTo(long id,
                              Object o)
Static access to the Comparable compareTo(Object) method.

Parameters:
id - the source id
o - the Object to which to compare
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
See Also:
Comparable.compareTo(Object)