Package jsonvalues

Class JsObj

  • All Implemented Interfaces:
    java.lang.Iterable<io.vavr.Tuple2<java.lang.String,​JsValue>>, Json<JsObj>, JsValue

    public final class JsObj
    extends java.lang.Object
    implements Json<JsObj>, java.lang.Iterable<io.vavr.Tuple2<java.lang.String,​JsValue>>
    Represents a json object, which is an unordered set of name/element pairs. Two implementations are provided, an immutable which uses the persistent Scala HashMap, and a mutable which uses the conventional Java HashMap.
    • Constructor Summary

      Constructors 
      Constructor Description
      JsObj()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsKey​(java.lang.String key)
      return true if the key is present
      boolean containsValue​(JsValue el)
      Returns true if this json contains the given element in the first level.
      JsObj delete​(java.lang.String key)  
      JsObj delete​(JsPath path)
      Removes the element in this json located at the given path, if it exists, returning the same this instance otherwise
      static JsObj empty()  
      boolean equals​(java.lang.Object that)  
      boolean equals​(JsObj that, JsArray.TYPE ARRAY_AS)
      return true if this obj is equal to the given as a parameter.
      JsObj filterAllKeys​(java.util.function.BiPredicate<? super JsPath,​? super JsValue> filter)
      Filters all the keys of this json, removing those that don't ifPredicateElse the predicate.
      JsObj filterAllKeys​(java.util.function.Predicate<? super java.lang.String> filter)
      Filters all the keys of this json, removing those that don't ifPredicateElse the predicate.
      JsObj filterAllObjs​(java.util.function.BiPredicate<? super JsPath,​? super JsObj> filter)
      Filters all the pair of jsons of this json, removing those that don't ifPredicateElse the predicate.
      JsObj filterAllObjs​(java.util.function.Predicate<? super JsObj> filter)
      Filters all the pair of jsons of this json, removing those that don't ifPredicateElse the predicate.
      JsObj filterAllValues​(java.util.function.BiPredicate<? super JsPath,​? super JsPrimitive> filter)
      Filters all the pairs of elements of this json, removing those that don't ifPredicateElse the predicate.
      JsObj filterAllValues​(java.util.function.Predicate<? super JsPrimitive> filter)
      Filters all the pairs of elements of this json, removing those that don't ifPredicateElse the predicate.
      JsObj filterKeys​(java.util.function.BiPredicate<? super java.lang.String,​? super JsValue> filter)  
      JsObj filterKeys​(java.util.function.Predicate<? super java.lang.String> filter)
      Filters the keys in the first level of this json, removing those that don't ifPredicateElse the predicate.
      JsObj filterObjs​(java.util.function.BiPredicate<? super java.lang.String,​? super JsObj> filter)  
      JsObj filterObjs​(java.util.function.Predicate<? super JsObj> filter)
      Filters the pair of jsons in the first level of this json, removing those that don't ifPredicateElse the predicate.
      JsObj filterValues​(java.util.function.BiPredicate<? super java.lang.String,​? super JsPrimitive> filter)  
      JsObj filterValues​(java.util.function.Predicate<? super JsPrimitive> filter)
      Filters the pairs of elements in the first level of this json, removing those that don't ifPredicateElse the predicate.
      JsValue get​(java.lang.String key)  
      JsValue get​(JsPath path)
      Returns the element located at the given path or JsNothing if it doesn't exist.
      JsArray getArray​(java.lang.String key)
      Returns the array located at the given key or null if it doesn't exist or it's not an array.
      JsArray getArray​(java.lang.String key, java.util.function.Supplier<JsArray> orElse)
      Returns the array located at the given key or the default value provided if it doesn't exist or it's not an array.
      java.math.BigDecimal getBigDec​(java.lang.String key)
      Returns the number located at the given key as a big decimal or null if it doesn't exist or it's not a decimal number.
      java.math.BigDecimal getBigDec​(java.lang.String key, java.util.function.Supplier<java.math.BigDecimal> orElse)
      Returns the number located at the given key as a big decimal or the default value provided if it doesn't exist or it's not a decimal number.
      java.math.BigInteger getBigInt​(java.lang.String key)
      Returns the big integer located at the given key as a big integer or null if it doesn't exist or it's not an integral number.
      java.math.BigInteger getBigInt​(java.lang.String key, java.util.function.Supplier<java.math.BigInteger> orElse)
      Returns the big integer located at the given key as a big integer or the default value provided if it doesn't exist or it's not an integral number.
      byte[] getBinary​(java.lang.String key)
      Returns the bytes located at the given key or null if it doesn't exist or it's not an array of bytes.
      byte[] getBinary​(java.lang.String key, java.util.function.Supplier<byte[]> orElse)
      Returns the bytes located at the given key or the default value provided if it doesn't exist or it's not an array of bytes.
      java.lang.Boolean getBool​(java.lang.String key)
      Returns the boolean located at the given key or null if it doesn't exist.
      java.lang.Boolean getBool​(java.lang.String key, java.util.function.Supplier<java.lang.Boolean> orElse)
      Returns the boolean located at the given key or the default value provided if it doesn't exist.
      java.lang.Double getDouble​(java.lang.String key)
      Returns the number located at the given key as a double or null if it doesn't exist or it's not a decimal number.
      java.lang.Double getDouble​(java.lang.String key, java.util.function.Supplier<java.lang.Double> orElse)
      Returns the number located at the given key as a double or the default value provided if it doesn't exist or it's not a decimal number.
      java.time.Instant getInstant​(java.lang.String key)
      Returns the instant located at the given key or null if it doesn't exist or it's not an instant.
      java.time.Instant getInstant​(java.lang.String key, java.util.function.Supplier<java.time.Instant> orElse)
      Returns the instant located at the given key or the default value provided if it doesn't exist or it's not an instant.
      java.lang.Integer getInt​(java.lang.String key)
      Returns the integral number located at the given key as an integer or null if it doesn't exist or it's not an integral number or it's an integral number but doesn't fit in an integer.
      java.lang.Integer getInt​(java.lang.String key, java.util.function.Supplier<java.lang.Integer> orElse)
      Returns the integral number located at the given key as an integer or the default value provided if it doesn't exist or it's not an integral number or it's an integral number but doesn't fit in an integer.
      java.lang.Long getLong​(java.lang.String key)
      Returns the integral number located at the given key as a long or null if it doesn't exist or it's not an integral number or it's an integral number but doesn't fit in a long.
      java.lang.Long getLong​(java.lang.String key, java.util.function.Supplier<java.lang.Long> orElse)
      Returns the integral number located at the given key as a long or the default value provided if it doesn't exist or it's not an integral number or it's an integral number but doesn't fit in a long.
      JsObj getObj​(java.lang.String key)
      Returns the json object located at the given key or null if it doesn't exist or it's not an object.
      JsObj getObj​(java.lang.String key, java.util.function.Supplier<JsObj> orElse)
      Returns the json object located at the given key or the default value provided if it doesn't exist or it's not an object.
      java.lang.String getStr​(java.lang.String key)
      Returns the string located at the given key or null if it doesn't exist or it's not an string.
      java.lang.String getStr​(java.lang.String key, java.util.function.Supplier<java.lang.String> orElse)
      Returns the string located at the given key or the default value provided if it doesn't exist or it's not an string.
      int hashCode()
      equals method is inherited, so it's implemented.
      io.vavr.Tuple2<java.lang.String,​JsValue> head()
      Returns a pair with an arbitrary key of this object and its associated element.
      int id()  
      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.
      JsObj intersectionAll​(JsObj that, JsArray.TYPE ARRAY_AS)
      this.intersectionAll(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.
      boolean isEmpty()
      return true if there's no element in this json
      boolean isObj()
      Returns true if this JsValue is a JsObj
      java.util.Iterator<io.vavr.Tuple2<java.lang.String,​JsValue>> iterator()  
      java.util.Set<java.lang.String> keySet()
      Returns a set containing each key fo this object.
      JsObj mapAllKeys​(java.util.function.BiFunction<? super JsPath,​? super JsValue,​java.lang.String> fn)
      Maps all the keys of this json.
      JsObj mapAllKeys​(java.util.function.Function<? super java.lang.String,​java.lang.String> fn)
      Maps all the keys of this json.
      JsObj mapAllObjs​(java.util.function.BiFunction<? super JsPath,​? super JsObj,​JsValue> fn)
      Maps all the jsons of this json.
      JsObj mapAllObjs​(java.util.function.Function<? super JsObj,​JsValue> fn)
      Maps all the jsons of this json.
      JsObj mapAllValues​(java.util.function.BiFunction<? super JsPath,​? super JsPrimitive,​? extends JsValue> fn)
      Maps all the values of this json.
      JsObj mapAllValues​(java.util.function.Function<? super JsPrimitive,​? extends JsValue> fn)
      Maps all the values of this json.
      JsObj mapKeys​(java.util.function.BiFunction<? super java.lang.String,​? super JsValue,​java.lang.String> fn)  
      JsObj mapKeys​(java.util.function.Function<? super java.lang.String,​java.lang.String> fn)
      Maps the keys in the first level of this json.
      JsObj mapObjs​(java.util.function.BiFunction<? super java.lang.String,​? super JsObj,​JsValue> fn)  
      JsObj mapObjs​(java.util.function.Function<? super JsObj,​JsValue> fn)
      Maps the jsons in the first level of this json.
      JsObj mapValues​(java.util.function.BiFunction<? super java.lang.String,​? super JsPrimitive,​? extends JsValue> fn)  
      JsObj mapValues​(java.util.function.Function<? super JsPrimitive,​? extends JsValue> fn)
      Maps the values in the first level of this json.
      static JsObj of​(java.lang.String key, JsValue el)
      Returns a one-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2)
      Returns a two-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3)
      Returns a three-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4)
      Returns a four-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5)
      Returns a five-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5, java.lang.String key6, JsValue el6)
      Returns a six-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5, java.lang.String key6, JsValue el6, java.lang.String key7, JsValue el7)
      Returns a six-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5, java.lang.String key6, JsValue el6, java.lang.String key7, JsValue el7, java.lang.String key8, JsValue el8)
      Returns a six-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5, java.lang.String key6, JsValue el6, java.lang.String key7, JsValue el7, java.lang.String key8, JsValue el8, java.lang.String key9, JsValue el9)
      Returns a six-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5, java.lang.String key6, JsValue el6, java.lang.String key7, JsValue el7, java.lang.String key8, JsValue el8, java.lang.String key9, JsValue el9, java.lang.String key10, JsValue el10)
      Returns a six-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5, java.lang.String key6, JsValue el6, java.lang.String key7, JsValue el7, java.lang.String key8, JsValue el8, java.lang.String key9, JsValue el9, java.lang.String key10, JsValue el10, java.lang.String key11, JsValue el11)
      Returns a six-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5, java.lang.String key6, JsValue el6, java.lang.String key7, JsValue el7, java.lang.String key8, JsValue el8, java.lang.String key9, JsValue el9, java.lang.String key10, JsValue el10, java.lang.String key11, JsValue el11, java.lang.String key12, JsValue el12)
      Returns a six-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5, java.lang.String key6, JsValue el6, java.lang.String key7, JsValue el7, java.lang.String key8, JsValue el8, java.lang.String key9, JsValue el9, java.lang.String key10, JsValue el10, java.lang.String key11, JsValue el11, java.lang.String key12, JsValue el12, java.lang.String key13, JsValue el13)
      Returns a six-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5, java.lang.String key6, JsValue el6, java.lang.String key7, JsValue el7, java.lang.String key8, JsValue el8, java.lang.String key9, JsValue el9, java.lang.String key10, JsValue el10, java.lang.String key11, JsValue el11, java.lang.String key12, JsValue el12, java.lang.String key13, JsValue el13, java.lang.String key14, JsValue el14)
      Returns a six-element immutable object.
      static JsObj of​(java.lang.String key1, JsValue el1, java.lang.String key2, JsValue el2, java.lang.String key3, JsValue el3, java.lang.String key4, JsValue el4, java.lang.String key5, JsValue el5, java.lang.String key6, JsValue el6, java.lang.String key7, JsValue el7, java.lang.String key8, JsValue el8, java.lang.String key9, JsValue el9, java.lang.String key10, JsValue el10, java.lang.String key11, JsValue el11, java.lang.String key12, JsValue el12, java.lang.String key13, JsValue el13, java.lang.String key14, JsValue el14, java.lang.String key15, JsValue el15)
      Returns a six-element immutable object.
      static JsObj of​(JsPair pair, JsPair... others)
      Returns an immutable object from one or more pairs.
      static JsObj ofIterable​(java.lang.Iterable<java.util.Map.Entry<java.lang.String,​JsValue>> xs)  
      static JsObj parse​(java.lang.String str)
      Tries to parse the string into an immutable object.
      static JsObj parseYaml​(java.lang.String str)
      Tries to parse a YAML string into an immutable object.
      <R> java.util.Optional<R> reduce​(java.util.function.BinaryOperator<R> op, java.util.function.BiFunction<? super java.lang.String,​? super JsPrimitive,​R> map, java.util.function.BiPredicate<? super java.lang.String,​? super JsPrimitive> predicate)
      Performs a reduction on the values that satisfy the predicate in the first level of this json.
      <R> java.util.Optional<R> reduce​(java.util.function.BinaryOperator<R> op, java.util.function.Function<? super JsPrimitive,​R> map, java.util.function.Predicate<? super JsPrimitive> predicate)
      Performs a reduction on the values that satisfy the predicate in the first level of this json.
      <R> java.util.Optional<R> reduceAll​(java.util.function.BinaryOperator<R> op, java.util.function.BiFunction<? super JsPath,​? super JsPrimitive,​R> map, java.util.function.BiPredicate<? super JsPath,​? super JsPrimitive> predicate)
      Performs a reduction on the values of this json that satisfy the predicate.
      <R> java.util.Optional<R> reduceAll​(java.util.function.BinaryOperator<R> op, java.util.function.Function<? super JsPrimitive,​R> map, java.util.function.Predicate<? super JsPrimitive> predicate)
      Performs a reduction on the values of this json that satisfy the predicate.
      JsObj set​(java.lang.String key, JsValue value)
      Inserts the element at the key in this json, replacing any existing element.
      JsObj set​(JsPath path, JsValue element)
      Inserts the element at the path in this json, replacing any existing element and filling with JsNull empty indexes in arrays when necessary.
      JsObj set​(JsPath path, JsValue value, JsValue padElement)
      Inserts the element at the path in this json, replacing any existing element and filling with padElement empty indexes in arrays when necessary.
      int size()
      Returns the number of elements in the first level of this json
      java.util.stream.Stream<JsPair> stream()
      Returns a stream over the pairs of elements in the first level of this json object.
      java.util.stream.Stream<JsPair> streamAll()
      Returns a stream over all the pairs of elements in this json object.
      java.util.stream.Stream<JsValue> streamValues()  
      JsObj tail()
      Returns a new object with all the entries of this json object except the one with the given key.
      java.lang.String toString()
      // Single-check idiom Item 83 from effective java
      JsObj union​(JsObj that)
      returns this json object plus those pairs from the given json object that which keys don't exist in this.
      JsObj unionAll​(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.
      • 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

      • JsObj

        public JsObj()
    • Method Detail

      • empty

        public static JsObj empty()
      • of

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

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

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

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

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

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

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

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

        public static JsObj of​(java.lang.String key1,
                               JsValue el1,
                               java.lang.String key2,
                               JsValue el2,
                               java.lang.String key3,
                               JsValue el3,
                               java.lang.String key4,
                               JsValue el4,
                               java.lang.String key5,
                               JsValue el5,
                               java.lang.String key6,
                               JsValue el6,
                               java.lang.String key7,
                               JsValue el7,
                               java.lang.String key8,
                               JsValue el8,
                               java.lang.String key9,
                               JsValue el9)
        Returns a six-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsValue to be associated to the key1
        key2 - name of a key
        el2 - JsValue to be associated to the key2
        key3 - name of a key
        el3 - JsValue to be associated to the key3
        key4 - name of a key
        el4 - JsValue to be associated to the key4
        key5 - name of a key
        el5 - JsValue to be associated to the key5
        key6 - name of a key
        el6 - JsValue to be associated to the key6
        key7 - name of a key
        el7 - JsValue to be associated to the key7
        key8 - name of a key
        el8 - JsValue to be associated to the key8
        key9 - name of a key
        el9 - JsValue to be associated to the key9
        Returns:
        an immutable nine-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        public static JsObj of​(java.lang.String key1,
                               JsValue el1,
                               java.lang.String key2,
                               JsValue el2,
                               java.lang.String key3,
                               JsValue el3,
                               java.lang.String key4,
                               JsValue el4,
                               java.lang.String key5,
                               JsValue el5,
                               java.lang.String key6,
                               JsValue el6,
                               java.lang.String key7,
                               JsValue el7,
                               java.lang.String key8,
                               JsValue el8,
                               java.lang.String key9,
                               JsValue el9,
                               java.lang.String key10,
                               JsValue el10)
        Returns a six-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsValue to be associated to the key1
        key2 - name of a key
        el2 - JsValue to be associated to the key2
        key3 - name of a key
        el3 - JsValue to be associated to the key3
        key4 - name of a key
        el4 - JsValue to be associated to the key4
        key5 - name of a key
        el5 - JsValue to be associated to the key5
        key6 - name of a key
        el6 - JsValue to be associated to the key6
        key7 - name of a key
        el7 - JsValue to be associated to the key7
        key8 - name of a key
        el8 - JsValue to be associated to the key8
        key9 - name of a key
        el9 - JsValue to be associated to the key9
        key10 - name of a key
        el10 - JsValue to be associated to the key10
        Returns:
        an immutable ten-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        public static JsObj of​(java.lang.String key1,
                               JsValue el1,
                               java.lang.String key2,
                               JsValue el2,
                               java.lang.String key3,
                               JsValue el3,
                               java.lang.String key4,
                               JsValue el4,
                               java.lang.String key5,
                               JsValue el5,
                               java.lang.String key6,
                               JsValue el6,
                               java.lang.String key7,
                               JsValue el7,
                               java.lang.String key8,
                               JsValue el8,
                               java.lang.String key9,
                               JsValue el9,
                               java.lang.String key10,
                               JsValue el10,
                               java.lang.String key11,
                               JsValue el11)
        Returns a six-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsValue to be associated to the key1
        key2 - name of a key
        el2 - JsValue to be associated to the key2
        key3 - name of a key
        el3 - JsValue to be associated to the key3
        key4 - name of a key
        el4 - JsValue to be associated to the key4
        key5 - name of a key
        el5 - JsValue to be associated to the key5
        key6 - name of a key
        el6 - JsValue to be associated to the key6
        key7 - name of a key
        el7 - JsValue to be associated to the key7
        key8 - name of a key
        el8 - JsValue to be associated to the key8
        key9 - name of a key
        el9 - JsValue to be associated to the key9
        key10 - name of a key
        el10 - JsValue to be associated to the key10
        key11 - name of a key
        el11 - JsValue to be associated to the key11
        Returns:
        an immutable eleven-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        public static JsObj of​(java.lang.String key1,
                               JsValue el1,
                               java.lang.String key2,
                               JsValue el2,
                               java.lang.String key3,
                               JsValue el3,
                               java.lang.String key4,
                               JsValue el4,
                               java.lang.String key5,
                               JsValue el5,
                               java.lang.String key6,
                               JsValue el6,
                               java.lang.String key7,
                               JsValue el7,
                               java.lang.String key8,
                               JsValue el8,
                               java.lang.String key9,
                               JsValue el9,
                               java.lang.String key10,
                               JsValue el10,
                               java.lang.String key11,
                               JsValue el11,
                               java.lang.String key12,
                               JsValue el12)
        Returns a six-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsValue to be associated to the key1
        key2 - name of a key
        el2 - JsValue to be associated to the key2
        key3 - name of a key
        el3 - JsValue to be associated to the key3
        key4 - name of a key
        el4 - JsValue to be associated to the key4
        key5 - name of a key
        el5 - JsValue to be associated to the key5
        key6 - name of a key
        el6 - JsValue to be associated to the key6
        key7 - name of a key
        el7 - JsValue to be associated to the key7
        key8 - name of a key
        el8 - JsValue to be associated to the key8
        key9 - name of a key
        el9 - JsValue to be associated to the key9
        key10 - name of a key
        el10 - JsValue to be associated to the key10
        key11 - name of a key
        el11 - JsValue to be associated to the key11
        key12 - name of a key
        el12 - JsValue to be associated to the key12
        Returns:
        an immutable twelve-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        public static JsObj of​(java.lang.String key1,
                               JsValue el1,
                               java.lang.String key2,
                               JsValue el2,
                               java.lang.String key3,
                               JsValue el3,
                               java.lang.String key4,
                               JsValue el4,
                               java.lang.String key5,
                               JsValue el5,
                               java.lang.String key6,
                               JsValue el6,
                               java.lang.String key7,
                               JsValue el7,
                               java.lang.String key8,
                               JsValue el8,
                               java.lang.String key9,
                               JsValue el9,
                               java.lang.String key10,
                               JsValue el10,
                               java.lang.String key11,
                               JsValue el11,
                               java.lang.String key12,
                               JsValue el12,
                               java.lang.String key13,
                               JsValue el13)
        Returns a six-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsValue to be associated to the key1
        key2 - name of a key
        el2 - JsValue to be associated to the key2
        key3 - name of a key
        el3 - JsValue to be associated to the key3
        key4 - name of a key
        el4 - JsValue to be associated to the key4
        key5 - name of a key
        el5 - JsValue to be associated to the key5
        key6 - name of a key
        el6 - JsValue to be associated to the key6
        key7 - name of a key
        el7 - JsValue to be associated to the key7
        key8 - name of a key
        el8 - JsValue to be associated to the key8
        key9 - name of a key
        el9 - JsValue to be associated to the key9
        key10 - name of a key
        el10 - JsValue to be associated to the key10
        key11 - name of a key
        el11 - JsValue to be associated to the key11
        key12 - name of a key
        el12 - JsValue to be associated to the key12
        key13 - name of a key
        el13 - JsValue to be associated to the key13
        Returns:
        an immutable twelve-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        public static JsObj of​(java.lang.String key1,
                               JsValue el1,
                               java.lang.String key2,
                               JsValue el2,
                               java.lang.String key3,
                               JsValue el3,
                               java.lang.String key4,
                               JsValue el4,
                               java.lang.String key5,
                               JsValue el5,
                               java.lang.String key6,
                               JsValue el6,
                               java.lang.String key7,
                               JsValue el7,
                               java.lang.String key8,
                               JsValue el8,
                               java.lang.String key9,
                               JsValue el9,
                               java.lang.String key10,
                               JsValue el10,
                               java.lang.String key11,
                               JsValue el11,
                               java.lang.String key12,
                               JsValue el12,
                               java.lang.String key13,
                               JsValue el13,
                               java.lang.String key14,
                               JsValue el14)
        Returns a six-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsValue to be associated to the key1
        key2 - name of a key
        el2 - JsValue to be associated to the key2
        key3 - name of a key
        el3 - JsValue to be associated to the key3
        key4 - name of a key
        el4 - JsValue to be associated to the key4
        key5 - name of a key
        el5 - JsValue to be associated to the key5
        key6 - name of a key
        el6 - JsValue to be associated to the key6
        key7 - name of a key
        el7 - JsValue to be associated to the key7
        key8 - name of a key
        el8 - JsValue to be associated to the key8
        key9 - name of a key
        el9 - JsValue to be associated to the key9
        key10 - name of a key
        el10 - JsValue to be associated to the key10
        key11 - name of a key
        el11 - JsValue to be associated to the key11
        key12 - name of a key
        el12 - JsValue to be associated to the key12
        key13 - name of a key
        el13 - JsValue to be associated to the key13
        key14 - name of a key
        el14 - JsValue to be associated to the key14
        Returns:
        an immutable twelve-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        public static JsObj of​(java.lang.String key1,
                               JsValue el1,
                               java.lang.String key2,
                               JsValue el2,
                               java.lang.String key3,
                               JsValue el3,
                               java.lang.String key4,
                               JsValue el4,
                               java.lang.String key5,
                               JsValue el5,
                               java.lang.String key6,
                               JsValue el6,
                               java.lang.String key7,
                               JsValue el7,
                               java.lang.String key8,
                               JsValue el8,
                               java.lang.String key9,
                               JsValue el9,
                               java.lang.String key10,
                               JsValue el10,
                               java.lang.String key11,
                               JsValue el11,
                               java.lang.String key12,
                               JsValue el12,
                               java.lang.String key13,
                               JsValue el13,
                               java.lang.String key14,
                               JsValue el14,
                               java.lang.String key15,
                               JsValue el15)
        Returns a six-element immutable object.
        Parameters:
        key1 - name of a key
        el1 - JsValue to be associated to the key1
        key2 - name of a key
        el2 - JsValue to be associated to the key2
        key3 - name of a key
        el3 - JsValue to be associated to the key3
        key4 - name of a key
        el4 - JsValue to be associated to the key4
        key5 - name of a key
        el5 - JsValue to be associated to the key5
        key6 - name of a key
        el6 - JsValue to be associated to the key6
        key7 - name of a key
        el7 - JsValue to be associated to the key7
        key8 - name of a key
        el8 - JsValue to be associated to the key8
        key9 - name of a key
        el9 - JsValue to be associated to the key9
        key10 - name of a key
        el10 - JsValue to be associated to the key10
        key11 - name of a key
        el11 - JsValue to be associated to the key11
        key12 - name of a key
        el12 - JsValue to be associated to the key12
        key13 - name of a key
        el13 - JsValue to be associated to the key13
        key14 - name of a key
        el14 - JsValue to be associated to the key14
        key15 - name of a key
        el15 - JsValue to be associated to the key15
        Returns:
        an immutable twelve-element JsObj
        Throws:
        UserError - if an elem is a mutable Json
      • of

        public 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
      • ofIterable

        public static JsObj ofIterable​(java.lang.Iterable<java.util.Map.Entry<java.lang.String,​JsValue>> xs)
      • set

        public JsObj set​(java.lang.String key,
                         JsValue value)
        Inserts the element at the key in this json, replacing any existing element.
        Parameters:
        key - the key
        value - the element
        Returns:
        a new json object
      • delete

        public final JsObj delete​(java.lang.String key)
      • parse

        public static JsObj parse​(java.lang.String str)
        Tries to parse the string into an immutable object.
        Parameters:
        str - the string to be parsed
        Returns:
        a JsOb object
        Throws:
        MalformedJson - if the string doesnt represent a json object
      • parseYaml

        public static JsObj parseYaml​(java.lang.String str)
        Tries to parse a YAML string into an immutable object.
        Parameters:
        str - the YAML to be parsed
        Returns:
        a JsOb object
        Throws:
        MalformedJson - if the string doesnt represent a json object
      • containsValue

        public final boolean containsValue​(JsValue el)
        Description copied from interface: Json
        Returns true if this json contains the given element in the first level.
        Specified by:
        containsValue in interface Json<JsObj>
        Parameters:
        el - the give element JsValue whose presence in this JsArray is to be tested
        Returns:
        true if this JsArray contains the JsValue
      • keySet

        public final java.util.Set<java.lang.String> keySet()
        Returns a set containing each key fo this object.
        Returns:
        a Set containing each key of this JsObj
      • get

        public JsValue get​(JsPath path)
        Description copied from interface: Json
        Returns the element located at the given path or JsNothing if it doesn't exist.
        Specified by:
        get in interface Json<JsObj>
        Parameters:
        path - the JsPath object of the element that will be returned
        Returns:
        the JsValue located at the given JsPath or JsNothing if it doesn't exist
      • filterValues

        public JsObj filterValues​(java.util.function.Predicate<? super JsPrimitive> filter)
        Description copied from interface: Json
        Filters the pairs of elements in the first level of this json, removing those that don't ifPredicateElse the predicate.
        Specified by:
        filterValues in interface Json<JsObj>
        Parameters:
        filter - the predicate which takes as the input every JsPair in the first level of this json
        Returns:
        same this instance if all the pairs satisfy the predicate or a new filtered json of the same type T
        See Also:
        how to filter the pair of elements of the whole json and not only the first level
      • filterAllValues

        public final JsObj filterAllValues​(java.util.function.BiPredicate<? super JsPath,​? super JsPrimitive> filter)
        Description copied from interface: Json
        Filters all the pairs of elements of this json, removing those that don't ifPredicateElse the predicate.
        Specified by:
        filterAllValues in interface Json<JsObj>
        Parameters:
        filter - the predicate which takes as the input every JsPair of this json
        Returns:
        same this instance if all the pairs satisfy the predicate or a new filtered json of the same type T
      • filterAllValues

        public JsObj filterAllValues​(java.util.function.Predicate<? super JsPrimitive> filter)
        Description copied from interface: Json
        Filters all the pairs of elements of this json, removing those that don't ifPredicateElse the predicate.
        Specified by:
        filterAllValues in interface Json<JsObj>
        Parameters:
        filter - the predicate which takes as the input every JsPair of this json
        Returns:
        same this instance if all the pairs satisfy the predicate or a new filtered json of the same type T
      • filterKeys

        public JsObj filterKeys​(java.util.function.Predicate<? super java.lang.String> filter)
        Description copied from interface: Json
        Filters the keys in the first level of this json, removing those that don't ifPredicateElse the predicate.
        Specified by:
        filterKeys in interface Json<JsObj>
        Parameters:
        filter - the predicate which takes as the input every JsPair in the first level of this json
        Returns:
        same this instance if all the keys satisfy the predicate or a new filtered json of the same type T
        See Also:
        how to filter the keys of the whole json and not only the first level
      • filterAllKeys

        public JsObj filterAllKeys​(java.util.function.BiPredicate<? super JsPath,​? super JsValue> filter)
        Description copied from interface: Json
        Filters all the keys of this json, removing those that don't ifPredicateElse the predicate.
        Specified by:
        filterAllKeys in interface Json<JsObj>
        Parameters:
        filter - the predicate which takes as the input every JsPair of this json
        Returns:
        same this instance if all the keys satisfy the predicate or a new filtered json of the same type T
      • filterAllKeys

        public JsObj filterAllKeys​(java.util.function.Predicate<? super java.lang.String> filter)
        Description copied from interface: Json
        Filters all the keys of this json, removing those that don't ifPredicateElse the predicate.
        Specified by:
        filterAllKeys in interface Json<JsObj>
        Parameters:
        filter - the predicate which takes as the input every JsPair of this json
        Returns:
        same this instance if all the keys satisfy the predicate or a new filtered json of the same type T
      • filterObjs

        public JsObj filterObjs​(java.util.function.Predicate<? super JsObj> filter)
        Description copied from interface: Json
        Filters the pair of jsons in the first level of this json, removing those that don't ifPredicateElse the predicate.
        Specified by:
        filterObjs in interface Json<JsObj>
        Parameters:
        filter - the predicate which takes as the input every JsPair in the first level of this json
        Returns:
        same this instance if all the pairs satisfy the predicate or a new filtered json of the same type T
      • filterAllObjs

        public final JsObj filterAllObjs​(java.util.function.BiPredicate<? super JsPath,​? super JsObj> filter)
        Description copied from interface: Json
        Filters all the pair of jsons of this json, removing those that don't ifPredicateElse the predicate.
        Specified by:
        filterAllObjs in interface Json<JsObj>
        Parameters:
        filter - the predicate which takes as the input every JsPair of this json
        Returns:
        same this instance if all the pairs satisfy the predicate or a new filtered json of the same type T
      • filterAllObjs

        public JsObj filterAllObjs​(java.util.function.Predicate<? super JsObj> filter)
        Description copied from interface: Json
        Filters all the pair of jsons of this json, removing those that don't ifPredicateElse the predicate.
        Specified by:
        filterAllObjs in interface Json<JsObj>
        Parameters:
        filter - the predicate which takes as the input every JsPair of this json
        Returns:
        same this instance if all the pairs satisfy the predicate or a new filtered json of the same type T
      • isEmpty

        public final boolean isEmpty()
        Description copied from interface: Json
        return true if there's no element in this json
        Specified by:
        isEmpty in interface Json<JsObj>
        Returns:
        true if empty, false otherwise
      • mapValues

        public JsObj mapValues​(java.util.function.Function<? super JsPrimitive,​? extends JsValue> fn)
        Description copied from interface: Json
        Maps the values in the first level of this json.
        Specified by:
        mapValues in interface Json<JsObj>
        Parameters:
        fn - the mapping function
        Returns:
        a new mapped json of the same type T
      • mapAllValues

        public final JsObj mapAllValues​(java.util.function.BiFunction<? super JsPath,​? super JsPrimitive,​? extends JsValue> fn)
        Description copied from interface: Json
        Maps all the values of this json.
        Specified by:
        mapAllValues in interface Json<JsObj>
        Parameters:
        fn - the mapping function
        Returns:
        a new mapped json of the same type T
      • mapAllValues

        public JsObj mapAllValues​(java.util.function.Function<? super JsPrimitive,​? extends JsValue> fn)
        Description copied from interface: Json
        Maps all the values of this json.
        Specified by:
        mapAllValues in interface Json<JsObj>
        Parameters:
        fn - the mapping function
        Returns:
        a new mapped json of the same type T
      • mapKeys

        public JsObj mapKeys​(java.util.function.Function<? super java.lang.String,​java.lang.String> fn)
        Description copied from interface: Json
        Maps the keys in the first level of this json.
        Specified by:
        mapKeys in interface Json<JsObj>
        Parameters:
        fn - the mapping function
        Returns:
        a new mapped json of the same type T
      • mapAllKeys

        public final JsObj mapAllKeys​(java.util.function.BiFunction<? super JsPath,​? super JsValue,​java.lang.String> fn)
        Description copied from interface: Json
        Maps all the keys of this json.
        Specified by:
        mapAllKeys in interface Json<JsObj>
        Parameters:
        fn - the mapping function
        Returns:
        a new mapped json of the same type T
      • mapAllKeys

        public JsObj mapAllKeys​(java.util.function.Function<? super java.lang.String,​java.lang.String> fn)
        Description copied from interface: Json
        Maps all the keys of this json.
        Specified by:
        mapAllKeys in interface Json<JsObj>
        Parameters:
        fn - the mapping function
        Returns:
        a new mapped json of the same type T
      • mapObjs

        public JsObj mapObjs​(java.util.function.Function<? super JsObj,​JsValue> fn)
        Description copied from interface: Json
        Maps the jsons in the first level of this json.
        Specified by:
        mapObjs in interface Json<JsObj>
        Parameters:
        fn - the mapping function
        Returns:
        a new mapped json of the same type T
      • mapAllObjs

        public final JsObj mapAllObjs​(java.util.function.BiFunction<? super JsPath,​? super JsObj,​JsValue> fn)
        Description copied from interface: Json
        Maps all the jsons of this json.
        Specified by:
        mapAllObjs in interface Json<JsObj>
        Parameters:
        fn - the mapping function
        Returns:
        a new mapped json of the same type T
      • mapAllObjs

        public JsObj mapAllObjs​(java.util.function.Function<? super JsObj,​JsValue> fn)
        Description copied from interface: Json
        Maps all the jsons of this json.
        Specified by:
        mapAllObjs in interface Json<JsObj>
        Parameters:
        fn - the mapping function
        Returns:
        a new mapped json of the same type T
      • set

        public final JsObj set​(JsPath path,
                               JsValue value,
                               JsValue padElement)
        Description copied from interface: Json
        Inserts the element at the path in this json, replacing any existing element and filling with padElement empty indexes in arrays when necessary.

        The same instance is returned when the head of the path is a key and this is an array or the head of the path is an index and this is an object or the element is JsNothing

        Specified by:
        set in interface Json<JsObj>
        Parameters:
        path - the JsPath object where the element will be inserted at
        value - the JsValue that will be inserted
        padElement - the JsValue that will be inserted in arrays when padding is necessary
        Returns:
        the same instance or a new json of the same type T
      • set

        public JsObj set​(JsPath path,
                         JsValue element)
        Description copied from interface: Json
        Inserts the element at the path in this json, replacing any existing element and filling with JsNull empty indexes in arrays when necessary.

        The same instance is returned when the head of the path is a key and this is an array or the head of the path is an index and this is an object or the element is JsNothing

        Specified by:
        set in interface Json<JsObj>
        Parameters:
        path - the JsPath object where the element will be inserted at
        element - the JsValue that will be inserted
        Returns:
        the same instance or a new json of the same type T
      • reduce

        public <R> java.util.Optional<R> reduce​(java.util.function.BinaryOperator<R> op,
                                                java.util.function.Function<? super JsPrimitive,​R> map,
                                                java.util.function.Predicate<? super JsPrimitive> predicate)
        Description copied from interface: Json
        Performs a reduction on the values that satisfy the predicate in the first level of this json. The reduction is performed mapping each value with the mapping function and then applying the operator
        Specified by:
        reduce in interface Json<JsObj>
        Type Parameters:
        R - the type of the operands of the operator
        Parameters:
        op - the operator upon two objects of type R
        map - the mapping function which produces an object of type R from a JsValue
        predicate - the predicate that determines what JsValue will be mapped and reduced
        Returns:
        an Optional describing the of of the reduction
        See Also:
        to apply the reduction in all the Json and not only in the first level
      • reduceAll

        public final <R> java.util.Optional<R> reduceAll​(java.util.function.BinaryOperator<R> op,
                                                         java.util.function.BiFunction<? super JsPath,​? super JsPrimitive,​R> map,
                                                         java.util.function.BiPredicate<? super JsPath,​? super JsPrimitive> predicate)
        Description copied from interface: Json
        Performs a reduction on the values of this json that satisfy the predicate. The reduction is performed mapping each value with the mapping function and then applying the operator
        Specified by:
        reduceAll in interface Json<JsObj>
        Type Parameters:
        R - the type of the operands of the operator
        Parameters:
        op - the operator upon two objects of type R
        map - the mapping function which produces an object of type R from a JsValue
        predicate - the predicate that determines what JsValue will be mapped and reduced
        Returns:
        an Optional describing the result of the reduction
      • reduceAll

        public <R> java.util.Optional<R> reduceAll​(java.util.function.BinaryOperator<R> op,
                                                   java.util.function.Function<? super JsPrimitive,​R> map,
                                                   java.util.function.Predicate<? super JsPrimitive> predicate)
        Description copied from interface: Json
        Performs a reduction on the values of this json that satisfy the predicate. The reduction is performed mapping each value with the mapping function and then applying the operator
        Specified by:
        reduceAll in interface Json<JsObj>
        Type Parameters:
        R - the type of the operands of the operator
        Parameters:
        op - the operator upon two objects of type R
        map - the mapping function which produces an object of type R from a JsValue
        predicate - the predicate that determines what JsValue will be mapped and reduced
        Returns:
        an Optional describing the result of the reduction
      • delete

        public final JsObj delete​(JsPath path)
        Description copied from interface: Json
        Removes the element in this json located at the given path, if it exists, returning the same this instance otherwise
        Specified by:
        delete in interface Json<JsObj>
        Parameters:
        path - the given JsPath object
        Returns:
        a json of the same type T
      • size

        public final int size()
        Description copied from interface: Json
        Returns the number of elements in the first level of this json
        Specified by:
        size in interface Json<JsObj>
        Returns:
        the number of elements in the first level of this json
      • streamAll

        public final java.util.stream.Stream<JsPair> streamAll()
        Description copied from interface: Json
        Returns a stream over all the pairs of elements in this json object.
        Specified by:
        streamAll in interface Json<JsObj>
        Returns:
        a Stream over all the JsPairs in this json
      • stream

        public final java.util.stream.Stream<JsPair> stream()
        Description copied from interface: Json
        Returns a stream over the pairs of elements in the first level of this json object.
        Specified by:
        stream in interface Json<JsObj>
        Returns:
        a Stream over all the JsPairs in the first level of this json
      • filterValues

        public final JsObj filterValues​(java.util.function.BiPredicate<? super java.lang.String,​? super JsPrimitive> filter)
      • filterKeys

        public final JsObj filterKeys​(java.util.function.BiPredicate<? super java.lang.String,​? super JsValue> filter)
      • filterObjs

        public final JsObj filterObjs​(java.util.function.BiPredicate<? super java.lang.String,​? super JsObj> filter)
      • mapValues

        public final JsObj mapValues​(java.util.function.BiFunction<? super java.lang.String,​? super JsPrimitive,​? extends JsValue> fn)
      • mapKeys

        public final JsObj mapKeys​(java.util.function.BiFunction<? super java.lang.String,​? super JsValue,​java.lang.String> fn)
      • mapObjs

        public final JsObj mapObjs​(java.util.function.BiFunction<? super java.lang.String,​? super JsObj,​JsValue> fn)
      • reduce

        public final <R> java.util.Optional<R> reduce​(java.util.function.BinaryOperator<R> op,
                                                      java.util.function.BiFunction<? super java.lang.String,​? super JsPrimitive,​R> map,
                                                      java.util.function.BiPredicate<? super java.lang.String,​? super JsPrimitive> predicate)
        Performs a reduction on the values that satisfy the predicate in the first level of this json. The reduction is performed mapping each value with the mapping function and then applying the operator
        Type Parameters:
        R - the type of the operands of the operator
        Parameters:
        op - the operator upon two objects of type R
        map - the mapping function which produces an object of type R from a JsValue
        predicate - the predicate that determines what JsValue will be mapped and reduced
        Returns:
        an Optional describing the of of the reduction
        See Also:
        to apply the reduction in all the Json and not only in the first level
      • equals

        public 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
      • containsKey

        public boolean containsKey​(java.lang.String key)
        return true if the key is present
        Parameters:
        key - the key
        Returns:
        true if the specified key exists
      • get

        public JsValue get​(java.lang.String key)
      • getArray

        public JsArray getArray​(java.lang.String key)
        Returns the array located at the given key or null if it doesn't exist or it's not an array.
        Parameters:
        key - the key
        Returns:
        the JsArray located at the given key or null
      • getArray

        public JsArray getArray​(java.lang.String key,
                                java.util.function.Supplier<JsArray> orElse)
        Returns the array located at the given key or the default value provided if it doesn't exist or it's not an array.
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the JsArray located at the given key or the default value provided
      • getBigDec

        public java.math.BigDecimal getBigDec​(java.lang.String key)
        Returns the number located at the given key as a big decimal or null if it doesn't exist or it's not a decimal number.
        Parameters:
        key - the key
        Returns:
        the BigDecimal located at the given key or null
      • getBigDec

        public java.math.BigDecimal getBigDec​(java.lang.String key,
                                              java.util.function.Supplier<java.math.BigDecimal> orElse)
        Returns the number located at the given key as a big decimal or the default value provided if it doesn't exist or it's not a decimal number.
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the BigDecimal located at the given key or the default value provided
      • getBinary

        public byte[] getBinary​(java.lang.String key)
        Returns the bytes located at the given key or null if it doesn't exist or it's not an array of bytes.
        Parameters:
        key - the key
        Returns:
        the bytes located at the given key or null
      • getBinary

        public byte[] getBinary​(java.lang.String key,
                                java.util.function.Supplier<byte[]> orElse)
        Returns the bytes located at the given key or the default value provided if it doesn't exist or it's not an array of bytes.
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the bytes located at the given key or the default value provided
      • getBigInt

        public java.math.BigInteger getBigInt​(java.lang.String key)
        Returns the big integer located at the given key as a big integer or null if it doesn't exist or it's not an integral number.
        Parameters:
        key - the key
        Returns:
        the BigInteger located at the given key or null
      • getBigInt

        public java.math.BigInteger getBigInt​(java.lang.String key,
                                              java.util.function.Supplier<java.math.BigInteger> orElse)
        Returns the big integer located at the given key as a big integer or the default value provided if it doesn't exist or it's not an integral number.
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the BigInteger located at the given key or null
      • getInstant

        public java.time.Instant getInstant​(java.lang.String key)
        Returns the instant located at the given key or null if it doesn't exist or it's not an instant.
        Parameters:
        key - the key
        Returns:
        the instant located at the given key or null
      • getInstant

        public java.time.Instant getInstant​(java.lang.String key,
                                            java.util.function.Supplier<java.time.Instant> orElse)
        Returns the instant located at the given key or the default value provided if it doesn't exist or it's not an instant.
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the instant located at the given key or null
      • getBool

        public java.lang.Boolean getBool​(java.lang.String key)
        Returns the boolean located at the given key or null if it doesn't exist.
        Parameters:
        key - the key
        Returns:
        the Boolean located at the given key or null
      • getBool

        public java.lang.Boolean getBool​(java.lang.String key,
                                         java.util.function.Supplier<java.lang.Boolean> orElse)
        Returns the boolean located at the given key or the default value provided if it doesn't exist.
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the Boolean located at the given key or null
      • getDouble

        public java.lang.Double getDouble​(java.lang.String key)
        Returns the number located at the given key as a double or null if it doesn't exist or it's not a decimal number. If the number is a BigDecimal, the conversion is identical to the specified in BigDecimal.doubleValue() and in some cases it can lose information about the precision of the BigDecimal
        Parameters:
        key - the key
        Returns:
        the decimal number located at the given key or null
      • getDouble

        public java.lang.Double getDouble​(java.lang.String key,
                                          java.util.function.Supplier<java.lang.Double> orElse)
        Returns the number located at the given key as a double or the default value provided if it doesn't exist or it's not a decimal number. If the number is a BigDecimal, the conversion is identical to the specified in BigDecimal.doubleValue() and in some cases it can lose information about the precision of the BigDecimal
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the decimal number located at the given key or null
      • getInt

        public java.lang.Integer getInt​(java.lang.String key)
        Returns the integral number located at the given key as an integer or null if it doesn't exist or it's not an integral number or it's an integral number but doesn't fit in an integer.
        Parameters:
        key - the key
        Returns:
        the integral number located at the given key or null
      • getInt

        public java.lang.Integer getInt​(java.lang.String key,
                                        java.util.function.Supplier<java.lang.Integer> orElse)
        Returns the integral number located at the given key as an integer or the default value provided if it doesn't exist or it's not an integral number or it's an integral number but doesn't fit in an integer.
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the integral number located at the given key or null
      • getLong

        public java.lang.Long getLong​(java.lang.String key)
        Returns the integral number located at the given key as a long or null if it doesn't exist or it's not an integral number or it's an integral number but doesn't fit in a long.
        Parameters:
        key - the key
        Returns:
        the integral number located at the given key or null
      • getLong

        public java.lang.Long getLong​(java.lang.String key,
                                      java.util.function.Supplier<java.lang.Long> orElse)
        Returns the integral number located at the given key as a long or the default value provided if it doesn't exist or it's not an integral number or it's an integral number but doesn't fit in a long.
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the integral number located at the given key or the default value provided
      • getObj

        public JsObj getObj​(java.lang.String key)
        Returns the json object located at the given key or null if it doesn't exist or it's not an object.
        Parameters:
        key - the key
        Returns:
        the json object located at the given key or null
      • getObj

        public JsObj getObj​(java.lang.String key,
                            java.util.function.Supplier<JsObj> orElse)
        Returns the json object located at the given key or the default value provided if it doesn't exist or it's not an object.
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the json object located at the given key or the default value
      • getStr

        public java.lang.String getStr​(java.lang.String key)
        Returns the string located at the given key or null if it doesn't exist or it's not an string.
        Parameters:
        key - the key
        Returns:
        the string located at the given key or null
      • getStr

        public java.lang.String getStr​(java.lang.String key,
                                       java.util.function.Supplier<java.lang.String> orElse)
        Returns the string located at the given key or the default value provided if it doesn't exist or it's not an string.
        Parameters:
        key - the key
        orElse - the default value
        Returns:
        the string located at the given key or null
      • hashCode

        public final int hashCode()
        equals method is inherited, so it's implemented. The purpose of this method is to cache the hashcode once calculated. the object is immutable and it won't change Single-check idiom Item 83 from Effective Java
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public final boolean equals​(java.lang.Object that)
        Overrides:
        equals in class java.lang.Object
      • toString

        public final java.lang.String toString()
        // Single-check idiom Item 83 from effective java
        Overrides:
        toString in class java.lang.Object
      • id

        public int id()
        Specified by:
        id in interface JsValue
      • isObj

        public boolean isObj()
        Description copied from interface: JsValue
        Returns true if this JsValue is a JsObj
        Specified by:
        isObj in interface JsValue
        Returns:
        true if this JsValue is a JsObj
      • head

        public final io.vavr.Tuple2<java.lang.String,​JsValue> 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().
        Returns:
        an arbitrary Map.Entry<String,JsValue> of this JsObj
        Throws:
        UserError - if this json object is empty
      • tail

        public final JsObj tail()
        Returns a new object with all the entries of this json object except the one with the given key.
        Returns:
        a new JsObj
        Throws:
        UserError - if this json object is empty
      • intersection

        public 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)
      • intersectionAll

        public JsObj intersectionAll​(JsObj that,
                                     JsArray.TYPE ARRAY_AS)
        this.intersectionAll(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)
      • iterator

        public java.util.Iterator<io.vavr.Tuple2<java.lang.String,​JsValue>> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<io.vavr.Tuple2<java.lang.String,​JsValue>>
      • union

        public final 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)
      • unionAll

        public final JsObj unionAll​(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)