Class Entity
- java.lang.Object
-
- de.aristaflow.adept2.model.orgmodel.Entity
-
- All Implemented Interfaces:
TypedCloneable<Entity>
,Serializable
,Cloneable
,Map<String,Object>
- Direct Known Subclasses:
OmeEntity
public class Entity extends Object implements Serializable, TypedCloneable<Entity>, Map<String,Object>
This class represents an entity, i.e. instance of an entity type like Agent, OrgPosition etc.. However, anEntity
-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!
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Entity(EntityType entityType)
Constructs a newDefaultEntity
with the given entity type.Entity(EntityType entityType, int attributeCount)
Constructs a newDefaultEntity
with the given entity type.Entity(EntityType entityType, long id)
Constructs a newDefaultEntity
with the given entity type and ID.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Entity
clone()
Clones this object (usually viaObject.clone()
).boolean
containsAttribute(String attrName)
Returns whether an attribute with the given name is contained in thisEntity
-object.boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<String,Object>>
entrySet()
boolean
equals(Object obj)
This implementation recognises twoEntity
s as equal if their ID attributes match.Object
get(Object key)
Object
get(String attrName)
Returns the value object for the given attribute name.int
getAttributeCount()
Returns the number of attributes stored in thisEntity
-object.String[]
getAttributeNames()
Returns the names of the attributes that are contained in thisEntity
-object.Date
getDate(String attrName)
This method will return the attribute value asDate
ornull
.double
getFloat(String attrName)
This method will return the attribute value as float or 0 if it isnull
.long
getInteger(String attrName)
This method will return the attribute value as an int or 0 if it isnull
.String
getString(String attrName)
This method will return the attribute value asString
ornull
.EntityType
getType()
Returns the type of this entity.int
hashCode()
boolean
hasIdAttr()
Gets whether this entity has an ID attribute of integer type (Long
) (notnull
).boolean
isEmpty()
boolean
isNull(String attrName)
Returns whether the specified attribute is null (not set) for this entity.Set<String>
keySet()
Object
put(String key, Object value)
void
putAll(Map<? extends String,?> m)
Object
remove(Object key)
void
removeAttribute(String attrName)
Removes the given attribute from this entity.boolean
set(String attrName, Object value)
Sets the given attribute to the given value.void
setDate(String attrName, Date value)
Sets the given attribute to the given value.void
setFloat(String attrName, double value)
Sets the given attribute to the given value.void
setInteger(String attrName, long value)
Sets the given attribute to the given value.void
setNull(String attrName)
Sets the given attribute to the given value.void
setString(String attrName, String value)
Sets the given attribute to the given value.int
size()
String
toString()
Collection<Object>
values()
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
Entity
public Entity(EntityType entityType)
Constructs a newDefaultEntity
with the given entity type.- Parameters:
entityType
- the type of the entity
-
Entity
public Entity(EntityType entityType, long id)
Constructs a newDefaultEntity
with the given entity type and ID.- Parameters:
entityType
- the type of the entityid
- the initial ID of this entity object
-
Entity
public Entity(EntityType entityType, int attributeCount)
Constructs a newDefaultEntity
with the given entity type. TheArrayList
is initialised for the given number of attributes.- Parameters:
entityType
- the type of the entityattributeCount
- the number of attributes this entity will hold
-
-
Method Detail
-
getType
public EntityType getType()
Returns the type of this entity.- Returns:
- the type of this entity
-
getAttributeCount
public int getAttributeCount()
Returns the number of attributes stored in thisEntity
-object.- Returns:
- the number of attributes stored in this
Entity
-object
-
getAttributeNames
public String[] getAttributeNames()
Returns the names of the attributes that are contained in thisEntity
-object.- Returns:
- a string array containing the names of the attributes that are
contained in this
Entity
-object
-
containsAttribute
public boolean containsAttribute(String attrName)
Returns whether an attribute with the given name is contained in thisEntity
-object.- Parameters:
attrName
- the attribute name to be checked- Returns:
- whether an attribute with the given name is contained in this
Entity
-object
-
isNull
public boolean isNull(String attrName) throws IllegalArgumentException
Returns whether the specified attribute is null (not set) for this entity.- Parameters:
attrName
- the attribute name to be checked- Returns:
- whether the specified attribute is null (not set) for this entity
- Throws:
IllegalArgumentException
- if theEntity
-object doesn't contain an attribute with this name
-
removeAttribute
public void removeAttribute(String attrName)
Removes the given attribute from this entity.- Parameters:
attrName
- the attribute to be removed from this entity
-
hasIdAttr
public boolean hasIdAttr()
Gets whether this entity has an ID attribute of integer type (Long
) (notnull
).- Returns:
- Whether this entity has an ID attribute of integer type (
Long
) (notnull
).
-
get
public Object get(String attrName) throws IllegalArgumentException
Returns the value object for the given attribute name.- Parameters:
attrName
- the attribute name for which the value object should be returned- Returns:
- the value object for the given attribute name
- Throws:
IllegalArgumentException
- if theEntity
-object doesn't contain an attribute with this name
-
getInteger
public long getInteger(String attrName) throws IllegalArgumentException
This method will return the attribute value as an int or 0 if it isnull
. Please make sure that the attribute really is an int. You will receive aClassCastException
if it isn't!- Parameters:
attrName
- the attribute whose value should be returned as an int- Returns:
- the attribute as an int; or 0 if it is
null
- Throws:
IllegalArgumentException
- if theEntity
-object doesn't contain an attribute with this name
-
getFloat
public double getFloat(String attrName) throws IllegalArgumentException
This method will return the attribute value as float or 0 if it isnull
. Please make sure that the attribute really is a float. You will receive aClassCastException
if it isn't!- Parameters:
attrName
- the attribute whose value should be returned as float- Returns:
- the attribute as float; or 0 if it is
null
- Throws:
IllegalArgumentException
- if theEntity
-object doesn't contain an attribute with this name
-
getString
public String getString(String attrName) throws IllegalArgumentException
This method will return the attribute value asString
ornull
. Please make sure that the attribute really is a string. You will receive aClassCastException
if it isn't! If you need the attribute in string representation regardless of the actual type,get(..).toString()
could be used instead.- Parameters:
attrName
- the attribute whose value should be returned asString
- Returns:
- the attribute as string; or
null
- Throws:
IllegalArgumentException
- if theEntity
-object doesn't contain an attribute with this name
-
getDate
public Date getDate(String attrName) throws IllegalArgumentException
This method will return the attribute value asDate
ornull
. Please make sure that the attribute really is a date. You will receive aClassCastException
if it isn't!- Parameters:
attrName
- the attribute whose value should be returned asDate
- Returns:
- the attribute as string; or
null
- Throws:
IllegalArgumentException
- if theEntity
-object doesn't contain an attribute with this name
-
set
public boolean set(String attrName, Object value)
Sets the given attribute to the given value. The attribute is added if it's not already contained in this entity-object.- Parameters:
attrName
- the attribute to be set (and added if needed)value
- the value of the attribute- Returns:
- Whether the designated attribute was new and therefore changed the attribute list of this entity.
-
setNull
public void setNull(String attrName)
Sets the given attribute to the given value. The attribute is added if it's not already contained in this entity-object.- Parameters:
attrName
- the attribute to be set (and added if needed)
-
setInteger
public void setInteger(String attrName, long value)
Sets the given attribute to the given value. The attribute is added if it's not already contained in this entity-object.- Parameters:
attrName
- the attribute to be set (and added if needed)value
- the value of the attribute
-
setFloat
public void setFloat(String attrName, double value)
Sets the given attribute to the given value. The attribute is added if it's not already contained in this entity-object.- Parameters:
attrName
- the attribute to be set (and added if needed)value
- the value of the attribute
-
setString
public void setString(String attrName, String value)
Sets the given attribute to the given value. The attribute is added if it's not already contained in this entity-object.- Parameters:
attrName
- the attribute to be set (and added if needed)value
- the value of the attribute
-
setDate
public void setDate(String attrName, Date value)
Sets the given attribute to the given value. The attribute is added if it's not already contained in this entity-object.- Parameters:
attrName
- the attribute to be set (and added if needed)value
- the value of the attribute
-
equals
public boolean equals(Object obj)
This implementation recognises twoEntity
s as equal if their ID attributes match. If either one of them does not have an ID this method returns false.
-
hashCode
public int hashCode()
-
clone
public Entity clone()
Description copied from interface:TypedCloneable
Clones this object (usually viaObject.clone()
).- Specified by:
clone
in interfaceTypedCloneable<Entity>
- Overrides:
clone
in classObject
- Returns:
- A clone of the implementing object.
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<String,Object>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<String,Object>
-
-