Class EntityProperty

java.lang.Object
io.higson.runtime.model.value.Property
io.higson.runtime.model.value.EntityProperty
All Implemented Interfaces:
Handle, Iterable<Property>
Direct Known Subclasses:
Bundle

public class EntityProperty extends Property
This class represents property of entity (complex) type with fields. Each filed is stored as:

  * key -> field name, which is case sensitive
  * value -> another Property - subtype of {@link Property }
 
Basic API methods:
Author:
przemek hertel
See Also:
  • Constructor Details

    • EntityProperty

      public EntityProperty(EntityType entityType)
      Creates entity (complex) property based on given entityType.
      Parameters:
      entityType - complex entity types
      See Also:
    • EntityProperty

      public EntityProperty(long id, EntityType entityType)
      Creates entity (complex) property with id, based on given entityType.
      Parameters:
      id - for property
      entityType - complex entity types
      See Also:
  • Method Details

    • add

      public EntityProperty add(String name, Property prop)
      Adds given property under provided name. Name is case sensitive. If there is already some property under this name, then new prop will override previous property. If provided property is CollectionProperty, then all it's children will also have mapped parent to this.
      Parameters:
      name - unique name
      prop - property to store under name
      Returns:
      same EntityProperty instance
      See Also:
    • setBundle

      public void setBundle(Bundle bundle)

      children fields will also have their bundle setup.
    • getFields

      public Map<String,Property> getFields()
      Returns:
      property fields, where key is name of a field, and value is associated property
    • containsOnlyEntityFields

      public boolean containsOnlyEntityFields()
      Returns:
      true if all children fields are entities
    • getProp

      public Property getProp(String name)
      Gets property based on given name.
      Parameters:
      name - of field
      Returns:
      property if found or null
      See Also:
    • getValue

      public ValueProperty getValue(String name)
      Gets ValueProperty based on given name. It may throw cast exception, if property of name is not type of ValueProperty.
      Parameters:
      name - of field
      Returns:
      property if found or null
      See Also:
    • getId

      public long getId()
      Specified by:
      getId in class Property
      Returns:
      id of property
    • setId

      public void setId(long id)
      Sets id.
      Parameters:
      id - for property
    • getElementType

      public ElementType getElementType()
      Description copied from interface: Handle
      Gets associated element type, based on property implementation.
      Returns:
      ElementType.ENTITY element type
      See Also:
    • isEntity

      public boolean isEntity()
      Description copied from class: Property
      Is property an entity.
      Specified by:
      isEntity in interface Handle
      Overrides:
      isEntity in class Property
      Returns:
      true
      See Also:
    • deepcopy

      public Property deepcopy(boolean resetIds)
      Returns deep copy of this property's subtree.
      It copies nested properties and reconstructs references to this property.
      Specified by:
      deepcopy in class Property
      Parameters:
      resetIds - control flag, if true then property and all elements will have their id set to 0, if false, id will be copied
      Returns:
      new instance of EntityProperty
      See Also:
    • resetIds

      public void resetIds()
      Reset ids. Also it will reset ids of all children properties stored in fields.
      Overrides:
      resetIds in class Property
    • print

      public void print(StringBuilder sb, int level, String prefix, String suffix)
      Prints subtree to string builder.
      Specified by:
      print in class Property
      Parameters:
      sb - StringBuilder containing data to print
      level - level used to indentation
      prefix - value to used as prefix
      suffix - value to used as suffix
    • printValues

      public String printValues()
      Creates formatted String. Example:
      
       	 EntityProperty[entityName#123, owner=44, values={field1=test}]
       
      Returns:
      formatted String
    • size

      public int size()
      Specified by:
      size in interface Handle
      Overrides:
      size in class Property
      Returns:
      number of fields within this property
    • create

      public Property create()
      Description copied from class: Property
      Specified by:
      create in interface Handle
      Overrides:
      create in class Property
      Returns:
      new instance of EntityProperty based on this compound type definition.
    • has

      public boolean has(String path)
      Checks if this property has element of given path.
      This can check either direct field or nested children.
      Parameters:
      path - of element to be checked
      Returns:
      true if found, false otherwise
    • set

      public void set(Object value)
      Sets new value of this property..
      It changes references and collection(container) properties with this new value or adds a new one.
      Specified by:
      set in interface Handle
      Overrides:
      set in class Property
      Parameters:
      value - must be sub type of Property or exception will be thrown.
      Throws:
      HigsonBundleUsageException - if value is not sub type of Property
    • find

      public Property find(long id)
      Find child property by id.
      Parameters:
      id - child id
      Returns:
      child if found, null otherwise
    • getState

      public EntityState getState()
      Gets state of property. There are two possible states of entity:
      Specified by:
      getState in interface Handle
      Overrides:
      getState in class Property
      Returns:
      state of property
    • mark

      public void mark()
      Marks entity property to EntityState.PERSISTENT.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Property
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Property
    • toString

      public String toString()
      Formatted String as follows:
      
        EntityProperty[name#23, @432423432, owner=101, fields=field1, refc=2]
       
      Overrides:
      toString in class Object
      Returns:
      formatted String