Class DocumentArray
java.lang.Object
com.inductiveautomation.ignition.common.document.DocumentElement
com.inductiveautomation.ignition.common.document.DocumentArray
- All Implemented Interfaces:
com.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>
,Serializable
,Iterable<DocumentElement>
- Direct Known Subclasses:
ExtendedDocumentArray
public class DocumentArray
extends DocumentElement
implements Iterable<DocumentElement>, com.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>
A class representing an array type in Json. An array is a list of
DocumentElement
s each of which can be of a
different type. This is an ordered list, meaning that the order in which elements are added is preserved.- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty DocumentArray.DocumentArray
(int capacity) DocumentArray
(com.inductiveautomation.ignition.common.gson.JsonArray json) -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(DocumentElement element) Adds the specified element to self.void
Adds the specified boolean to self.void
Adds the specified character to self.void
Adds the specified number to self.void
Adds the specified string 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.deepCopy()
Creates a deep copy of this element and all its childrenboolean
get
(int i) Returns the ith element of the array.convenience method to get this array as aBigDecimal
if it contains a single element.convenience method to get this array as aBigInteger
if it contains a single element.boolean
convenience method to get this array as a boolean if it contains a single element.byte
convenience method to get this element as a primitive byte value.char
convenience method to get this element as a primitive character value.double
convenience method to get this array as a double if it contains a single element.float
convenience method to get this array as a float if it contains a single element.int
getAsInt()
convenience method to get this array as an integer if it contains a single element.long
convenience method to get this array as a long if it contains a single element.convenience method to get this array as aNumber
if it contains a single element.short
convenience method to get this array as a primitive short if it contains a single element.convenience method to get this array as aString
if it contains a single element.int
hashCode()
iterator()
Returns an iterator to navigate the elements of the array.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.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.com.inductiveautomation.ignition.common.gson.JsonArray
protected Iterator<DocumentElement>
Internal uses of iterator should use this method instead ofiterator()
.Methods inherited from class com.inductiveautomation.ignition.common.document.DocumentElement
fromJson, getAsDocument, getAsDocumentArray, getAsDocumentNull, getAsDocumentPrimitive, isDocument, isDocumentArray, isDocumentNull, isDocumentPrimitive, toString, toStringNoIndent
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
elements
-
-
Constructor Details
-
DocumentArray
public DocumentArray()Creates an empty DocumentArray. -
DocumentArray
public DocumentArray(int capacity) -
DocumentArray
public DocumentArray(com.inductiveautomation.ignition.common.gson.JsonArray json)
-
-
Method Details
-
deepCopy
Creates a deep copy of this element and all its children- Specified by:
deepCopy
in classDocumentElement
-
toJsonElement
public com.inductiveautomation.ignition.common.gson.JsonArray toJsonElement()- Specified by:
toJsonElement
in classDocumentElement
-
add
Adds the specified boolean to self.- Parameters:
bool
- the boolean that needs to be added to the array.
-
add
Adds the specified character to self.- Parameters:
character
- the character that needs to be added to the array.
-
add
Adds the specified number to self.- Parameters:
number
- the number that needs to be added to the array.
-
add
Adds the specified string to self.- Parameters:
string
- the string that needs to be added to the array.
-
add
Adds the specified element to self.- Parameters:
element
- the element that needs to be added to the array.
-
addAll
Adds all the elements of the specified array to self.- Parameters:
array
- the array whose elements need to be added to the array.
-
set
Replaces the element at the specified position in this array with the specified element. Element can be null.- Parameters:
index
- index of the element to replaceelement
- element to be stored at the specified position- Returns:
- the element previously at the specified position
- Throws:
IndexOutOfBoundsException
- if the specified index is outside the array bounds
-
remove
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.- Parameters:
element
- element to be removed from this array, if present- Returns:
- true if this array contained the specified element, false otherwise
-
remove
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.- Parameters:
index
- index the index of the element to be removed- Returns:
- the element previously at the specified position
- Throws:
IndexOutOfBoundsException
- if the specified index is outside the array bounds
-
contains
Returns true if this array contains the specified element.- Parameters:
element
- whose presence in this array is to be tested- Returns:
- true if this array contains the specified element.
-
size
public int size()Returns the number of elements in the array.- Specified by:
size
in interfacecom.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>
- Returns:
- the number of elements in the array.
-
iterator
Returns an iterator to navigate the elements of the array. Since the array is an ordered list, the iterator navigates the elements in the order they were inserted.- Specified by:
iterator
in interfaceIterable<DocumentElement>
- Returns:
- an iterator to navigate the elements of the array.
-
unsafeIterator
Internal uses of iterator should use this method instead ofiterator()
. Provides an iterator that returns the same elements in this array, allowing for mutating this class through those elements. This is more efficient than the publiciterator()
where subclasses might need to make safe copies of those elements before exposing through iterator. -
get
Returns the ith element of the array.- Specified by:
get
in interfacecom.inductiveautomation.ignition.common.document.DiffTree.Producer<DocumentElement>
- Parameters:
i
- the index of the element that is being sought.- Returns:
- the element present at the ith index.
- Throws:
IndexOutOfBoundsException
- if i is negative or greater than or equal to thesize()
of the array.
-
getAsNumber
convenience method to get this array as aNumber
if it contains a single element.- Overrides:
getAsNumber
in classDocumentElement
- Returns:
- get this element as a number if it is single element array.
- Throws:
ClassCastException
- if the element in the array is of not aDocumentPrimitive
and is not a valid Number.IllegalStateException
- if the array has more than one element.
-
getAsString
convenience method to get this array as aString
if it contains a single element.- Overrides:
getAsString
in classDocumentElement
- Returns:
- get this element as a String if it is single element array.
- Throws:
ClassCastException
- if the element in the array is of not aDocumentPrimitive
and is not a valid String.IllegalStateException
- if the array has more than one element.
-
getAsDouble
public double getAsDouble()convenience method to get this array as a double if it contains a single element.- Overrides:
getAsDouble
in classDocumentElement
- Returns:
- get this element as a double if it is single element array.
- Throws:
ClassCastException
- if the element in the array is of not aDocumentPrimitive
and is not a valid double.IllegalStateException
- if the array has more than one element.
-
getAsBigDecimal
convenience method to get this array as aBigDecimal
if it contains a single element.- Overrides:
getAsBigDecimal
in classDocumentElement
- Returns:
- get this element as a
BigDecimal
if it is single element array. - Throws:
ClassCastException
- if the element in the array is of not aDocumentPrimitive
.NumberFormatException
- if the element at index 0 is not a validBigDecimal
.IllegalStateException
- if the array has more than one element.
-
getAsBigInteger
convenience method to get this array as aBigInteger
if it contains a single element.- Overrides:
getAsBigInteger
in classDocumentElement
- Returns:
- get this element as a
BigInteger
if it is single element array. - Throws:
ClassCastException
- if the element in the array is of not aDocumentPrimitive
.NumberFormatException
- if the element at index 0 is not a validBigInteger
.IllegalStateException
- if the array has more than one element.
-
getAsFloat
public float getAsFloat()convenience method to get this array as a float if it contains a single element.- Overrides:
getAsFloat
in classDocumentElement
- Returns:
- get this element as a float if it is single element array.
- Throws:
ClassCastException
- if the element in the array is of not aDocumentPrimitive
and is not a valid float.IllegalStateException
- if the array has more than one element.
-
getAsLong
public long getAsLong()convenience method to get this array as a long if it contains a single element.- Overrides:
getAsLong
in classDocumentElement
- Returns:
- get this element as a long if it is single element array.
- Throws:
ClassCastException
- if the element in the array is of not aDocumentPrimitive
and is not a valid long.IllegalStateException
- if the array has more than one element.
-
getAsInt
public int getAsInt()convenience method to get this array as an integer if it contains a single element.- Overrides:
getAsInt
in classDocumentElement
- Returns:
- get this element as an integer if it is single element array.
- Throws:
ClassCastException
- if the element in the array is of not aDocumentPrimitive
and is not a valid integer.IllegalStateException
- if the array has more than one element.
-
getAsByte
public byte getAsByte()Description copied from class:DocumentElement
convenience method to get this element as a primitive byte value.- Overrides:
getAsByte
in classDocumentElement
- Returns:
- get this element as a primitive byte value.
-
getAsCharacter
public char getAsCharacter()Description copied from class:DocumentElement
convenience method to get this element as a primitive character value.- Overrides:
getAsCharacter
in classDocumentElement
- Returns:
- get this element as a primitive char value.
-
getAsShort
public short getAsShort()convenience method to get this array as a primitive short if it contains a single element.- Overrides:
getAsShort
in classDocumentElement
- Returns:
- get this element as a primitive short if it is single element array.
- Throws:
ClassCastException
- if the element in the array is of not aDocumentPrimitive
and is not a valid short.IllegalStateException
- if the array has more than one element.
-
getAsBoolean
public boolean getAsBoolean()convenience method to get this array as a boolean if it contains a single element.- Overrides:
getAsBoolean
in classDocumentElement
- Returns:
- get this element as a boolean if it is single element array.
- Throws:
ClassCastException
- if the element in the array is of not aDocumentPrimitive
and is not a valid boolean.IllegalStateException
- if the array has more than one element.
-
equals
-
hashCode
public int hashCode()
-