Class DocumentArray

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<DocumentElement>

    public final class DocumentArray
    extends DocumentElement
    implements java.lang.Iterable<DocumentElement>
    A class representing an array type in Json. An array is a list of DocumentElements 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:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DocumentArray()
      Creates an empty DocumentArray.
      DocumentArray​(int capacity)  
      DocumentArray​(com.inductiveautomation.ignition.common.gson.JsonArray json)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(DocumentElement element)
      Adds the specified element to self.
      void add​(java.lang.Boolean bool)
      Adds the specified boolean to self.
      void add​(java.lang.Character character)
      Adds the specified character to self.
      void add​(java.lang.Number number)
      Adds the specified number to self.
      void add​(java.lang.String string)
      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.
      DocumentArray deepCopy()
      Creates a deep copy of this element and all its children
      boolean equals​(java.lang.Object o)  
      DocumentElement get​(int i)
      Returns the ith element of the array.
      java.math.BigDecimal getAsBigDecimal()
      convenience method to get this array as a BigDecimal if it contains a single element.
      java.math.BigInteger getAsBigInteger()
      convenience method to get this array as a BigInteger if it contains a single element.
      boolean getAsBoolean()
      convenience method to get this array as a boolean if it contains a single element.
      byte getAsByte()
      convenience method to get this element as a primitive byte value.
      char getAsCharacter()
      convenience method to get this element as a primitive character value.
      double getAsDouble()
      convenience method to get this array as a double if it contains a single element.
      float getAsFloat()
      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 getAsLong()
      convenience method to get this array as a long if it contains a single element.
      java.lang.Number getAsNumber()
      convenience method to get this array as a Number if it contains a single element.
      short getAsShort()
      convenience method to get this array as a primitive short if it contains a single element.
      java.lang.String getAsString()
      convenience method to get this array as a String if it contains a single element.
      int hashCode()  
      java.util.Iterator<DocumentElement> iterator()
      Returns an iterator to navigate the elements of the array.
      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.
      com.inductiveautomation.ignition.common.gson.JsonArray toJsonElement()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • DocumentArray

        public DocumentArray()
        Creates an empty DocumentArray.
      • DocumentArray

        public DocumentArray​(int capacity)
      • DocumentArray

        public DocumentArray​(com.inductiveautomation.ignition.common.gson.JsonArray json)
    • Method Detail

      • toJsonElement

        public com.inductiveautomation.ignition.common.gson.JsonArray toJsonElement()
        Specified by:
        toJsonElement in class DocumentElement
      • add

        public void add​(java.lang.Boolean bool)
        Adds the specified boolean to self.
        Parameters:
        bool - the boolean that needs to be added to the array.
      • add

        public void add​(java.lang.Character character)
        Adds the specified character to self.
        Parameters:
        character - the character that needs to be added to the array.
      • add

        public void add​(java.lang.Number number)
        Adds the specified number to self.
        Parameters:
        number - the number that needs to be added to the array.
      • add

        public void add​(java.lang.String string)
        Adds the specified string to self.
        Parameters:
        string - the string that needs to be added to the array.
      • add

        public void add​(DocumentElement element)
        Adds the specified element to self.
        Parameters:
        element - the element that needs to be added to the array.
      • addAll

        public void addAll​(DocumentArray array)
        Adds all the elements of the specified array to self.
        Parameters:
        array - the array whose elements need to be added to the array.
      • set

        public DocumentElement set​(int index,
                                   DocumentElement element)
        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 replace
        element - element to be stored at the specified position
        Returns:
        the element previously at the specified position
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is outside the array bounds
      • remove

        public boolean remove​(DocumentElement element)
        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

        public DocumentElement remove​(int index)
        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:
        java.lang.IndexOutOfBoundsException - if the specified index is outside the array bounds
      • contains

        public boolean contains​(DocumentElement element)
        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.
        Returns:
        the number of elements in the array.
      • iterator

        public java.util.Iterator<DocumentElement> 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 interface java.lang.Iterable<DocumentElement>
        Returns:
        an iterator to navigate the elements of the array.
      • get

        public DocumentElement get​(int i)
        Returns the ith element of the array.
        Parameters:
        i - the index of the element that is being sought.
        Returns:
        the element present at the ith index.
        Throws:
        java.lang.IndexOutOfBoundsException - if i is negative or greater than or equal to the size() of the array.
      • getAsNumber

        public java.lang.Number getAsNumber()
        convenience method to get this array as a Number if it contains a single element.
        Overrides:
        getAsNumber in class DocumentElement
        Returns:
        get this element as a number if it is single element array.
        Throws:
        java.lang.ClassCastException - if the element in the array is of not a DocumentPrimitive and is not a valid Number.
        java.lang.IllegalStateException - if the array has more than one element.
      • getAsString

        public java.lang.String getAsString()
        convenience method to get this array as a String if it contains a single element.
        Overrides:
        getAsString in class DocumentElement
        Returns:
        get this element as a String if it is single element array.
        Throws:
        java.lang.ClassCastException - if the element in the array is of not a DocumentPrimitive and is not a valid String.
        java.lang.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 class DocumentElement
        Returns:
        get this element as a double if it is single element array.
        Throws:
        java.lang.ClassCastException - if the element in the array is of not a DocumentPrimitive and is not a valid double.
        java.lang.IllegalStateException - if the array has more than one element.
      • getAsBigDecimal

        public java.math.BigDecimal getAsBigDecimal()
        convenience method to get this array as a BigDecimal if it contains a single element.
        Overrides:
        getAsBigDecimal in class DocumentElement
        Returns:
        get this element as a BigDecimal if it is single element array.
        Throws:
        java.lang.ClassCastException - if the element in the array is of not a DocumentPrimitive.
        java.lang.NumberFormatException - if the element at index 0 is not a valid BigDecimal.
        java.lang.IllegalStateException - if the array has more than one element.
      • getAsBigInteger

        public java.math.BigInteger getAsBigInteger()
        convenience method to get this array as a BigInteger if it contains a single element.
        Overrides:
        getAsBigInteger in class DocumentElement
        Returns:
        get this element as a BigInteger if it is single element array.
        Throws:
        java.lang.ClassCastException - if the element in the array is of not a DocumentPrimitive.
        java.lang.NumberFormatException - if the element at index 0 is not a valid BigInteger.
        java.lang.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 class DocumentElement
        Returns:
        get this element as a float if it is single element array.
        Throws:
        java.lang.ClassCastException - if the element in the array is of not a DocumentPrimitive and is not a valid float.
        java.lang.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 class DocumentElement
        Returns:
        get this element as a long if it is single element array.
        Throws:
        java.lang.ClassCastException - if the element in the array is of not a DocumentPrimitive and is not a valid long.
        java.lang.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 class DocumentElement
        Returns:
        get this element as an integer if it is single element array.
        Throws:
        java.lang.ClassCastException - if the element in the array is of not a DocumentPrimitive and is not a valid integer.
        java.lang.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 class DocumentElement
        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 class DocumentElement
        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 class DocumentElement
        Returns:
        get this element as a primitive short if it is single element array.
        Throws:
        java.lang.ClassCastException - if the element in the array is of not a DocumentPrimitive and is not a valid short.
        java.lang.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 class DocumentElement
        Returns:
        get this element as a boolean if it is single element array.
        Throws:
        java.lang.ClassCastException - if the element in the array is of not a DocumentPrimitive and is not a valid boolean.
        java.lang.IllegalStateException - if the array has more than one element.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object