Package jsonvalues

Interface JsArray

  • All Superinterfaces:
    Iterable<JsElem>, JsElem, Json<JsArray>, Serializable

    public interface JsArray
    extends Json<JsArray>, Iterable<JsElem>
    Represents a json array, which is an ordered list of elements. Two implementations are provided, an immutable which uses the persistent Scala Vector and a mutable which uses the conventional Java ArrayList.
    • Method Detail

      • _empty_

        static JsArray _empty_()
        Returns a mutable empty array.
        Returns:
        mutable empty JsArray
      • _of_

        static JsArray _of_​(List<JsElem> list)
        Returns a mutable array copying the reference of the collection of elements. Since the reference is copied, changes in the array are reflected in the list and vice versa. If the collection is immutable (created using List.of or Arrays.asList factory methods for example), every modification in the array will throw an UnsupportedOperationException.
        Parameters:
        list - the Collection of JsElem from which reference the JsArray will be created
        Returns:
        a mutable JsArray
        Throws:
        UnsupportedOperationException - if an elem of the list is an immutable Json
      • _of_

        static JsArray _of_​(JsElem e)
        Returns a mutable one-element array.
        Parameters:
        e - the JsElem
        Returns:
        a mutable one-element JsArray
        Throws:
        UnsupportedOperationException - if the elem is an immutable Json
      • _of_

        static JsArray _of_​(JsElem e,
                            JsElem e1)
        Returns a mutable two-element array.
        Parameters:
        e - a JsElem
        e1 - a JsElem
        Returns:
        a mutable two-element JsArray
        Throws:
        UnsupportedOperationException - if an elem is an immutable Json
      • _of_

        static JsArray _of_​(JsElem e,
                            JsElem e1,
                            JsElem e2)
        Returns a mutable three-element array.
        Parameters:
        e - a JsElem
        e1 - a JsElem
        e2 - a JsElem
        Returns:
        a mutable three-element JsArray
        Throws:
        UnsupportedOperationException - if an elem is an immutable Json
      • _of_

        static JsArray _of_​(JsElem e,
                            JsElem e1,
                            JsElem e2,
                            JsElem e3,
                            JsElem e4,
                            JsElem... rest)
        Returns a mutable array containing an arbitrary number of elements.
        Parameters:
        e - a JsElem
        e1 - a JsElem
        e2 - a JsElem
        e3 - a JsElem
        e4 - a JsElem
        rest - more optional JsElem
        Returns:
        a mutable JsArray
        Throws:
        UnsupportedOperationException - if an elem is an immutable Json
      • _parse_

        static TryArr _parse_​(String str)
        Tries to parse the string into a mutable json array.
        Parameters:
        str - the string to be parsed
        Returns:
        a TryArr computation
      • equals

        default boolean equals​(JsArray array,
                               JsArray.TYPE ARRAY_AS)
        Returns true if this array is equal to the given as a parameter. In the case of ARRAY_AS=LIST, this method is equivalent to JsArray.equals(Object).
        Parameters:
        array - the given array
        ARRAY_AS - option to define if arrays are considered SETS, LISTS OR MULTISET
        Returns:
        true if both arrays are equals according to ARRAY_AS parameter
      • _parse_

        static TryArr _parse_​(String str,
                              ParseOptions options)
        Tries to parse the string into a mutable array, performing some operations while the parsing. It's faster to do certain operations right while the parsing instead of doing the parsing and apply them later.
        Parameters:
        str - the string that will be parsed.
        options - a builder with the filters and maps that, if specified, will be applied during the parsing
        Returns:
        a TryArr computation
      • appendAll

        JsArray appendAll​(JsArray array)
        Adds all the elements of the given array, starting from the head, to the back of this array.
        Parameters:
        array - the JsArray of elements to be added to the back
        Returns:
        a new JsArray
      • prependAll

        JsArray prependAll​(JsArray array)
        Adds all the elements of the array, starting from the last, to the front of this array.
        Parameters:
        array - the JsArray of elements to be added to the front
        Returns:
        a new JsArray
      • append

        JsArray append​(JsElem elem,
                       JsElem... others)
        Adds one or more elements, starting from the first, to the back of this array.
        Parameters:
        elem - the JsElem to be added to the back.
        others - more optional JsElem to be added to the back
        Returns:
        a new JsArray
      • prepend

        JsArray prepend​(JsElem elem,
                        JsElem... others)
        Adds one or more elements, starting from the last, to the front of this array.
        Parameters:
        elem - the JsElem to be added to the front.
        others - more optional JsElem to be added to the front
        Returns:
        a new JsArray
      • collector

        static Collector<JsPair,​JsArray,​JsArray> collector()
        Returns a collector that accumulates the pairs from a stream into an immutable array.
        Returns:
        a Collector which collects all the pairs of elements into an immutable JsArray, in encounter order
      • _collector_

        static Collector<JsPair,​JsArray,​JsArray> _collector_()
        Returns a collector that accumulates the pairs from a stream into a mutable array.
        Returns:
        a Collector which collects all the pairs of elements into a mutable JsArray, in encounter order
      • empty

        static JsArray empty()
        Returns the immutable empty array. The same instance is always returned.
        Returns:
        the singleton immutable empty JsArray.
      • init

        JsArray init()
        Returns all the elements of this array except the last one.
        Returns:
        JsArray with all the JsElem except the last one
        Throws:
        UnsupportedOperationException - if this JsArray is empty
      • of

        static JsArray of​(Collection<? extends JsElem> list)
        Returns an immutable array from the collection of elements.
        Parameters:
        list - the Collection of JsElem from which the JsArray will be created
        Returns:
        an immutable JsArray
        Throws:
        UnsupportedOperationException - if an elem of the list is a mutable Json
      • of

        static JsArray of​(JsElem e,
                          JsElem e1)
        Returns an immutable two-element array.
        Parameters:
        e - a JsElem
        e1 - a JsElem
        Returns:
        an immutable two-element JsArray
        Throws:
        UnsupportedOperationException - if an elem is a mutable Json
      • of

        static JsArray of​(JsElem e,
                          JsElem e1,
                          JsElem e2)
        Returns an immutable three-element array.
        Parameters:
        e - a JsElem
        e1 - a JsElem
        e2 - a JsElem
        Returns:
        an immutable three-element JsArray
        Throws:
        UnsupportedOperationException - if an elem is a mutable Json
      • parse

        static TryArr parse​(String str)
        Tries to parse the string into an immutable array.
        Parameters:
        str - the string to be parsed
        Returns:
        a TryArr computation
      • parse

        static TryArr parse​(String str,
                            ParseOptions options)
        Tries to parse the string into an immutable array, performing some operations during the parsing. It's faster to do certain operations right while the parsing instead of doing the parsing and applying them later.
        Parameters:
        str - string to be parsed
        options - a Options with the filters and maps that will be applied during the parsing
        Returns:
        a TryArr computation
      • of

        static JsArray of​(String str,
                          String... others)
        Returns an immutable array from one or more strings.
        Parameters:
        str - a string
        others - more optional strings
        Returns:
        an immutable JsArray
      • _of_

        static JsArray _of_​(String str,
                            String... others)
        Returns a mutable array from one or more strings.
        Parameters:
        str - a string
        others - more optional strings
        Returns:
        a mutable JsArray
      • of

        static JsArray of​(int number,
                          int... others)
        Returns an immutable array from one or more integers.
        Parameters:
        number - an integer
        others - more optional integers
        Returns:
        an immutable JsArray
      • _of_

        static JsArray _of_​(int number,
                            int... others)
        Returns a mutable array from one or more integers
        Parameters:
        number - an integer
        others - more optional integers
        Returns:
        an mutable JsArray
      • of

        static JsArray of​(long number,
                          long... others)
        Returns an immutable array from one or more longs.
        Parameters:
        number - a long
        others - more optional longs
        Returns:
        an immutable JsArray
      • of

        static JsArray of​(boolean bool,
                          boolean... others)
        Returns an immutable array from one or more booleans.
        Parameters:
        bool - a boolean
        others - more optional booleans
        Returns:
        an immutable JsArray
      • of

        static JsArray of​(double number,
                          double... others)
        Returns an immutable array from one or more doubles.
        Parameters:
        number - a double
        others - more optional doubles
        Returns:
        an immutable JsArray
      • _of_

        static JsArray _of_​(long number,
                            long... others)
        Returns a mutable array from one or more longs.
        Parameters:
        number - a long
        others - more optional longs
        Returns:
        a mutable JsArray
      • _of_

        static JsArray _of_​(boolean bool,
                            boolean... others)
        Returns a mutable array from one or more booleans.
        Parameters:
        bool - a boolean
        others - more optional booleans
        Returns:
        a mutable JsArray
      • _of_

        static JsArray _of_​(double number,
                            double... others)
        Returns a mutable array from one or more doubles.
        Parameters:
        number - a double
        others - more optional doubles
        Returns:
        a mutable JsArray
      • tail

        JsArray tail()
        Returns a json array consisting of all elements of this array except the first one.
        Returns:
        a JsArray consisting of all the elements of this JsArray except the head
        Throws:
        UnsupportedOperationException - if this JsArray is empty.
      • intersection

        JsArray intersection​(JsArray that,
                             JsArray.TYPE ARRAY_AS)
        Returns the intersection of this array and another given as a parameter, defining characteristics like order and duplicates occurrence with the given ARRAY_AS parameter.
        Parameters:
        that - the other array
        ARRAY_AS - option to define if arrays are considered SETS, LISTS OR MULTISET
        Returns:
        a new JsArray of the same type as the inputs (mutable or immutable)
      • intersection_

        JsArray intersection_​(JsArray that)
        Returns the intersection of this array and another given as parameter considering both JsArray.TYPE.LISTlists and applying recursively the intersection to those elements which are Json of the same type and are located at the same position.
        Parameters:
        that - the other array
        Returns:
        a JsArray of the same type as the inputs (mutable or immutable)
      • union

        JsArray union​(JsArray that,
                      JsArray.TYPE ARRAY_AS)
        Returns the union of this array and another, defining characteristics like order and duplicates occurrence with the given ARRAY_AS parameter.
        Parameters:
        that - the other array
        ARRAY_AS - option to define if arrays are considered SETS, LISTS OR MULTISET
        Returns:
        a new json array of the same type as the inputs (mutable or immutable)
      • union_

        JsArray union_​(JsArray that)
        Returns the union of this array and another given as parameter considering both JsArray.TYPE.LISTlists and applying recursively the union to those elements which are Json of the same type and are located at the same position.
        Parameters:
        that - the other array
        Returns:
        a new JsArray of the same type as the inputs (mutable or immutable)
      • of

        static JsArray of​(JsPair pair,
                          JsPair... pairs)
        Returns an immutable array from one or more pairs.
        Parameters:
        pair - a pair
        pairs - more optional pairs
        Returns:
        an immutable JsArray
        Throws:
        UnsupportedOperationException - if an elem of a pair is mutable
      • _of_

        static JsArray _of_​(JsPair pair,
                            JsPair... pairs)
        Returns a mutable array from one or more pairs.
        Parameters:
        pair - a pair
        pairs - more optional pairs
        Returns:
        a mutable JsArray
        Throws:
        UnsupportedOperationException - if an elem of a pair is immutable
      • isObj

        default boolean isObj()
        Specified by:
        isObj in interface JsElem
        Returns:
        true if this JsElem is a JsObj
      • isArray

        default boolean isArray()
        Specified by:
        isArray in interface JsElem
        Returns:
        true if this JsElem is a JsArray