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, an
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!
- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionEntity(EntityType entityType) Constructs a newDefaultEntitywith the given entity type.Entity(EntityType entityType, int attributeCount) Constructs a newDefaultEntitywith the given entity type.Entity(EntityType entityType, long id) Constructs a newDefaultEntitywith the given entity type and ID. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()clone()Clones this object (usually viaObject.clone()).booleancontainsAttribute(String attrName) Returns whether an attribute with the given name is contained in thisEntity-object.booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()booleanThis implementation recognises twoEntitys as equal if their ID attributes match.Returns the value object for the given attribute name.intReturns the number of attributes stored in thisEntity-object.String[]Returns the names of the attributes that are contained in thisEntity-object.This method will return the attribute value asDateornull.doubleThis method will return the attribute value as float or 0 if it isnull.longgetInteger(String attrName) This method will return the attribute value as an int or 0 if it isnull.This method will return the attribute value asStringornull.getType()Returns the type of this entity.inthashCode()booleanGets whether this entity has an ID attribute of integer type (Long) (notnull).booleanisEmpty()booleanReturns whether the specified attribute is null (not set) for this entity.keySet()voidvoidremoveAttribute(String attrName) Removes the given attribute from this entity.booleanSets the given attribute to the given value.voidSets the given attribute to the given value.voidSets the given attribute to the given value.voidsetInteger(String attrName, long value) Sets the given attribute to the given value.voidSets the given attribute to the given value.voidSets the given attribute to the given value.intsize()toString()values()Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
Entity
Constructs a newDefaultEntitywith the given entity type.- Parameters:
entityType- the type of the entity
-
Entity
Constructs a newDefaultEntitywith the given entity type and ID.- Parameters:
entityType- the type of the entityid- the initial ID of this entity object
-
Entity
Constructs a newDefaultEntitywith the given entity type. TheArrayListis initialised for the given number of attributes.- Parameters:
entityType- the type of the entityattributeCount- the number of attributes this entity will hold
-
-
Method Details
-
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
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
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
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
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
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
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 aClassCastExceptionif 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
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 aClassCastExceptionif 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
This method will return the attribute value asStringornull. Please make sure that the attribute really is a string. You will receive aClassCastExceptionif 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
This method will return the attribute value asDateornull. Please make sure that the attribute really is a date. You will receive aClassCastExceptionif 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
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
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
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
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
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
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
This implementation recognises twoEntitys 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() -
toString
-
clone
Description copied from interface:TypedCloneableClones this object (usually viaObject.clone()).- Specified by:
clonein interfaceTypedCloneable<Entity>- Overrides:
clonein classObject- Returns:
- A clone of the implementing object.
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<String,Object>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
containsValue
- Specified by:
containsValuein interfaceMap<String,Object>
-
values
-
entrySet
-