Class ExtendedDocumentArray
- java.lang.Object
-
- com.inductiveautomation.ignition.common.document.DocumentElement
-
- com.inductiveautomation.ignition.common.document.DocumentArray
-
- com.inductiveautomation.ignition.common.document.ExtendedDocumentArray
-
- All Implemented Interfaces:
com.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>
,java.io.Serializable
,java.lang.Iterable<DocumentElement>
public class ExtendedDocumentArray extends DocumentArray
Allows cloning aDocumentArray
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. Ifextend(com.inductiveautomation.ignition.common.document.DocumentArray)
is called on anExtendedDocumentArray
the delegate DocumentArray is reused and modifications are copied to the newExtendedDocumentArray
.
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:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.inductiveautomation.ignition.common.document.DocumentArray
elements
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(DocumentElement element)
Adds the specified element to self.void
addAll(DocumentArray array)
Adds all the elements of the specified array to self.boolean
contains(DocumentElement element)
Returns true if this array contains the specified element.DocumentArray
deepCopy()
Creates a deep copy of this element and all its childrenstatic DocumentArray
extend(DocumentArray array)
DocumentElement
get(int i)
Returns the ith element of the array.java.util.Iterator<DocumentElement>
iterator()
Provides a safe iterator that extends elements before publishing through iterator, preventing mutation of backing array elements.DocumentElement
remove(int index)
Removes the element at the specified position in this array.boolean
remove(DocumentElement element)
Removes the first occurrence of the specified element from this array, if it is present.DocumentElement
set(int index, DocumentElement element)
Replaces the element at the specified position in this array with the specified element.int
size()
Returns the number of elements in the array.protected java.util.Iterator<DocumentElement>
unsafeIterator()
Provides iterator that publishes objects from backing array.-
Methods inherited from class com.inductiveautomation.ignition.common.document.DocumentArray
add, add, add, add, equals, getAsBigDecimal, getAsBigInteger, getAsBoolean, getAsByte, getAsCharacter, getAsDouble, getAsFloat, getAsInt, getAsLong, getAsNumber, getAsShort, getAsString, hashCode, toJsonElement
-
Methods inherited from class com.inductiveautomation.ignition.common.document.DocumentElement
fromJson, getAsDocument, getAsDocumentArray, getAsDocumentNull, getAsDocumentPrimitive, isDocument, isDocumentArray, isDocumentNull, isDocumentPrimitive, toString, toStringNoIndent
-
-
-
-
Method Detail
-
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 classDocumentArray
-
add
public void add(DocumentElement element)
Description copied from class:DocumentArray
Adds the specified element to self.- Overrides:
add
in classDocumentArray
- 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 classDocumentArray
- 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 classDocumentArray
- Parameters:
index
- index of the element to replaceelement
- 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 classDocumentArray
- 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 classDocumentArray
- 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 classDocumentArray
- 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 interfacecom.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>
- Overrides:
size
in classDocumentArray
- Returns:
- the number of elements in the array.
-
iterator
public java.util.Iterator<DocumentElement> iterator()
Provides a safe iterator that extends elements before publishing through iterator, preventing mutation of backing array elements.- Specified by:
iterator
in interfacejava.lang.Iterable<DocumentElement>
- Overrides:
iterator
in classDocumentArray
- Returns:
- an iterator to navigate the elements of the array.
-
unsafeIterator
protected java.util.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 classDocumentArray
-
get
public DocumentElement get(int i)
Description copied from class:DocumentArray
Returns the ith element of the array.- Specified by:
get
in interfacecom.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>
- Overrides:
get
in classDocumentArray
- Parameters:
i
- the index of the element that is being sought.- Returns:
- the element present at the ith index.
-
-