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:
  • Constructor Details

    • Entity

      public Entity(EntityType entityType)
      Constructs a new DefaultEntity with the given entity type.
      Parameters:
      entityType - the type of the entity
    • Entity

      public Entity(EntityType entityType, long id)
      Constructs a new DefaultEntity with the given entity type and ID.
      Parameters:
      entityType - the type of the entity
      id - the initial ID of this entity object
    • Entity

      public Entity(EntityType entityType, int attributeCount)
      Constructs a new DefaultEntity with the given entity type. The ArrayList is initialised for the given number of attributes.
      Parameters:
      entityType - the type of the entity
      attributeCount - the number of attributes this entity will hold
  • Method Details

    • 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 this Entity-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 this Entity-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 this Entity-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 the Entity-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) (not null).
      Returns:
      Whether this entity has an ID attribute of integer type (Long) (not null).
    • 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 the Entity-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 is null. Please make sure that the attribute really is an int. You will receive a ClassCastException 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 the Entity-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 is null. Please make sure that the attribute really is a float. You will receive a ClassCastException 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 the Entity-object doesn't contain an attribute with this name
    • getString

      public String getString(String attrName) throws IllegalArgumentException
      This method will return the attribute value as 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.
      Parameters:
      attrName - the attribute whose value should be returned as String
      Returns:
      the attribute as string; or null
      Throws:
      IllegalArgumentException - if the Entity-object doesn't contain an attribute with this name
    • getDate

      public Date getDate(String attrName) throws IllegalArgumentException
      This method will return the attribute value as Date or null. Please make sure that the attribute really is a date. You will receive a ClassCastException if it isn't!
      Parameters:
      attrName - the attribute whose value should be returned as Date
      Returns:
      the attribute as string; or null
      Throws:
      IllegalArgumentException - if the Entity-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 two Entitys as equal if their ID attributes match. If either one of them does not have an ID this method returns false.
      Specified by:
      equals in interface Map<String,Object>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<String,Object>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • clone

      public Entity clone()
      Description copied from interface: TypedCloneable
      Clones this object (usually via Object.clone()).
      Specified by:
      clone in interface TypedCloneable<Entity>
      Overrides:
      clone in class Object
      Returns:
      A clone of the implementing object.
    • size

      public int size()
      Specified by:
      size in interface Map<String,Object>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<String,Object>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<String,Object>
    • get

      public Object get(Object key)
      Specified by:
      get in interface Map<String,Object>
    • put

      public Object put(String key, Object value)
      Specified by:
      put in interface Map<String,Object>
    • remove

      public Object remove(Object key)
      Specified by:
      remove in interface Map<String,Object>
    • putAll

      public void putAll(Map<? extends String,?> m)
      Specified by:
      putAll in interface Map<String,Object>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<String,Object>
    • keySet

      public Set<String> keySet()
      Specified by:
      keySet in interface Map<String,Object>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<String,Object>
    • values

      public Collection<Object> values()
      Specified by:
      values in interface Map<String,Object>
    • entrySet

      public Set<Map.Entry<String,Object>> entrySet()
      Specified by:
      entrySet in interface Map<String,Object>