Package jsonvalues
Interface Json<T extends Json<T>>
-
- Type Parameters:
T- Type of container: either an object or an array
- All Superinterfaces:
JsValue
public interface Json<T extends Json<T>> extends JsValue
Represents a json of type T, where T is the type of the container, either a JsObj or a JsArray. A json of any type can be modeled as a set of pairs
JsPair=(JsPath,JsValue), where: - a JsElem is aJsBoolorJsStrorJsNumberorJsNull, or anotherJsonlikeJsObjorJsArray, what makes the data structure recursive. - a JsPath represents the location of the element in the json. For example, the json { "a":1, "x":{ "c": true, "d":null, e: [false, 1, "hi"] } } can be seen as the following set: Set[(a,1), (x.c,true), (x.d,null), (x.e.0,false), (x.e.1,1), (x.e.2,"hi"), (_,NOTHING)] where _, which means any other JsPath, and the special elementJsNothing.NOTHING, makes the functionget(JsPath)total (defined for every possible path). Moreover, inserting JsNothing in a json doesn't change the json, which is very convenient when passing functions as parameters to put data in: //all the logic goes into the supplierSupplier<JsElem> supplier = ()-> (doesnt-put-anything-condition) ? JsNothing.NOTHING : JsInt.of(2); json.putIfAbsent(path,supplier)Another way to see a json is like a stream of pairs, which opens the door to doing all the operations that were introduced in Java 8 (map, filter, reduce, etc). For this purpose the methodsstreamAll()orstream()are provided. There are one convention on method names: -Methods that are suffixed with underscore traverse the whole json recursively. All the methods throw a NullPointerException when any of the params passed in is null. The exceptionUserErroris thrown when the user calls a method inappropriately: for example calling the methodasJsStrin aJsNullinstance or calling the method head in an empty array, etc. Normally, when that happens, a previous check is missing.- Author:
- Rafael Merino Garcia
- See Also:
to work with jsons that are objects,to work with jsons that are arrays
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Tappend(JsPath path, boolean elem, boolean... others)Appends one or more booleans, starting from the first, to the array located at the given path in this json.default Tappend(JsPath path, double elem, double... others)Appends one or more doubles, starting from the first, to the array located at the given path in this json.default Tappend(JsPath path, int elem, int... others)Appends one or more integers, starting from the first, to the array located at the given path in this json.default Tappend(JsPath path, long elem, long... others)Appends one or more longs, starting from the first, to the array located at the given path in this json.default Tappend(JsPath path, String elem, String... others)Appends one or more strings, starting from the first, to the array located at the given path in this json.Tappend(JsPath path, JsValue elem)Appends one element to the array located at the given path in this json.default Tappend(JsPath path, JsValue elem, JsValue... others)Appends one or more elements, starting from the first, to the array located at the given path in this json.TappendAll(JsPath path, JsArray elems)Appends all the elements of the array, starting from the head, to the array located at the given path in this json.default TappendAllIfPresent(JsPath path, Supplier<JsArray> supplier)Appends all the elements of the array computed by the supplier, starting from the head, to an array located at the given path in this json, returning the same this instance if the array is not present, in which case, the supplier is not evaluated.default TappendIfPresent(JsPath path, boolean number, boolean... others)Appends one or more booleans to the array located at the given path in this json, returning the same this instance if the array is not present.default TappendIfPresent(JsPath path, double number, double... others)Appends one or more doubles to the array located at the given path in this json, returning the same this instance if the array is not present.default TappendIfPresent(JsPath path, int number, int... others)Appends one or more integers to the array located at the given path in this json, returning the same this instance if the array is not present.default TappendIfPresent(JsPath path, long number, long... others)Appends one or more longs to the array located at the given path in this json, returning the same this instance if the array is not present.default TappendIfPresent(JsPath path, String str, String... others)Appends one or more strings to the array located at the given path in this json, returning the same this instance if the array is not present.default TappendIfPresent(JsPath path, Supplier<? extends JsValue> supplier)Appends the element given by the supplier, to the array located at the given path in this json, returning the same this instance if the array is not present.default booleancontainsPath(JsPath path)Returns true if an element exists in this json at the given path.booleancontainsValue(JsValue element)Returns true if this json contains the given element in the first level.default booleanequals(JsValue elem, JsArray.TYPE ARRAY_AS)TfilterAllKeys(Predicate<? super JsPair> filter)Filters all the keys of this json, removing those that don't ifPredicateElse the predicate.TfilterAllObjs(BiPredicate<? super JsPath,? super JsObj> filter)Filters all the pair of jsons of this json, removing those that don't ifPredicateElse the predicate.TfilterAllValues(Predicate<? super JsPair> filter)Filters all the pairs of elements of this json, removing those that don't ifPredicateElse the predicate.TfilterKeys(Predicate<? super JsPair> filter)Filters the keys in the first level of this json, removing those that don't ifPredicateElse the predicate.TfilterObjs(BiPredicate<? super JsPath,? super JsObj> filter)Filters the pair of jsons in the first level of this json, removing those that don't ifPredicateElse the predicate.TfilterValues(Predicate<? super JsPair> filter)Filters the pairs of elements in the first level of this json, removing those that don't ifPredicateElse the predicate.JsValueget(JsPath path)Returns the element located at the given path orJsNothingif it doesn't exist.default JsArraygetArray(JsPath path)Returns the array located at the given path or null if it doesn't exist or it's not an array.default BigDecimalgetBigDec(JsPath path)Returns the number located at the given path as a big decimal or null if it doesn't exist or it's not a decimal number.default BigIntegergetBigInt(JsPath path)Returns the number located at the given path as a big integer or null if it doesn't exist or it's not an integral number.default BooleangetBool(JsPath path)Returns the boolean located at the given path or null if it doesn't exist.default DoublegetDouble(JsPath path)Returns the decimal number located at the given path as a double or null if it doesn't exist or it's not a decimal number.default IntegergetInt(JsPath path)Returns the integral number located at the given path 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.default LonggetLong(JsPath path)Returns the integral number located at the given path 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.default JsObjgetObj(JsPath path)Returns the object located at the given path or null if it doesn't exist or it's not an object.default Optional<JsArray>getOptArray(JsPath path)Returns the array located at the given path orOptional.empty()if it doesn't exist or it's not an array.default Optional<BigDecimal>getOptBigDec(JsPath path)Returns the number located at the given path as a big decimal orOptional.empty()if it doesn't exist or it's not a decimal number.default Optional<BigInteger>getOptBigInt(JsPath path)Returns the number located at the given path as a big integer orOptional.empty()if it doesn't exist or it's not an integral number.default Optional<Boolean>getOptBool(JsPath path)Returns the boolean located at the given path orOptional.empty()if it doesn't exist.default OptionalDoublegetOptDouble(JsPath path)Returns the decimal number located at the given path as a double orOptionalDouble.empty()if it doesn't exist or it's not a decimal number.default OptionalIntgetOptInt(JsPath path)Returns the integral number located at the given path as an integer orOptionalInt.empty()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.default OptionalLonggetOptLong(JsPath path)Returns the integral number located at the given path as a long orOptionalLong.empty()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.default Optional<JsObj>getOptObj(JsPath path)Returns the object located at the given path orOptional.empty()if it doesn't exist or it's not an object.default Optional<String>getOptStr(JsPath path)Returns the string located at the given path orOptional.empty()if it doesn't exist or it's not an string.default StringgetStr(JsPath path)Returns the string located at the given path or null if it doesn't exist or it's not an string.default <A> AifEmptyElse(Supplier<A> emptySupplier, Supplier<A> nonemptySupplier)Declarative way of implementing if(this.isEmpty()) return emptySupplier.get() else return nonEmptySupplier.get()booleanisEmpty()return true if there's no element in this jsondefault booleanisNotEmpty()return true if this json it not emptydefault Tmap(UnaryOperator<T> fn)TmapAllKeys(Function<? super JsPair,String> fn)Maps all the keys of this json.TmapAllKeys(Function<? super JsPair,String> fn, Predicate<? super JsPair> predicate)Maps all the keys of this json that satisfies a given predicate.TmapAllObjs(BiFunction<? super JsPath,? super JsObj,JsObj> fn)Maps all the jsons of this json.TmapAllObjs(BiFunction<? super JsPath,? super JsObj,JsObj> fn, BiPredicate<? super JsPath,? super JsObj> predicate)Maps all the jsons of this json that satisfies a given predicate.TmapAllValues(Function<? super JsPair,? extends JsValue> fn)Maps all the values of this json.TmapAllValues(Function<? super JsPair,? extends JsValue> fn, Predicate<? super JsPair> predicate)Maps all the values of this json that satisfies a given predicate.TmapKeys(Function<? super JsPair,String> fn)Maps the keys in the first level of this json.TmapKeys(Function<? super JsPair,String> fn, Predicate<? super JsPair> predicate)Maps the keys in the first level of this json that satisfies a given predicate.TmapObjs(BiFunction<? super JsPath,? super JsObj,JsObj> fn)Maps the jsons in the first level of this json.TmapObjs(BiFunction<? super JsPath,? super JsObj,JsObj> fn, BiPredicate<? super JsPath,? super JsObj> predicate)Maps the jsons in the first level of this json that satisfies a given predicate.TmapValues(Function<? super JsPair,? extends JsValue> fn)Maps the values in the first level of this json.TmapValues(Function<? super JsPair,? extends JsValue> fn, Predicate<? super JsPair> predicate)Maps the values in the first level of this json that satisfies a given predicate.default Tprepend(JsPath path, boolean elem, boolean... others)prepends one or more booleans, starting from the first, to the array located at the path in this json.default Tprepend(JsPath path, double elem, double... others)prepends one or more doubles, starting from the first, to the array located at the path in this json.default Tprepend(JsPath path, int elem, int... others)prepends one or more integers, starting from the first, to the array located at the path in this json.default Tprepend(JsPath path, long elem, long... others)prepends one or more longs, starting from the first, to the array located at the path in this json.default Tprepend(JsPath path, String elem, String... others)Prepends one or more strings, starting from the first, to the array located at the path in this json.Tprepend(JsPath path, JsValue elem)prepends one element to the array located at the path in this json.default Tprepend(JsPath path, JsValue elem, JsValue... others)prepends one or more elements, starting from the first, to the array located at the path in this json.TprependAll(JsPath path, JsArray elems)prepends all the elements of the array, starting from the head, to the array located at the path in this json.default TprependAllIfPresent(JsPath path, Supplier<JsArray> supplier)Prepends all the elements of the array computed by the supplier, starting from the head, to the array located at the path in this json, returning the same this instance if the array is not present, in which case, the supplier is not invoked.default TprependIfPresent(JsPath path, boolean bool, boolean... others)Prepends one or more booleans to the array located at the given path in this json in the following order [number, others, existing elements], returning the same this instance if the array is not present.default TprependIfPresent(JsPath path, double number, double... others)Prepends one or more doubles to the array located at the given path in this json in the following order [number, others, existing elements], returning the same this instance if the array is not present.default TprependIfPresent(JsPath path, int number, int... others)Prepends one or more integers to the array located at the given path in this json in the following order [number, others, existing elements], returning the same this instance if the array is not present.default TprependIfPresent(JsPath path, long number, long... others)Prepends one or more longs to the array located at the given path in this json in the following order [number, others, existing elements], returning the same this instance if the array is not present.default TprependIfPresent(JsPath path, String str, String... others)Prepends one or more strings to the array located at the given path in this json in the following order [number, others, existing elements], returning the same this instance if the array is not present.default TprependIfPresent(JsPath path, Supplier<JsValue> supplier)Prepends one element given by a supplier, to the array located at the given path in this json, returning the same this instance if the array is not present.default Tput(JsPath path, boolean bool)Inserts the boolean at the given path in this json, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default Tput(JsPath path, int n)Inserts the integer number at the path in this json, replacing any existing element and filling withJsNullempty indexes in arrays when necessary.default Tput(JsPath path, long n)Inserts the long number at the path in this json, replacing any existing element and filling withJsNullempty indexes in arrays when necessary.default Tput(JsPath path, String str)Inserts the string at the given path in this json, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default Tput(JsPath path, BigDecimal bigdecimal)Inserts the big decimal number at the given path in this json, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default Tput(JsPath path, BigInteger bigint)Inserts the big integer number at the given path in this json, replacing any existing element in teh path and filling withJsNullempty positions in arrays when necessary.Tput(JsPath path, Function<? super JsValue,? extends JsValue> fn)Inserts the element returned by the function at the given path in this json, replacing any existing element and filling withJsNullempty indexes in arrays when necessary.default Tput(JsPath path, JsValue element)Inserts the element at the path in this json, replacing any existing element and filling withJsNullempty indexes in arrays when necessary.default TputIf(Predicate<? super JsValue> predicate, JsPath path, Function<? super JsValue,? extends JsValue> fn)Inserts at the given path in this json, if the existing element satisfies the predicate, a new element returned by the function.default TputIfAbsent(JsPath path, boolean bool)Inserts at the given path in this json, if no element is present, the specified boolean, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfAbsent(JsPath path, double number)Inserts at the given path in this json, if no element is present, the specified double, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfAbsent(JsPath path, int number)Inserts at the given path in this json, if no element is present, the specified integer, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfAbsent(JsPath path, long number)Inserts at the given path in this json, if no element is present, the specified long, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfAbsent(JsPath path, String str)Inserts at the given path in this json, if no element is present, the specified string, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfAbsent(JsPath path, BigDecimal number)Inserts at the given path in this json, if no element is present, the specified number, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfAbsent(JsPath path, BigInteger number)Inserts at the given path in this json, if no element is present, the specified number, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfAbsent(JsPath path, Supplier<? extends JsValue> supplier)Inserts at the given path in this json, if no element is present, the element returned by the supplier, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfAbsent(JsPath path, JsArray array)Inserts at the given path in this json, if no element is present, the specified array, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfAbsent(JsPath path, JsObj obj)Inserts at the given path in this json, if no element is present, the specified object, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfAbsent(JsPath path, JsValue value)Inserts at the given path in this json, if no element is present, the specified json value, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.default TputIfPresent(JsPath path, boolean bool)Inserts at the given path in this json, if some element is present, the specified boolean.default TputIfPresent(JsPath path, double number)Inserts at the given path in this json, if some element is present, the specified double.default TputIfPresent(JsPath path, int number)Inserts at the given path in this json, if some element is present, the specified integer.default TputIfPresent(JsPath path, long number)Inserts at the given path in this json, if some element is present, the specified long.default TputIfPresent(JsPath path, String str)Inserts at the given path in this json, if some element is present, the specified string.default TputIfPresent(JsPath path, BigDecimal number)Inserts at the given path in this json, if some element is present, the specified big decimal.default TputIfPresent(JsPath path, BigInteger number)Inserts at the given path in this json, if some element is present, the specified big integer.default TputIfPresent(JsPath path, Function<? super JsValue,? extends JsValue> fn)Inserts at the given path in this json, if some element is present, the element returned by the function.default TputIfPresent(JsPath path, JsArray array)Inserts at the given path in this json, if some element is present, the specified integer.default TputIfPresent(JsPath path, JsObj obj)Inserts at the given path in this json, if some element is present, the specified integer.default TputIfPresent(JsPath path, JsValue value)Inserts at the given path in this json, if some element is present, the specified value.<R> Optional<R>reduce(BinaryOperator<R> op, Function<? super JsPair,R> map, Predicate<? super JsPair> predicate)Performs a reduction on the values that satisfy the predicate in the first level of this json.<R> Optional<R>reduceAll(BinaryOperator<R> op, Function<? super JsPair,R> map, Predicate<? super JsPair> predicate)Performs a reduction on the values of this json that satisfy the predicate.Tremove(JsPath path)Removes the element in this json located at the given path, if it exists, returning the same this instance otherwisedefault byte[]serialize()Serialize this Json into an array of bytes.default voidserialize(OutputStream ouputstream)Serializes this Json into the given output stream, no returning anythingintsize()Returns the number of elements in the first level of this jsondefault OptionalIntsize(JsPath path)Returns the size of the json located at the given path in this json or OptionalInt.empty() if it doesn't exist or it's not a Jsondefault intsizeAll()Returns the number of all the elements in this jsondefault OptionalIntsizeAll(JsPath path)Returns the number of all the elements of the json located at the given path in this json or OptionalInt.empty() if it doesn't exist or it's not a JsonStream<JsPair>stream()Returns a stream over the pairs of elements in the first level of this json object.Stream<JsPair>streamAll()Returns a stream over all the pairs of elements in this json object.default longtimes(JsValue e)default longtimesAll(JsValue e)default StringtoPrettyString()Converts the string representation of this Json to a pretty print version-
Methods inherited from interface jsonvalues.JsValue
id, isArray, isArray, isBigDec, isBigDec, isBigInt, isBigInt, isBool, isDecimal, isDouble, isDouble, isFalse, isInstant, isInstant, isInt, isInt, isIntegral, isJson, isJson, isLocalDate, isLocalDate, isLocalDateTime, isLocalDateTime, isLong, isLong, isNothing, isNotJson, isNotNothing, isNotNull, isNotNumber, isNull, isNumber, isObj, isObj, isSameType, isStr, isStr, isTrue, toJsArray, toJsBigDec, toJsBigInt, toJsBool, toJsDouble, toJsInt, toJsLong, toJsNumber, toJsObj, toJson, toJsStr
-
-
-
-
Method Detail
-
toPrettyString
default String toPrettyString()
Converts the string representation of this Json to a pretty print version- Returns:
- pretty print version of the string representation of this Json
-
append
default T append(JsPath path, JsValue elem, JsValue... others)
Appends one or more elements, starting from the first, to the array located at the given path in this json. If the array doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the given JsPath pointing to the array in which all the elements will be appendedelem- the first JsElem to be appended to the existing or created arrayothers- more optional JsElem to be appended- Returns:
- same this instance or a new json of the same type T
-
append
T append(JsPath path, JsValue elem)
Appends one element to the array located at the given path in this json. If the array doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the path pointing to the array in which the element will be appendedelem- the JsElem to be appended to the existing or created array- Returns:
- same this instance or a new json of the same type T
-
append
default T append(JsPath path, String elem, String... others)
Appends one or more strings, starting from the first, to the array located at the given path in this json. If the array doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the given path pointing to the array in which all the strings will be appendedelem- the first string to be appended to the existing or created arrayothers- more optional strings to be appended- Returns:
- same this instance or a new json of the same type T
-
append
default T append(JsPath path, int elem, int... others)
Appends one or more integers, starting from the first, to the array located at the given path in this json. If the array doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the given path pointing to the array in which all the integers will be appendedelem- the first integer to be appended to the existing or created arrayothers- more optional integers to be appended- Returns:
- same this instance or a new json of the same type T
-
append
default T append(JsPath path, long elem, long... others)
Appends one or more longs, starting from the first, to the array located at the given path in this json. If the array doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the given path pointing to the array in which all the longs will be appendedelem- the first long to be appended to the existing or created arrayothers- more optional longs to be appended- Returns:
- same this instance or a new json of the same type T
-
append
default T append(JsPath path, boolean elem, boolean... others)
Appends one or more booleans, starting from the first, to the array located at the given path in this json. If the array doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the given path pointing to the array in which all the booleans will be appendedelem- the first boolean to be appended to the existing or created arrayothers- more optional booleans to be appended- Returns:
- same this instance or a new json of the same type T
-
append
default T append(JsPath path, double elem, double... others)
Appends one or more doubles, starting from the first, to the array located at the given path in this json. If the array doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the given path pointing to the array in which all the doubles will be appendedelem- the first double to be appended to the existing or created arrayothers- more optional doubles to be appended- Returns:
- same this instance or a new json of the same type T
-
appendAll
T appendAll(JsPath path, JsArray elems)
Appends all the elements of the array, starting from the head, to the array located at the given path in this json. If the array doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the given JsPath pointing to the array in which all the elements will be appendedelems- the JsArray of elements to be appended- Returns:
- same this instance or a new json of the same type T
-
appendAllIfPresent
default T appendAllIfPresent(JsPath path, Supplier<JsArray> supplier)
Appends all the elements of the array computed by the supplier, starting from the head, to an array located at the given path in this json, returning the same this instance if the array is not present, in which case, the supplier is not evaluated.- Parameters:
path- the given JsPath object pointing to the existing array in which all the elements will be appendedsupplier- the supplier of the array of elements that will be appended- Returns:
- same this instance or a new json of the same type T
-
appendIfPresent
default T appendIfPresent(JsPath path, Supplier<? extends JsValue> supplier)
Appends the element given by the supplier, to the array located at the given path in this json, returning the same this instance if the array is not present. The supplier is not applied if there's no array at the specified path.- Parameters:
path- the JsPath pointing to the existing array in which the element will be appendedsupplier- the given supplier- Returns:
- same this instance or a new json of the same type T
-
appendIfPresent
default T appendIfPresent(JsPath path, int number, int... others)
Appends one or more integers to the array located at the given path in this json, returning the same this instance if the array is not present.- Parameters:
path- the path pointing to the existing array in which the integers will be appendednumber- the integer to be appendedothers- more optional integers to be appended- Returns:
- same this instance or a new json of the same type T
-
appendIfPresent
default T appendIfPresent(JsPath path, long number, long... others)
Appends one or more longs to the array located at the given path in this json, returning the same this instance if the array is not present.- Parameters:
path- the path pointing to the existing array in which the longs will be appendednumber- the long to be appendedothers- more optional longs to be appended- Returns:
- same this instance or a new json of the same type T
-
appendIfPresent
default T appendIfPresent(JsPath path, String str, String... others)
Appends one or more strings to the array located at the given path in this json, returning the same this instance if the array is not present.- Parameters:
path- the path pointing to the existing array in which the strings will be appendedstr- the string to be appendedothers- more optional strings to be appended- Returns:
- same this instance or a new json of the same type T
-
appendIfPresent
default T appendIfPresent(JsPath path, boolean number, boolean... others)
Appends one or more booleans to the array located at the given path in this json, returning the same this instance if the array is not present.- Parameters:
path- the path pointing to the existing array in which the booleans will be appendednumber- the boolean to be appendedothers- more optional booleans to be appended- Returns:
- same this instance or a new json of the same type T
-
appendIfPresent
default T appendIfPresent(JsPath path, double number, double... others)
Appends one or more doubles to the array located at the given path in this json, returning the same this instance if the array is not present.- Parameters:
path- the path pointing to the existing array in which the doubles will be appendednumber- the double to be appendedothers- more optional doubles to be appended- Returns:
- same this instance or a new json of the same type T
-
containsValue
boolean containsValue(JsValue element)
Returns true if this json contains the given element in the first level.- Parameters:
element- the give element JsElem whose presence in this JsArray is to be tested- Returns:
- true if this JsArray contains the JsElem
-
containsPath
default boolean containsPath(JsPath path)
Returns true if an element exists in this json at the given path.- Parameters:
path- the JsPath- Returns:
- true if a JsElem exists at the JsPath
-
equals
default boolean equals(JsValue elem, JsArray.TYPE ARRAY_AS)
-
filterValues
T filterValues(Predicate<? super JsPair> filter)
Filters the pairs of elements in the first level of this json, removing those that don't ifPredicateElse the predicate.- 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
T filterAllValues(Predicate<? super JsPair> filter)
Filters all the pairs of elements of this json, removing those that don't ifPredicateElse the predicate.- 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
- See Also:
how to filter the pairs of values of only the first level
-
filterKeys
T filterKeys(Predicate<? super JsPair> filter)
Filters the keys in the first level of this json, removing those that don't ifPredicateElse the predicate.- 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
T filterAllKeys(Predicate<? super JsPair> filter)
Filters all the keys of this json, removing those that don't ifPredicateElse the predicate.- 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
- See Also:
how to filter the keys of only the first level
-
filterObjs
T filterObjs(BiPredicate<? super JsPath,? super JsObj> filter)
Filters the pair of jsons in the first level of this json, removing those that don't ifPredicateElse the predicate.- 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 jsons of the whole json and not only the first level
-
filterAllObjs
T filterAllObjs(BiPredicate<? super JsPath,? super JsObj> filter)
Filters all the pair of jsons of this json, removing those that don't ifPredicateElse the predicate.- 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
- See Also:
how to filter the pair of jsons of only the first level
-
get
JsValue get(JsPath path)
Returns the element located at the given path orJsNothingif it doesn't exist.- Parameters:
path- the JsPath object of the element that will be returned- Returns:
- the JsElem located at the given JsPath or JsNothing if it doesn't exist
-
getOptArray
default Optional<JsArray> getOptArray(JsPath path)
Returns the array located at the given path orOptional.empty()if it doesn't exist or it's not an array.- Parameters:
path- the path- Returns:
- the JsArray located at the given JsPath wrapped in an Optional
-
getArray
default JsArray getArray(JsPath path)
Returns the array located at the given path or null if it doesn't exist or it's not an array.- Parameters:
path- the path- Returns:
- the JsArray located at the given JsPath or null
-
getOptBigDec
default Optional<BigDecimal> getOptBigDec(JsPath path)
Returns the number located at the given path as a big decimal orOptional.empty()if it doesn't exist or it's not a decimal number.- Parameters:
path- the path- Returns:
- the number located at the given JsPath wrapped in an Optional
-
getBigDec
default BigDecimal getBigDec(JsPath path)
Returns the number located at the given path as a big decimal or null if it doesn't exist or it's not a decimal number.- Parameters:
path- the path- Returns:
- the number located at the given JsPath or null
-
getOptBigInt
default Optional<BigInteger> getOptBigInt(JsPath path)
Returns the number located at the given path as a big integer orOptional.empty()if it doesn't exist or it's not an integral number.- Parameters:
path- the path- Returns:
- the BigInteger located at the given JsPath wrapped in an Optional
-
getBigInt
default BigInteger getBigInt(JsPath path)
Returns the number located at the given path as a big integer or null if it doesn't exist or it's not an integral number.- Parameters:
path- the path- Returns:
- the BigInteger located at the given JsPath or null
-
getOptBool
default Optional<Boolean> getOptBool(JsPath path)
Returns the boolean located at the given path orOptional.empty()if it doesn't exist.- Parameters:
path- the path- Returns:
- the Boolean located at the given JsPath wrapped in an Optional
-
getBool
default Boolean getBool(JsPath path)
Returns the boolean located at the given path or null if it doesn't exist.- Parameters:
path- the path- Returns:
- the Boolean located at the given JsPath or null
-
getOptDouble
default OptionalDouble getOptDouble(JsPath path)
Returns the decimal number located at the given path as a double orOptionalDouble.empty()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 inBigDecimal.doubleValue()and in some cases it can lose information about the precision of the BigDecimal- Parameters:
path- the path- Returns:
- the decimal number located at the given JsPath wrapped in an OptionalDouble
-
getDouble
default Double getDouble(JsPath path)
Returns the decimal number located at the given path 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 inBigDecimal.doubleValue()and in some cases it can lose information about the precision of the BigDecimal- Parameters:
path- the path- Returns:
- the decimal number located at the given JsPath or null
-
getOptInt
default OptionalInt getOptInt(JsPath path)
Returns the integral number located at the given path as an integer orOptionalInt.empty()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:
path- the path- Returns:
- the integral number located at the given JsPath wrapped in an OptionalInt
-
getInt
default Integer getInt(JsPath path)
Returns the integral number located at the given path 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:
path- the path- Returns:
- the integral number located at the given JsPath or null
-
getOptLong
default OptionalLong getOptLong(JsPath path)
Returns the integral number located at the given path as a long orOptionalLong.empty()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:
path- the path- Returns:
- the integral number located at the given JsPath wrapped in an OptionalLong
-
getLong
default Long getLong(JsPath path)
Returns the integral number located at the given path 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:
path- the path- Returns:
- the integral number located at the given JsPath or null
-
getOptObj
default Optional<JsObj> getOptObj(JsPath path)
Returns the object located at the given path orOptional.empty()if it doesn't exist or it's not an object.- Parameters:
path- the path- Returns:
- the JsObj located at the given JsPath wrapped in an Optional
-
getObj
default JsObj getObj(JsPath path)
Returns the object located at the given path or null if it doesn't exist or it's not an object.- Parameters:
path- the path- Returns:
- the JsObj located at the given JsPath or null
-
getOptStr
default Optional<String> getOptStr(JsPath path)
Returns the string located at the given path orOptional.empty()if it doesn't exist or it's not an string.- Parameters:
path- the path- Returns:
- the JsStr located at the given path wrapped in an Optional
-
getStr
default String getStr(JsPath path)
Returns the string located at the given path or null if it doesn't exist or it's not an string.- Parameters:
path- the path- Returns:
- the JsStr located at the given path or null
-
ifEmptyElse
default <A> A ifEmptyElse(Supplier<A> emptySupplier, Supplier<A> nonemptySupplier)
Declarative way of implementing if(this.isEmpty()) return emptySupplier.get() else return nonEmptySupplier.get()- Type Parameters:
A- the type of the result- Parameters:
emptySupplier- Supplier that will produce the result if this json is emptynonemptySupplier- Supplier that will produce the result if this json is not empty- Returns:
- an object of type A
-
isEmpty
boolean isEmpty()
return true if there's no element in this json- Returns:
- true if empty, false otherwise
-
isNotEmpty
default boolean isNotEmpty()
return true if this json it not empty- Returns:
- false if empty, true otherwise
-
map
default T map(UnaryOperator<T> fn)
-
mapValues
T mapValues(Function<? super JsPair,? extends JsValue> fn)
Maps the values in the first level of this json.- Parameters:
fn- the mapping function- Returns:
- a new mapped json of the same type T
- See Also:
to map jsons,to map keys of json objects,to map all the values and not only the first level
-
mapValues
T mapValues(Function<? super JsPair,? extends JsValue> fn, Predicate<? super JsPair> predicate)
Maps the values in the first level of this json that satisfies a given predicate.- Parameters:
fn- the mapping functionpredicate- the given predicate that determines what JsValues will be mapped- Returns:
- same this instance or a new mapped json of the same type T
- See Also:
to map jsons,to map keys of json objects,to map all the values and not only the first level
-
mapAllValues
T mapAllValues(Function<? super JsPair,? extends JsValue> fn)
Maps all the values of this json.- Parameters:
fn- the mapping function- Returns:
- a new mapped json of the same type T
- See Also:
to map jsons,to map keys of json objects,to map only the first level
-
mapAllValues
T mapAllValues(Function<? super JsPair,? extends JsValue> fn, Predicate<? super JsPair> predicate)
Maps all the values of this json that satisfies a given predicate.- Parameters:
fn- the mapping functionpredicate- the given predicate that determines what JsValues will be mapped- Returns:
- same this instance or a new mapped json of the same type TT
- See Also:
to map jsons,to map keys of json objects,to map only the first level
-
mapKeys
T mapKeys(Function<? super JsPair,String> fn)
Maps the keys in the first level of this json.- Parameters:
fn- the mapping function- Returns:
- a new mapped json of the same type T
- See Also:
to map values,to map jsons,to map all the keys and not only the first level
-
mapKeys
T mapKeys(Function<? super JsPair,String> fn, Predicate<? super JsPair> predicate)
Maps the keys in the first level of this json that satisfies a given predicate.- Parameters:
fn- the mapping functionpredicate- the given predicate that determines what keys will be mapped- Returns:
- same this instance or a new mapped json of the same type T
- See Also:
to map jsons,to map values,to map all the keys and not only the first level
-
mapAllKeys
T mapAllKeys(Function<? super JsPair,String> fn)
Maps all the keys of this json.- Parameters:
fn- the mapping function- Returns:
- a new mapped json of the same type T
- See Also:
to map values,to map jsons,to map only the first level
-
mapAllKeys
T mapAllKeys(Function<? super JsPair,String> fn, Predicate<? super JsPair> predicate)
Maps all the keys of this json that satisfies a given predicate.- Parameters:
fn- the mapping functionpredicate- the given predicate that determines what keys will be mapped- Returns:
- same this instance or a new mapped json of the same type T
- See Also:
to map values,to map jsons,to map only the first level
-
mapObjs
T mapObjs(BiFunction<? super JsPath,? super JsObj,JsObj> fn, BiPredicate<? super JsPath,? super JsObj> predicate)
Maps the jsons in the first level of this json that satisfies a given predicate.- Parameters:
fn- the mapping functionpredicate- the given predicate that determines what Jsons will be mapped- Returns:
- same this instance or a new mapped json of the same type T
- See Also:
to map values,to map keys of json objects,to map all the jsons and not only the first level
-
mapObjs
T mapObjs(BiFunction<? super JsPath,? super JsObj,JsObj> fn)
Maps the jsons in the first level of this json.- Parameters:
fn- the mapping function- Returns:
- a new mapped json of the same type T
- See Also:
to map values,to map keys of json objects,to map all the jsons and not only the first level
-
mapAllObjs
T mapAllObjs(BiFunction<? super JsPath,? super JsObj,JsObj> fn, BiPredicate<? super JsPath,? super JsObj> predicate)
Maps all the jsons of this json that satisfies a given predicate.- Parameters:
fn- the mapping functionpredicate- the given predicate that determines what Jsons will be mapped- Returns:
- same this instance or a new mapped json of the same type T
- See Also:
to map values,to map keys of json objects,to map only the first level
-
mapAllObjs
T mapAllObjs(BiFunction<? super JsPath,? super JsObj,JsObj> fn)
Maps all the jsons of this json.- Parameters:
fn- the mapping function- Returns:
- a new mapped json of the same type T
- See Also:
to map values,to map keys of json objects,to map only the first level
-
prepend
default T prepend(JsPath path, JsValue elem, JsValue... others)
prepends one or more elements, starting from the first, to the array located at the path in this json. If the array at the path doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the JsPath pointing to the array in which all the elements will be prependedelem- the first JsElem to be prepended to the existing or created arrayothers- more optional JsElem to be prepended- Returns:
- same this instance or a new json of the same type T
-
prepend
T prepend(JsPath path, JsValue elem)
prepends one element to the array located at the path in this json. If the array at the path doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the JsPath pointing to the array in which the element will be prependedelem- the JsElem to be prepended to the existing or created array- Returns:
- same this instance or a new json of the same type T
-
prepend
default T prepend(JsPath path, String elem, String... others)
Prepends one or more strings, starting from the first, to the array located at the path in this json. If the array at the path doesn't exist, a new one is created, replacing any existing element and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the path-like string pointing to the array in which all the string will be prependedelem- the first string to be prepended to the existing or created arrayothers- more optional strings to be prepended- Returns:
- same this instance or a new json of the same type T
-
prepend
default T prepend(JsPath path, int elem, int... others)
prepends one or more integers, starting from the first, to the array located at the path in this json. If the array at the path doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the JsPath pointing to the array in which all the integers will be prependedelem- the first integer to be prepended to the existing or created arrayothers- more optional integers to be prepended- Returns:
- same this instance or a new json of the same type T
-
prepend
default T prepend(JsPath path, long elem, long... others)
prepends one or more longs, starting from the first, to the array located at the path in this json. If the array at the path doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the JsPath pointing to the array in which all the longs will be prependedelem- the first long to be prepended to the existing or created arrayothers- more optional longs to be prepended- Returns:
- same this instance or a new json of the same type T
-
prepend
default T prepend(JsPath path, boolean elem, boolean... others)
prepends one or more booleans, starting from the first, to the array located at the path in this json. If the array at the path doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the JsPath pointing to the array in which all the booleans will be prependedelem- the first boolean to be prepended to the existing or created arrayothers- more optional booleans to be prepended- Returns:
- same this instance or a new json of the same type T
-
prepend
default T prepend(JsPath path, double elem, double... others)
prepends one or more doubles, starting from the first, to the array located at the path in this json. If the array at the path doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the JsPath pointing to the array in which all the doubles will be prependedelem- the first double to be prepended to the existing or created arrayothers- more optional doubles to be prepended- Returns:
- same this instance or a new json of the same type T
-
prependAll
T prependAll(JsPath path, JsArray elems)
prepends all the elements of the array, starting from the head, to the array located at the path in this json. If the array at the path doesn't exist, a new one is created, replacing any existing element in the path and filling empty indexes in arrays withJsNullwhen necessary. The same this instance is returned when it's an array and the head of the path is a key or when it's an object and the head of the path is an index.- Parameters:
path- the JsPath pointing to the array in which all the elements will be prependedelems- the JsArray of elements to be prepended to the existing or created array- Returns:
- same this instance or a new json of the same type T
-
prependAllIfPresent
default T prependAllIfPresent(JsPath path, Supplier<JsArray> supplier)
Prepends all the elements of the array computed by the supplier, starting from the head, to the array located at the path in this json, returning the same this instance if the array is not present, in which case, the supplier is not invoked.- Parameters:
path- the JsPath object pointing to the existing array in which all the elements will be prependedsupplier- the supplier of the array of elements that will be prepended- Returns:
- same this instance or a new json of the same type T
-
prependIfPresent
default T prependIfPresent(JsPath path, Supplier<JsValue> supplier)
Prepends one element given by a supplier, to the array located at the given path in this json, returning the same this instance if the array is not present. The supplier is not applied if there's no array at the specified path.- Parameters:
path- the JsPath pointing to the existing array in which all the elements will be appendedsupplier- the given supplier- Returns:
- same this instance or a new json of the same type T
-
prependIfPresent
default T prependIfPresent(JsPath path, int number, int... others)
Prepends one or more integers to the array located at the given path in this json in the following order [number, others, existing elements], returning the same this instance if the array is not present.- Parameters:
path- the path pointing to the existing array in which the integers will be prependednumber- the integer to be prependedothers- more optional integers to be prepended- Returns:
- same this instance or a new json of the same type T
-
prependIfPresent
default T prependIfPresent(JsPath path, long number, long... others)
Prepends one or more longs to the array located at the given path in this json in the following order [number, others, existing elements], returning the same this instance if the array is not present.- Parameters:
path- the path pointing to the existing array in which the longs will be prependednumber- the long to be prependedothers- more optional longs to be prepended- Returns:
- same this instance or a new json of the same type T
-
prependIfPresent
default T prependIfPresent(JsPath path, double number, double... others)
Prepends one or more doubles to the array located at the given path in this json in the following order [number, others, existing elements], returning the same this instance if the array is not present.- Parameters:
path- the path pointing to the existing array in which the doubles will be prependednumber- the double to be prependedothers- more optional doubles to be prepended- Returns:
- same this instance or a new json of the same type T
-
prependIfPresent
default T prependIfPresent(JsPath path, String str, String... others)
Prepends one or more strings to the array located at the given path in this json in the following order [number, others, existing elements], returning the same this instance if the array is not present.- Parameters:
path- the path pointing to the existing array in which the strings will be prependedstr- the string to be prependedothers- more optional strings to be prepended- Returns:
- same this instance or a new json of the same type T
-
prependIfPresent
default T prependIfPresent(JsPath path, boolean bool, boolean... others)
Prepends one or more booleans to the array located at the given path in this json in the following order [number, others, existing elements], returning the same this instance if the array is not present.- Parameters:
path- the path pointing to the existing array in which the booleans will be prependedbool- the boolean to be prependedothers- more optional booleans to be prepended- Returns:
- same this instance or a new json of the same type T
-
put
T put(JsPath path, Function<? super JsValue,? extends JsValue> fn)
Inserts the element returned by the function at the given path in this json, replacing any existing element and filling withJsNullempty indexes in arrays when necessary. The same instance is returned when the path is empty, or 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. In both cases the function is not invoked. The same instance is returned as well when the element returned by the function isJsNothing- Parameters:
path- the JsPath object where the JsElem will be inserted atfn- the function that takes as an input the JsElem at the path and produces the JsElem to be inserted at the path- Returns:
- the same instance or a new json of the same type T
-
put
default T put(JsPath path, JsValue element)
Inserts the element at the path in this json, replacing any existing element and filling withJsNullempty 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- Parameters:
path- the JsPath object where the element will be inserted atelement- the JsElem that will be inserted- Returns:
- the same instance or a new json of the same type T
-
put
default T put(JsPath path, int n)
Inserts the integer number at the path in this json, replacing any existing element and filling withJsNullempty 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 isJsNothing- Parameters:
path- the path where the integer number will be inserted atn- the integer that will be inserted- Returns:
- the same instance or a new json of the same type T
-
put
default T put(JsPath path, long n)
Inserts the long number at the path in this json, replacing any existing element and filling withJsNullempty 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 isJsNothing- Parameters:
path- the path where the long number will be inserted atn- the long number that will be inserted- Returns:
- the same instance or a new json of the same type T
-
put
default T put(JsPath path, String str)
Inserts the string at the given path in this json, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the path where the string will be inserted atstr- the string that will be inserted- Returns:
- the same instance or a new json of the same type T
-
put
default T put(JsPath path, BigInteger bigint)
Inserts the big integer number at the given path in this json, replacing any existing element in teh path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given path where the big integer number will be inserted atbigint- the big integer number that will be inserted- Returns:
- the same instance or a new json of the same type T
-
put
default T put(JsPath path, BigDecimal bigdecimal)
Inserts the big decimal number at the given path in this json, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given path where the big decimal number will be inserted atbigdecimal- the big decimal number that will be inserted- Returns:
- the same instance or a new json of the same type T
-
put
default T put(JsPath path, boolean bool)
Inserts the boolean at the given path in this json, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given path where the boolean will be inserted atbool- the boolean that will be inserted- Returns:
- the same instance or a new json of the same type T
-
putIf
default T putIf(Predicate<? super JsValue> predicate, JsPath path, Function<? super JsValue,? extends JsValue> fn)
Inserts at the given path in this json, if the existing element satisfies the predicate, a new element returned by the function. If the predicate evaluates to false, the function is not computed. If the function returnsJsNothing, the same this instance is returned.- Parameters:
predicate- the predicate on which the existing element is tested onpath- the JsPath objectfn- the function witch computes the new element if the existing one satisfies the given predicate- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, Supplier<? extends JsValue> supplier)
Inserts at the given path in this json, if no element is present, the element returned by the supplier, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary. The supplier is not invoked if the element is present.- Parameters:
path- the given JsPath objectsupplier- the supplier which computes the new JsElem if absent- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, int number)
Inserts at the given path in this json, if no element is present, the specified integer, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given JsPath objectnumber- the specified integer- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, long number)
Inserts at the given path in this json, if no element is present, the specified long, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given JsPath objectnumber- the specified long- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, JsObj obj)
Inserts at the given path in this json, if no element is present, the specified object, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given JsPath objectobj- the specified object- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, JsArray array)
Inserts at the given path in this json, if no element is present, the specified array, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given JsPath objectarray- the specified array- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, double number)
Inserts at the given path in this json, if no element is present, the specified double, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given JsPath objectnumber- the specified double- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, String str)
Inserts at the given path in this json, if no element is present, the specified string, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given JsPath objectstr- the specified String- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, boolean bool)
Inserts at the given path in this json, if no element is present, the specified boolean, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given JsPath objectbool- the specified boolean- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, BigDecimal number)
Inserts at the given path in this json, if no element is present, the specified number, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given JsPath objectnumber- the specified number- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, BigInteger number)
Inserts at the given path in this json, if no element is present, the specified number, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given JsPath objectnumber- the specified number- Returns:
- the same instance or a new json of the same type T
-
putIfAbsent
default T putIfAbsent(JsPath path, JsValue value)
Inserts at the given path in this json, if no element is present, the specified json value, replacing any existing element in the path and filling withJsNullempty positions in arrays when necessary.- Parameters:
path- the given JsPath objectvalue- the specified json value- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, int number)
Inserts at the given path in this json, if some element is present, the specified integer.- Parameters:
path- the given pathnumber- the specified integer- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, JsObj obj)
Inserts at the given path in this json, if some element is present, the specified integer.- Parameters:
path- the given pathobj- the specified object- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, JsArray array)
Inserts at the given path in this json, if some element is present, the specified integer.- Parameters:
path- the given patharray- the specified array- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, long number)
Inserts at the given path in this json, if some element is present, the specified long.- Parameters:
path- the given pathnumber- the specified long- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, double number)
Inserts at the given path in this json, if some element is present, the specified double.- Parameters:
path- the given pathnumber- the specified double- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, String str)
Inserts at the given path in this json, if some element is present, the specified string.- Parameters:
path- the given pathstr- the specified string- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, boolean bool)
Inserts at the given path in this json, if some element is present, the specified boolean.- Parameters:
path- the given pathbool- the specified boolean- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, BigInteger number)
Inserts at the given path in this json, if some element is present, the specified big integer.- Parameters:
path- the given pathnumber- the specified big integer- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, BigDecimal number)
Inserts at the given path in this json, if some element is present, the specified big decimal.- Parameters:
path- the given pathnumber- the specified big decimal- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, JsValue value)
Inserts at the given path in this json, if some element is present, the specified value.- Parameters:
path- the given pathvalue- the specified value- Returns:
- the same instance or a new json of the same type T
-
putIfPresent
default T putIfPresent(JsPath path, Function<? super JsValue,? extends JsValue> fn)
Inserts at the given path in this json, if some element is present, the element returned by the function.- Parameters:
path- the given JsPath objectfn- the function which computes the new JsElem from the existing one- Returns:
- the same instance or a new json of the same type T
-
reduce
<R> Optional<R> reduce(BinaryOperator<R> op, Function<? super JsPair,R> map, Predicate<? super JsPair> 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 Rmap- the mapping function which produces an object of type R from a JsValuepredicate- the predicate that determines what JsValue will be mapped and reduced- Returns:
- an
Optionaldescribing the of of the reduction - See Also:
to apply the reduction in all the Json and not only in the first level
-
reduceAll
<R> Optional<R> reduceAll(BinaryOperator<R> op, Function<? super JsPair,R> map, Predicate<? super JsPair> predicate)
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- Type Parameters:
R- the type of the operands of the operator- Parameters:
op- the operator upon two objects of type Rmap- the mapping function which produces an object of type R from a JsValuepredicate- the predicate that determines what JsValue will be mapped and reduced- Returns:
- an
Optionaldescribing the result of the reduction - See Also:
to apply the reduction only in the first level
-
remove
T remove(JsPath path)
Removes the element in this json located at the given path, if it exists, returning the same this instance otherwise- Parameters:
path- the given JsPath object- Returns:
- a json of the same type T
-
size
int size()
Returns the number of elements in the first level of this json- Returns:
- the number of elements in the first level of this json
-
size
default OptionalInt size(JsPath path)
Returns the size of the json located at the given path in this json or OptionalInt.empty() if it doesn't exist or it's not a Json- Parameters:
path- the given JsPath object- Returns:
- an OptionalInt
-
sizeAll
default int sizeAll()
Returns the number of all the elements in this json- Returns:
- the number of all the elements in this json
-
sizeAll
default OptionalInt sizeAll(JsPath path)
Returns the number of all the elements of the json located at the given path in this json or OptionalInt.empty() if it doesn't exist or it's not a Json- Parameters:
path- the given JsPath object- Returns:
- an OptionalInt
-
stream
Stream<JsPair> stream()
Returns a stream over the pairs of elements in the first level of this json object.- Returns:
- a
Streamover all the JsPairs in the first level of this json
-
streamAll
Stream<JsPair> streamAll()
Returns a stream over all the pairs of elements in this json object.- Returns:
- a
Streamover all the JsPairs in this json
-
times
default long times(JsValue e)
-
timesAll
default long timesAll(JsValue e)
-
serialize
default void serialize(OutputStream ouputstream) throws SerializerException
Serializes this Json into the given output stream, no returning anything- Parameters:
ouputstream- the output stream- Throws:
SerializerException
-
serialize
default byte[] serialize() throws SerializerExceptionSerialize this Json into an array of bytes. When possible, it's more efficient to work on byte level that with strings- Returns:
- this Json serialized into an array of bytes
- Throws:
SerializerException
-
-