public class Entity
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
Entity-object doesn't necessarily
have to contain all attributes that are defined for an entity type. In
future, there might be methods that allow the caller to specify which
attributes are needed.
All attribute names are case insensitive, still the original case should be
preserved. getAttributeNames() should reflect the insertion order of
the attributes.
This class not only defines methods to read but also to add and set attributes. These, however, will not be propagated to the data source!
When setting values it will NOT be ensured, that they have the correct data type or any known or supported data type at all. This is simply a container class!
| Constructor and Description |
|---|
Entity(EntityType entityType)
Constructs a new
DefaultEntity with the given entity type. |
Entity(EntityType entityType,
int attributeCount)
Constructs a new
DefaultEntity with the given entity type. |
Entity(EntityType entityType,
long id)
Constructs a new
DefaultEntity with the given entity type and ID. |
| Modifier and Type | Method and Description |
|---|---|
Entity |
clone() |
boolean |
containsAttribute(java.lang.String attrName)
Returns whether an attribute with the given name is contained in this
Entity-object. |
boolean |
equals(java.lang.Object obj)
This implementation recognises two
Entitys as equal if their ID
attributes match. |
java.lang.Object |
get(java.lang.String attrName)
Returns the value object for the given attribute name.
|
int |
getAttributeCount()
Returns the number of attributes stored in this
Entity-object. |
java.lang.String[] |
getAttributeNames()
Returns the names of the attributes that are contained in this
Entity-object. |
java.util.Date |
getDate(java.lang.String attrName)
This method will return the attribute value as
Date or null. |
double |
getFloat(java.lang.String attrName)
This method will return the attribute value as float or 0 if it is
null. |
long |
getInteger(java.lang.String attrName)
This method will return the attribute value as an int or 0 if it is
null. |
java.lang.String |
getString(java.lang.String attrName)
This method will return the attribute value as
String or
null. |
EntityType |
getType()
Returns the type of this entity.
|
int |
hashCode() |
boolean |
isNull(java.lang.String attrName)
Returns whether the specified attribute is null (not set) for this entity.
|
void |
removeAttribute(java.lang.String attrName)
Removes the given attribute from this entity.
|
void |
set(java.lang.String attrName,
java.lang.Object value)
Sets the given attribute to the given value.
|
void |
setDate(java.lang.String attrName,
java.util.Date value)
Sets the given attribute to the given value.
|
void |
setFloat(java.lang.String attrName,
double value)
Sets the given attribute to the given value.
|
void |
setInteger(java.lang.String attrName,
long value)
Sets the given attribute to the given value.
|
void |
setNull(java.lang.String attrName)
Sets the given attribute to the given value.
|
void |
setString(java.lang.String attrName,
java.lang.String value)
Sets the given attribute to the given value.
|
java.lang.String |
toString() |
public Entity(EntityType entityType)
DefaultEntity with the given entity type.entityType - the type of the entitypublic Entity(EntityType entityType, long id)
DefaultEntity with the given entity type and ID.entityType - the type of the entityid - the initial ID of this entity objectpublic Entity(EntityType entityType, int attributeCount)
DefaultEntity with the given entity type. The
ArrayList is initialised for the given number of attributes.entityType - the type of the entityattributeCount - the number of attributes this entity will holdpublic EntityType getType()
public int getAttributeCount()
Entity-object.Entity-objectpublic java.lang.String[] getAttributeNames()
Entity-object.Entity-objectpublic boolean containsAttribute(java.lang.String attrName)
Entity-object.attrName - the attribute name to be checkedEntity-objectpublic boolean isNull(java.lang.String attrName)
throws java.lang.IllegalArgumentException
attrName - the attribute name to be checkedjava.lang.IllegalArgumentException - if the Entity-object doesn't
contain an attribute with this namepublic void removeAttribute(java.lang.String attrName)
attrName - the attribute to be removed from this entitypublic java.lang.Object get(java.lang.String attrName)
throws java.lang.IllegalArgumentException
attrName - the attribute name for which the value object should be
returnedjava.lang.IllegalArgumentException - if the Entity-object doesn't
contain an attribute with this namepublic long getInteger(java.lang.String attrName)
throws java.lang.IllegalArgumentException
null. Please make sure that the attribute really is an int. You
will receive a ClassCastException if it isn't!attrName - the attribute whose value should be returned as an intnulljava.lang.IllegalArgumentException - if the Entity-object doesn't
contain an attribute with this namepublic double getFloat(java.lang.String attrName)
throws java.lang.IllegalArgumentException
null. Please make sure that the attribute really is a float. You
will receive a ClassCastException if it isn't!attrName - the attribute whose value should be returned as floatnulljava.lang.IllegalArgumentException - if the Entity-object doesn't
contain an attribute with this namepublic java.lang.String getString(java.lang.String attrName)
throws java.lang.IllegalArgumentException
String or
null. Please make sure that the attribute really is a string. You
will receive a ClassCastException if it isn't! If you need the
attribute in string representation regardless of the actual type,
get(..).toString() could be used instead.attrName - the attribute whose value should be returned as
Stringnulljava.lang.IllegalArgumentException - if the Entity-object doesn't
contain an attribute with this namepublic java.util.Date getDate(java.lang.String attrName)
throws java.lang.IllegalArgumentException
Date or null.
Please make sure that the attribute really is a date. You will receive a
ClassCastException if it isn't!attrName - the attribute whose value should be returned as
Datenulljava.lang.IllegalArgumentException - if the Entity-object doesn't
contain an attribute with this namepublic void set(java.lang.String attrName,
java.lang.Object value)
attrName - the attribute to be set (and added if needed)value - the value of the attributepublic void setNull(java.lang.String attrName)
attrName - the attribute to be set (and added if needed)public void setInteger(java.lang.String attrName,
long value)
attrName - the attribute to be set (and added if needed)value - the value of the attributepublic void setFloat(java.lang.String attrName,
double value)
attrName - the attribute to be set (and added if needed)value - the value of the attributepublic void setString(java.lang.String attrName,
java.lang.String value)
attrName - the attribute to be set (and added if needed)value - the value of the attributepublic void setDate(java.lang.String attrName,
java.util.Date value)
attrName - the attribute to be set (and added if needed)value - the value of the attributepublic boolean equals(java.lang.Object obj)
Entitys as equal if their ID
attributes match. If either one of them does not have an ID this method
returns false.equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic Entity clone()
clone in class java.lang.Object