Package jsonvalues

Interface JsObj

    • Method Detail

      • _empty_

        static JsObj _empty_()
        Returns a mutable empty object.
        Returns:
        a mutable empty JsObj
      • _of_

        static JsObj _of_​(String key,
                          JsElem el)
        Returns a mutable one-pair object.
        Parameters:
        key - name of the key
        el - JsElem to be associated to the key
        Returns:
        a mutable one-pair JsObj
        Throws:
        UserError - if the elem is an immutable Json
      • _of_

        static JsObj _of_​(String key1,
                          JsElem el1,
                          String key2,
                          JsElem el2)
        Returns a mutable two-pair object.
        Parameters:
        key1 - name of a key
        el1 - JsElem to be associated to the key1
        key2 - name of a key
        el2 - JsElem to be associated to the key2
        Returns:
        a two-pair mutable JsObj
        Throws:
        UserError - if an elem is an immutable Json
      • _of_

        static JsObj _of_​(String key1,
                          JsElem el1,
                          String key2,
                          JsElem el2,
                          String key3,
                          JsElem el3)
        Returns a mutable three-pair object.
        Parameters:
        key1 - name of a key
        el1 - JsElem to be associated to the key1
        key2 - name of a key
        el2 - JsElem to be associated to the key2
        key3 - name of a key
        el3 - JsElem to be associated to the key3
        Returns:
        a three-pair mutable JsObj
        Throws:
        UserError - if an elem is an immutable Json
      • _of_

        static JsObj _of_​(String key1,
                          JsElem el1,
                          String key2,
                          JsElem el2,
                          String key3,
                          JsElem el3,
                          String key4,
                          JsElem el4)
        Returns a mutable four-pair object.
        Parameters:
        key1 - name of a key
        el1 - JsElem to be associated to the key1
        key2 - name of a key
        el2 - JsElem to be associated to the key2
        key3 - name of a key
        el3 - JsElem to be associated to the key3
        key4 - name of a key
        el4 - JsElem to be associated to the key4
        Returns:
        a mutable four-pair JsObj
        Throws:
        UserError - if an elem is an immutable Json
      • _of_

        static JsObj _of_​(String key1,
                          JsElem el1,
                          String key2,
                          JsElem el2,
                          String key3,
                          JsElem el3,
                          String key4,
                          JsElem el4,
                          String key5,
                          JsElem el5)
        Returns a mutable five-pair object.
        Parameters:
        key1 - name parse a key
        el1 - JsElem to be associated to the key1
        key2 - name parse a key
        el2 - JsElem to be associated to the key2
        key3 - name parse a key
        el3 - JsElem to be associated to the key3
        key4 - name parse a key
        el4 - JsElem to be associated to the key4
        key5 - name parse a key
        el5 - JsElem to be associated to the key5
        Returns:
        a mutable five-element JsObj
        Throws:
        UserError - if an elem is an immutable Json
      • _of_

        static JsObj _of_​(String key1,
                          JsElem el1,
                          String key2,
                          JsElem el2,
                          String key3,
                          JsElem el3,
                          String key4,
                          JsElem el4,
                          String key5,
                          JsElem el5,
                          String key6,
                          JsElem el6)
        Returns a mutable six-pair object.
        Parameters:
        key1 - name parse a key
        el1 - JsElem to be associated to the key1
        key2 - name parse a key
        el2 - JsElem to be associated to the key2
        key3 - name parse a key
        el3 - JsElem to be associated to the key3
        key4 - name parse a key
        el4 - JsElem to be associated to the key4
        key5 - name parse a key
        el5 - JsElem to be associated to the key5
        key6 - name parse a key
        el6 - JsElem to be associated to the key6
        Returns:
        a mutable six-element JsObj
        Throws:
        UserError - if an elem is an immutable Json
      • _of_

        static JsObj _of_​(Map<String,​JsElem> map)
        Returns a mutable object from a map of elements.
        Parameters:
        map - the map of JsElem
        Returns:
        a mutable JsObj
        Throws:
        UserError - if an elem of the map is an immutable Json
      • _parse_

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

        default boolean equals​(JsObj that,
                               JsArray.TYPE ARRAY_AS)
        return true if this obj is equal to the given as a parameter. In the case of ARRAY_AS=LIST, this method is equivalent to JsObj.equals(Object).
        Parameters:
        that - the given array
        ARRAY_AS - enum to specify if arrays are considered as lists or sets or multisets
        Returns:
        true if both objs are equals
      • _parse_

        static TryObj _parse_​(String str,
                              ParseBuilder builder)
        Tries to parse the string into an mutable object, performing the specified transformations while 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
        builder - builder with the transformations that will be applied during the parsing
        Returns:
        a TryObj computation
      • collector

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

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

        static JsObj empty()
        Returns the immutable empty object. The same instance is always returned.
        Returns:
        the singleton immutable empty JsObj
      • fields

        Set<String> fields()
        Returns a set containing each key fo this object.
        Returns:
        a Set containing each key of this JsObj
      • head

        Map.Entry<String,​JsElem> head()
        Returns a pair with an arbitrary key of this object and its associated element. When using head and tail to process a JsObj, the key of the pair returned must be passed in to get the tail using the method tail(String).
        Returns:
        an arbitrary Map.Entry<String,JsElem> of this JsObj
        Throws:
        UserError - if this json object is empty
      • of

        static JsObj of​(String key,
                        JsElem el)
        Returns an immutable one-element object.
        Parameters:
        key - name of the key
        el - JsElem to be associated to the key
        Returns:
        an immutable one-element JsObj
        Throws:
        UserError - if the elem is a mutable Json
      • of

        static JsObj of​(String key1,
                        JsElem el1,
                        String key2,
                        JsElem el2)
        Returns a two-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsElem to be associated to the key1
        key2 - name of a key
        el2 - JsElem to be associated to the key2
        Returns:
        an immutable two-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        static JsObj of​(String key1,
                        JsElem el1,
                        String key2,
                        JsElem el2,
                        String key3,
                        JsElem el3)
        Returns a three-element immutable json object.
        Parameters:
        key1 - name of a key
        el1 - JsElem to be associated to the key1
        key2 - name of a key
        el2 - JsElem to be associated to the key2
        key3 - name of a key
        el3 - JsElem to be associated to the key3
        Returns:
        an immutable three-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        static JsObj of​(String key1,
                        JsElem el1,
                        String key2,
                        JsElem el2,
                        String key3,
                        JsElem el3,
                        String key4,
                        JsElem el4)
        Returns a four-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsElem to be associated to the key1
        key2 - name of a key
        el2 - JsElem to be associated to the key2
        key3 - name of a key
        el3 - JsElem to be associated to the key3
        key4 - name of a key
        el4 - JsElem to be associated to the key4
        Returns:
        an immutable four-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        static JsObj of​(String key1,
                        JsElem el1,
                        String key2,
                        JsElem el2,
                        String key3,
                        JsElem el3,
                        String key4,
                        JsElem el4,
                        String key5,
                        JsElem el5)
        Returns a five-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsElem to be associated to the key1
        key2 - name of a key
        el2 - JsElem to be associated to the key2
        key3 - name of a key
        el3 - JsElem to be associated to the key3
        key4 - name of a key
        el4 - JsElem to be associated to the key4
        key5 - name of a key
        el5 - JsElem to be associated to the key5
        Returns:
        an immutable five-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        static JsObj of​(String key1,
                        JsElem el1,
                        String key2,
                        JsElem el2,
                        String key3,
                        JsElem el3,
                        String key4,
                        JsElem el4,
                        String key5,
                        JsElem el5,
                        String key6,
                        JsElem el6)
        Returns a six-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsElem to be associated to the key1
        key2 - name of a key
        el2 - JsElem to be associated to the key2
        key3 - name of a key
        el3 - JsElem to be associated to the key3
        key4 - name of a key
        el4 - JsElem to be associated to the key4
        key5 - name of a key
        el5 - JsElem to be associated to the key5
        key6 - name of a key
        el6 - JsElem to be associated to the key6
        Returns:
        an immutable six-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        static JsObj of​(Map<String,​JsElem> map)
        Returns a immutable object from a map of elements.
        Parameters:
        map - the map of JsElem
        Returns:
        an immutable JsObj
        Throws:
        UserError - if an elem of the map is a mutable Json
      • parse

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

        static TryObj parse​(String str,
                            ParseBuilder builder)
        Tries to parse the string into an immutable object, performing the specified transformations 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
        builder - builder with the transformations that will be applied during the parsing
        Returns:
        a TryObj computation
      • tail

        JsObj tail​(String key)
        Returns a new object with all the entries of this json object except the one with the given key.
        Parameters:
        key - the given key, which associated pair will be excluded
        Returns:
        a new JsObj
        Throws:
        UserError - if this json object is empty
      • intersection

        JsObj intersection​(JsObj that,
                           JsArray.TYPE ARRAY_AS)
        this.intersection(that, SET) returns an array with the elements that exist in both this and that this.intersection(that, MULTISET) returns an array with the elements that exist in both this and that, being duplicates allowed. this.intersection(that, LIST) returns an array with the elements that exist in both this and that, and are located at the same position.
        Parameters:
        that - the other obj
        ARRAY_AS - option to define if arrays are considered SETS, LISTS OR MULTISET
        Returns:
        a new JsObj of the same type as the inputs (mutable or immutable)
      • intersection_

        JsObj intersection_​(JsObj that,
                            JsArray.TYPE ARRAY_AS)
        this.intersection_(that) behaves as this.intersection(that, LIST), but for those elements that are containers of the same type and are located at the same position, the result is their intersection. So this operation is kind of a 'recursive' intersection.
        Parameters:
        that - the other object
        ARRAY_AS - option to define if arrays are considered SETS, LISTS OR MULTISET
        Returns:
        a new JsObj of the same type as the inputs (mutable or immutable)
      • union

        JsObj union​(JsObj that)
        returns this json object plus those pairs from the given json object that which keys don't exist in this. Taking that into account, it's not a commutative operation unless the elements associated with the keys that exist in both json objects are equals.
        Parameters:
        that - the given json object
        Returns:
        a new JsObj of the same type as the inputs (mutable or immutable)
      • union_

        JsObj union_​(JsObj that,
                     JsArray.TYPE ARRAY_AS)
        behaves like the union(JsObj) but, for those keys that exit in both this and that json objects, which associated elements are **containers of the same type**, the result is their union. In this case, we can specify if arrays are considered Sets, Lists, or MultiSets. So this operation is kind of a 'recursive' union.
        Parameters:
        that - the given json object
        ARRAY_AS - option to define if arrays are considered SETS, LISTS OR MULTISET
        Returns:
        a new JsObj of the same type as the inputs (mutable or immutable)
      • of

        static JsObj of​(JsPair pair,
                        JsPair... others)
        Returns an immutable object from one or more pairs.
        Parameters:
        pair - a pair
        others - more optional pairs
        Returns:
        an immutable JsObject
        Throws:
        UserError - if an elem of a pair is mutable
      • _of_

        static JsObj _of_​(JsPair pair,
                          JsPair... others)
        Returns a mutable object from one or more pairs.
        Parameters:
        pair - a pair
        others - more optional pairs
        Returns:
        a mutable JsObject
        Throws:
        UserError - 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
      • patch

        default TryPatch<JsObj> patch​(JsArray ops)
        Description copied from interface: Json
        Implementation of the Json Patch specification. Go to https://tools.ietf.org/html/rfc6902 for further details.
        Specified by:
        patch in interface Json<JsObj>
        Parameters:
        ops - operations to be applied to the json
        Returns:
        a TryPatch computation