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 aDocumentArraywithout 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 anExtendedDocumentArraythe 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 voidadd(DocumentElement element)Adds the specified element to self.voidaddAll(DocumentArray array)Adds all the elements of the specified array to self.booleancontains(DocumentElement element)Returns true if this array contains the specified element.DocumentArraydeepCopy()Creates a deep copy of this element and all its childrenstatic DocumentArrayextend(DocumentArray array)DocumentElementget(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.DocumentElementremove(int index)Removes the element at the specified position in this array.booleanremove(DocumentElement element)Removes the first occurrence of the specified element from this array, if it is present.DocumentElementset(int index, DocumentElement element)Replaces the element at the specified position in this array with the specified element.intsize()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:DocumentArrayCreates a deep copy of this element and all its children- Overrides:
deepCopyin classDocumentArray
-
add
public void add(DocumentElement element)
Description copied from class:DocumentArrayAdds the specified element to self.- Overrides:
addin classDocumentArray- Parameters:
element- the element that needs to be added to the array.
-
addAll
public void addAll(DocumentArray array)
Description copied from class:DocumentArrayAdds all the elements of the specified array to self.- Overrides:
addAllin 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:DocumentArrayReplaces the element at the specified position in this array with the specified element. Element can be null.- Overrides:
setin 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:DocumentArrayRemoves 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:
removein 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:DocumentArrayRemoves 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:
removein 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:DocumentArrayReturns true if this array contains the specified element.- Overrides:
containsin 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:DocumentArrayReturns the number of elements in the array.- Specified by:
sizein interfacecom.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>- Overrides:
sizein 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:
iteratorin interfacejava.lang.Iterable<DocumentElement>- Overrides:
iteratorin 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:
unsafeIteratorin classDocumentArray
-
get
public DocumentElement get(int i)
Description copied from class:DocumentArrayReturns the ith element of the array.- Specified by:
getin interfacecom.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>- Overrides:
getin classDocumentArray- Parameters:
i- the index of the element that is being sought.- Returns:
- the element present at the ith index.
-
-