net.charlesames.utility.entity
Class Entity

java.lang.Object
  extended by net.charlesames.utility.common.Disposable
      extended by net.charlesames.utility.entity.Entity
All Implemented Interfaces:
EntityContainer
Direct Known Subclasses:
WriteableEntity

public abstract class Entity
extends Disposable
implements EntityContainer

Entity is an abstract base class enhancing Object. It adds four properties:
A reference to the container which holds this entity.
An integer ID which should be unique under the container (defaults to Integer.MIN_VALUE).
A text Name (defaults to blank);
A Handle which is unique among all Entity instances created during the current execution session. This value should not be persisted to file.
A Status property.
A Modifiable flag.

Author:
Charles Ames

Method Summary
 void decrementReferenceCount()
          Decrement the count of objects referencing this one.
static Entity dereferenceHandle(long handle)
          Dereference the Entity identified by the indicated handle.
 void dispose()
          Render this Entity amenable to garbage collection.
 boolean equals(Entity other)
          Test if this Entity instance has the same content as another Entity instance.
 EntityContainer getContainer()
          Getter for the Container property.
 long getHandle()
          Get the globally unique handle identifying this Entity.
 int getID()
          Getter for the ID property.
 java.lang.String getName()
          Getter for the Name property.
 java.lang.String getPath()
          Return a description of this entity and its containers.
 int getReferenceCount()
          Get the count of objects referencing this one.
 Status getStatus()
          Getter for the Status property.
 java.lang.String getText()
          Return a unique description of this entity.
 boolean hasContainer()
          Test if Container property is populated.
 void incrementReferenceCount()
          Increment the count of objects referencing this one.
 boolean isModifiable()
          Getter for the Modifiable property.
 boolean methodHasOverride(java.lang.Class<?> baseClass, java.lang.String methodName)
          Test if a class has overridden a base-class method.
 Entity predecessor(java.util.SortedMap<java.lang.Integer,? extends Entity> entities, int minID)
           
static void resequenceEntities(java.util.SortedMap<java.lang.Integer,? extends Entity> entities, int minID)
          A helper function which removes gaps from a sequence of entity id's.
 void setContainer(EntityContainer container)
          Setter for the Container property.
 boolean setID(int value)
          Setter for the ID property.
 void setModifiable(boolean modifiable)
          Setter for the Modifiable property.
 boolean setName(java.lang.String value)
          Setter for the Name property.
 boolean setStatus(Status value)
          Setter for the Status property.
static void shiftEntitiesDown(int startingID, int increment, java.util.SortedMap<java.lang.Integer,? extends Entity> entities, int minID)
          A helper function which moves a block of entities down within an id-indexed collection.
static void shiftEntityDown(int id, java.util.SortedMap<java.lang.Integer,? extends Entity> entities)
          A helper function which moves a specified entity down within an id-indexed collection.
static void shiftEntityUp(int id, java.util.SortedMap<java.lang.Integer,? extends Entity> entities, int minID)
          A helper function which moves a specified entity up within an id-indexed collection.
 Entity successor(java.util.SortedMap<java.lang.Integer,? extends Entity> entities)
           
 java.lang.String toString()
           
 void wipe()
          Clear all data in this Entity instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

wipe

public void wipe()
Clear all data in this Entity instance.


dispose

public final void dispose()
Render this Entity amenable to garbage collection.

Specified by:
dispose in class Disposable

getContainer

public EntityContainer getContainer()
Getter for the Container property.

Returns:
The assigned Container value.

hasContainer

public final boolean hasContainer()
Test if Container property is populated.

Returns:
False if container is null; true otherwise.

setContainer

public void setContainer(EntityContainer container)
Setter for the Container property.

Parameters:
container - The intended Container value.

isModifiable

public boolean isModifiable()
Getter for the Modifiable property.

Returns:
The assigned Modifiable value.

setModifiable

public void setModifiable(boolean modifiable)
Setter for the Modifiable property.

Parameters:
modifiable - The intended Modifiable value.

getID

public final int getID()
Getter for the ID property.

