Class ExtendedDocumentArray

All Implemented Interfaces:
com.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>, Serializable, Iterable<DocumentElement>

public class ExtendedDocumentArray extends DocumentArray
Allows cloning a DocumentArray without having to create a deep copy of all it's elements. This is managed by tracking all modifications to a delegate DocumentArray instead of applying those modifications directly to the DocumentArray. If extend(com.inductiveautomation.ignition.common.document.DocumentArray) is called on an ExtendedDocumentArray the delegate DocumentArray is reused and modifications are copied to the new ExtendedDocumentArray.

It's extremely important that the delegate DocumentArray is never modified. In cases where the delegate DocumentArray might change, DocumentArray.deepCopy() should be used instead.
See Also:
  • Method Details

    • extend

      public static DocumentArray extend(DocumentArray array)
    • deepCopy

      public DocumentArray deepCopy()
      Description copied from class: DocumentArray
      Creates a deep copy of this element and all its children
      Overrides:
      deepCopy in class DocumentArray
    • add

      public void add(DocumentElement element)
      Description copied from class: DocumentArray
      Adds the specified element to self.
      Overrides:
      add in class DocumentArray
      Parameters:
      element - the element that needs to be added to the array.
    • addAll

      public void addAll(DocumentArray array)
      Description copied from class: DocumentArray
      Adds all the elements of the specified array to self.
      Overrides:
      addAll in class DocumentArray
      Parameters:
      array - the array whose elements need to be added to the array.
    • set

      public DocumentElement set(int index, DocumentElement element)
      Description copied from class: DocumentArray
      Replaces the element at the specified position in this array with the specified element. Element can be null.
      Overrides:
      set in class DocumentArray
      Parameters:
      index - index of the element to replace
      element - element to be stored at the specified position
      Returns:
      the element previously at the specified position
    • remove

      public boolean remove(DocumentElement element)
      Description copied from class: DocumentArray
      Removes the first occurrence of the specified element from this array, if it is present. If the array does not contain the element, it is unchanged.
      Overrides:
      remove in class DocumentArray
      Parameters:
      element - element to be removed from this array, if present
      Returns:
      true if this array contained the specified element, false otherwise
    • remove

      public DocumentElement remove(int index)
      Description copied from class: DocumentArray
      Removes the element at the specified position in this array. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the array.
      Overrides:
      remove in class DocumentArray
      Parameters:
      index - index the index of the element to be removed
      Returns:
      the element previously at the specified position
    • contains

      public boolean contains(DocumentElement element)
      Description copied from class: DocumentArray
      Returns true if this array contains the specified element.
      Overrides:
      contains in class DocumentArray
      Parameters:
      element - whose presence in this array is to be tested
      Returns:
      true if this array contains the specified element.
    • size

      public int size()
      Description copied from class: DocumentArray
      Returns the number of elements in the array.
      Specified by:
      size in interface com.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>
      Overrides:
      size in class DocumentArray
      Returns:
      the number of elements in the array.
    • iterator

      public Iterator<DocumentElement> iterator()
      Provides a safe iterator that extends elements before publishing through iterator, preventing mutation of backing array elements.
      Specified by:
      iterator in interface Iterable<DocumentElement>
      Overrides:
      iterator in class DocumentArray
      Returns:
      an iterator to navigate the elements of the array.
    • unsafeIterator

      protected Iterator<DocumentElement> unsafeIterator()
      Provides iterator that publishes objects from backing array. Used internally for more efficient access to elements that we know won't be modified (equals, hashCode, etc).
      Overrides:
      unsafeIterator in class DocumentArray
    • get

      public DocumentElement get(int i)
      Description copied from class: DocumentArray
      Returns the ith element of the array.
      Specified by:
      get in interface com.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>
      Overrides:
      get in class DocumentArray
      Parameters:
      i - the index of the element that is being sought.
      Returns:
      the element present at the ith index.