Class CollectionProperty

java.lang.Object
io.higson.runtime.model.value.Property
io.higson.runtime.model.value.CollectionProperty
All Implemented Interfaces:
Handle, Iterable<Property>

public class CollectionProperty extends Property
This class represents collection of properties, that should store other properties with the same type TypeDef. All methods, which are accessing nested list, must follow this rule: 0 <= index < list.size(). Two collections of type CollectionProperty are equal in the sense of equals and hashCode, if their nested list are equals.
Author:
przemek hertel
Implementation Note:
on each add, set, methods there should be extra check, if added property is the same TypeDef as collection property type.
See Also:
  • Constructor Details

    • CollectionProperty

      public CollectionProperty(TypeDef type)
      Creates CollectionProperty for provided type definition.
      Parameters:
      type - definition
      See Also:
    • CollectionProperty

      public CollectionProperty(EntityType entityType)
      Creates CollectionProperty for provided compound entityType.
      Parameters:
      entityType - compound type
  • Method Details

    • add

      public CollectionProperty add(Property property)
      Attach given property at the end. Check if given property is already in tree, then creates reference to property and adds it to collection.
      Parameters:
      property - to add
      Returns:
      collection property on which this method is invoked
      See Also:
    • add

      public CollectionProperty add(Property property, boolean checkRef)
      Attach given property at the end. Check if given property is already in tree and checkRef == true, then creates reference to property and adds it to collection.
      Parameters:
      property - to add
      checkRef - indicates whether add mechanism should check if given property is already in bundle. If yes, then ref property is created
      Returns:
      collection property on which this method is invoked
    • add

      public CollectionProperty add(int index, Property property)
      Attach given property at provided index. Check if given property is already in tree, then creates reference to property and adds it to collection.
      Parameters:
      index - in which given property should be added
      property - to add
      Returns:
      collection property on which this method is invoked
      See Also:
    • add

      public CollectionProperty add(int index, Property property, boolean checkRef)
      Attach given property at provided index. Check if given property is already in tree and checkRef == true, then creates reference to property and adds it to collection.
      Parameters:
      index - index in which given property should be added
      property - to add
      checkRef - indicates whether add mechanism should check if given property is already in bundle. If yes, then ref property is created
      Returns:
      collection property on which this method is invoked
    • set

      public CollectionProperty set(int index, Property property)
      Attach given property at provided index. Previous node will be removed from collections at index position.
      Parameters:
      index - index at which property should be replaced
      property - property to put at index
      Returns:
      collection property on which this method is invoked
      Throws:
      IndexOutOfBoundsException - if index is greater then size of collection
      See Also:
    • getList

      public List<Property> getList()
      Returns:
      list of properties in kept order
    • mark

      public void mark()
      Marks collection property state to EntityState.PERSISTENT.
    • add

      public CollectionProperty add(Property... properties)
      Adds multiple properties in given order using add(Property).
      Specified by:
      add in interface Handle
      Overrides:
      add in class Property
      Parameters:
      properties - to add
      Returns:
      collection property on which this method is invoked
      See Also:
    • size

      public int size()
      Specified by:
      size in interface Handle
      Overrides:
      size in class Property
      Returns:
      size of collection
    • iterator

      public Iterator<Property> iterator()
      Description copied from class: Property
      .
      Specified by:
      iterator in interface Iterable<Property>
      Overrides:
      iterator in class Property
      Returns:
      new iterator instance
    • at

      public Property at(int index)
      Gets property at given index withing this property. Index starts with 0.
      If index is smaller then 0 or exceeds list size, then exception will be throw.
      Specified by:
      at in interface Handle
      Overrides:
      at in class Property
      Parameters:
      index - index to retrieve element from
      Returns:
      property from collection
      Throws:
      HigsonBundleUsageException - if index is not available for list
    • clear

      public Property clear()
      Clear all children of this property.
      Removes each element and all metadata behind.
      Specified by:
      clear in interface Handle
      Overrides:
      clear in class Property
      Returns:
      this
    • set

      public void set(Object value)
      value must be of type CollectionProperty, then all elements of this value will be added to this CollectionProperty instance. Otherwise exception will be thrown.
      Specified by:
      set in interface Handle
      Overrides:
      set in class Property
      Parameters:
      value - to be used
      Throws:
      HigsonBundleUsageException - if value is not instance of CollectionProperty
    • create

      public Property create()
      Creates new property of EntityProperty with compound type matching collection supported type.
      Specified by:
      create in interface Handle
      Overrides:
      create in class Property
      Returns:
      new property
    • find

      public Property find(long id)
      Search for element with id within collection and it's subtree.
      Parameters:
      id - child id
      Returns:
      property if found or null
    • getElementType

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

      public Property deepcopy(boolean resetIds)
      Creates defensive copies of collection property and it's property elements. There is possibility to control id's of elements with given resetIds.
      Specified by:
      deepcopy in class Property
      Parameters:
      resetIds - whether to reset ids on copy
      Returns:
      new instance of CollectionProperty
      See Also:
    • resetIds

      public void resetIds()
      Resets owner id and reset ids on each property element from list.
      Overrides:
      resetIds in class Property
    • print

      public void print(StringBuilder sb, int level, String prefix, String suffix)
      Adds to sb formatted String, specific for ValueProperty, which looks like:
      
         * covers  collection(Cover)  size=2
           * covers[0]  (Cover#1003  @21133) refc=1
             * code = CA  (string)
             * premium = 100  (number)
             * su = 10000  (number)
           * covers[1]  (Cover#1004  @45743) refc=1
             * code = CB  (string)
             * premium = 200  (number)
             * su = 20000  (number)
       
      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
      See Also:
    • equals

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

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

      public long getId()
      Specified by:
      getId in class Property
      Returns:
      owner id
    • isCollection

      public boolean isCollection()
      Description copied from class: Property
      Is property a collection type.
      Specified by:
      isCollection in interface Handle
      Overrides:
      isCollection in class Property
      Returns:
      true
      See Also:
    • toString

      public String toString()
      Formatted String as follows:
      
       	CollectionProperty[collection1 (MyType)  size=1]
       
      Overrides:
      toString in class Object
      Returns:
      formatted String
    • toArray

      public Property[] toArray()
      Creates snapshot array
      Returns:
      array of properties