Returns:
The current ID value.

setID

public boolean setID(int value)
Setter for the ID property.

Parameters:
value - The intended ID value.
Returns:
True if an ID change actually happened; false otherwise.

getName

public java.lang.String getName()
Getter for the Name property.

Returns:
The current Name value.

setName

public boolean setName(java.lang.String value)
Setter for the Name property.

Parameters:
value - The intended Name value.
Returns:
True if a Name change actually happened; false otherwise.

getReferenceCount

public final int getReferenceCount()
Get the count of objects referencing this one.

Returns:
The count of objects referencing this one.

incrementReferenceCount

public void incrementReferenceCount()
Increment the count of objects referencing this one. Call this each time an object reference to this entity is populated.


decrementReferenceCount

public void decrementReferenceCount()
Decrement the count of objects referencing this one. Call this each time an object reference to this entity is nulled out or changed.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getHandle

public long getHandle()
Get the globally unique handle identifying this Entity.

Returns:
The globally unique handle identifying this Entity.

dereferenceHandle

public static Entity dereferenceHandle(long handle)
Dereference the Entity identified by the indicated handle.

Parameters:
handle - The indicated handle.
Returns:
The Entity identified by the indicated handle.

getText

public java.lang.String getText()
Return a unique description of this entity.

Returns:
A unique description of this entity.

getPath

public java.lang.String getPath()
Return a description of this entity and its containers.

Specified by:
getPath in interface EntityContainer
Returns:
A description of this entity and its containers.

getStatus

public final Status getStatus()
Getter for the Status property.

Returns:
The current Status value.

setStatus

public boolean setStatus(Status value)
Setter for the Status property.

Parameters:
value - The intended Status value.
Returns:
True if a Status change actually happened; false otherwise.

methodHasOverride

public boolean methodHasOverride(java.lang.Class<?> baseClass,
                                 java.lang.String methodName)
Test if a class has overridden a base-class method.

Parameters:
baseClass - The base class.
methodName - The method name
Returns:
True if the class overrides the method.

predecessor

public final Entity predecessor(java.util.SortedMap<java.lang.Integer,? extends Entity> entities,
                                int minID)
Parameters:
entities - An id-indexed collection which includes the present entity.
minID - Lowest acceptable id value.
Returns:
This entity's predecessor in the entities collection.

successor

public final Entity successor(java.util.SortedMap<java.lang.Integer,? extends Entity> entities)
Parameters:
entities - An id-indexed collection which includes the present entity.
Returns:
This entity's successor in the entities collection.

resequenceEntities

public static void resequenceEntities(java.util.SortedMap<java.lang.Integer,? extends Entity> entities,
                                      int minID)
A helper function which removes gaps from a sequence of entity id's.

Parameters:
entities - An id-indexed collection.
minID - Lowest acceptable id value.

shiftEntityUp

public static void shiftEntityUp(int id,
                                 java.util.SortedMap<java.lang.Integer,? extends Entity> entities,
                                 int minID)
A helper function which moves a specified entity up within an id-indexed collection.

Parameters:
id - The entity id
entities - An id-indexed collection.
minID - Lowest acceptable id value.

shiftEntityDown

public static void shiftEntityDown(int id,
                                   java.util.SortedMap<java.lang.Integer,? extends Entity> entities)
A helper function which moves a specified entity down within an id-indexed collection.

Parameters:
id - The entity id
entities - An id-indexed collection.

shiftEntitiesDown

public static void shiftEntitiesDown(int startingID,
                                     int increment,
                                     java.util.SortedMap<java.lang.Integer,? extends Entity> entities,
                                     int minID)
A helper function which moves a block of entities down within an id-indexed collection.

Parameters:
startingID - All entities in the collection with id's greater than or equal to the startingID will be shifted down.
increment - Number of positions to shift
entities - An id-indexed collection.
minID - Lowest acceptable id value.

equals

public boolean equals(Entity other)
Test if this Entity instance has the same content as another Entity instance.

Parameters:
other - The other Entity instance.
Returns:
True if the two entities have the same content. False otherwise.