public final class JsArray extends Object implements Json<JsArray>, Iterable<JsValue>
A JsArray
is a collection of JSON values arranged in an ordered sequence. It allows for easy manipulation of JSON arrays, such as adding, updating, or removing elements, while preserving immutability. This class is designed to be used for creating and working with JSON arrays in a functional and safe manner.
JsArray
implements the Json
interface, which allows it to seamlessly integrate with other JSON-related classes and operations.
As a persistent data structure, modifications to a JsArray
result in a new instance being created, leaving the original array unchanged. This immutability ensures safe concurrent access and simplifies handling of JSON data.
Modifier and Type | Class and Description |
---|---|
static class |
JsArray.TYPE
Enumeration representing different types of arrays: SET, LIST, or MULTISET.
|
Modifier and Type | Field and Description |
---|---|
static JsOptics.JsArrayLenses |
lens
Provides a set of optics (lenses) for working with JSON arrays.
|
static JsOptics.JsArrayOptionals |
optional
Provides a set of optional optics for working with JSON arrays.
|
static fun.optic.Prism<JsValue,JsArray> |
prism
|
Modifier and Type | Method and Description |
---|---|
JsArray |
append(JsValue e,
JsValue... others)
Appends one or more
JsValue elements to the end of this JSON array. |
JsArray |
appendAll(JsArray array)
Appends all elements from another
JsArray to the end of this JSON array. |
boolean |
containsValue(JsValue el)
Checks if this JSON contains the given value in its first level.
|
JsArray |
delete(int index)
Deletes the element at the specified index from this
JsArray . |
JsArray |
delete(JsPath path)
Removes the element at the specified path within this immutable JSON object, if it exists.
|
static JsArray |
empty()
Returns the singleton empty JSON array
|
boolean |
equals(JsArray array,
JsArray.TYPE ARRAY_AS)
Checks if this JSON array is equal to another JSON array.
|
boolean |
equals(Object that) |
JsArray |
filterKeys(BiPredicate<? super JsPath,? super JsValue> filter)
Filters all the keys of this json, removing those that don't satisfy the given predicate.
|
JsArray |
filterKeys(Predicate<? super String> filter)
Filters all the keys of this json, removing those that don't ifPredicateElse the predicate.
|
JsArray |
filterObjs(BiPredicate<? super JsPath,? super JsObj> filter)
Filters all the pair of jsons of this json, removing those that don't satisfy the given predicate.
|
JsArray |
filterObjs(Predicate<? super JsObj> filter)
Filters all the pair of jsons of this json, removing those that don't ifPredicateElse the predicate.
|
JsArray |
filterValues(BiPredicate<? super JsPath,? super JsPrimitive> filter)
Filters all the pairs of elements of this json, removing those that don't satisfy the given predicate.
|
JsArray |
filterValues(Predicate<? super JsPrimitive> filter)
Filters all the pairs of elements of this json, removing those that don't ifPredicateElse the predicate.
|
JsValue |
get(int i)
Returns the element located at the specified index or
JsNothing if it doesn't exist. |
JsValue |
get(JsPath path)
Gets the value located at the given path or
JsNothing if it doesn't exist. |
JsArray |
getArray(int index)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as a JSON array (JsArray).
|
JsArray |
getArray(int index,
Supplier<JsArray> orElse)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as a JSON array (JsArray).
|
BigDecimal |
getBigDec(int index)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as a decimal number, returning it as a BigDecimal.
|
BigDecimal |
getBigDec(int index,
Supplier<BigDecimal> orElse)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as a decimal number, returning it as a BigDecimal.
|
BigInteger |
getBigInt(int index)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as an integral number, returning it as a BigInteger.
|
BigInteger |
getBigInt(int index,
Supplier<BigInteger> orElse)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as an integral number, returning it as a BigInteger.
|
byte[] |
getBinary(int index)
Retrieves the binary data located at the specified index within the JSON-like array and returns it as an array of bytes.
|
byte[] |
getBinary(int index,
Supplier<byte[]> orElse)
Retrieves the binary data located at the specified index within the JSON-like array and returns it as an array of bytes.
|
Boolean |
getBool(int index)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as a boolean.
|
Boolean |
getBool(int index,
Supplier<Boolean> orElse)
Retrieves the boolean value located at the specified index within the JSON-like array and returns it.
|
Double |
getDouble(int index)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as a decimal number, converting it to a double.
|
Double |
getDouble(int index,
Supplier<Double> orElse)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as a decimal number, converting it to a double.
|
Instant |
getInstant(int index)
Returns the instant located at the given index as an
Instant or null if it doesn't exist or
is not a valid instant representation. |
Instant |
getInstant(int index,
Supplier<Instant> orElse)
|
Integer |
getInt(int index)
Returns the integral number located at the given index 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.
|
Integer |
getInt(int index,
Supplier<Integer> orElse)
Returns the integral number located at the given index as an integer or a default value 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.
|
Long |
getLong(int index)
Returns the integral number located at the given index 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.
|
Long |
getLong(int index,
Supplier<Long> orElse)
Returns the integral number located at the given index as a long or a default value provided by the
orElse
supplier 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(int index)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as a JSON object (JsObj).
|
JsObj |
getObj(int index,
Supplier<JsObj> orElse)
Retrieves the value located at the specified index within the JSON-like array and attempts to
interpret it as a JSON object (JsObj).
|
String |
getStr(int index)
Returns the string located at the given index or
null if it doesn't exist or it's not a string. |
String |
getStr(int index,
Supplier<String> orElse)
Returns the string located at the given index or a default value supplied by the provided
orElse function
if it doesn't exist or is not a string. |
int |
hashCode()
equals method is inherited, so it's implemented.
|
JsValue |
head()
Returns the first element of this array.
|
JsArray |
init()
Returns all the elements of this array except the last one.
|
JsArray |
intersection(JsArray that,
JsArray.TYPE ARRAY_AS)
this.union(that, SET) returns this plus those elements from that that
don't exist in this . |
boolean |
isArray()
Returns true if this JsValue is a JsArray.
|
boolean |
isEmpty()
Determines whether this Json instance is empty, i.e., it contains no elements.
|
Iterator<JsValue> |
iterator() |
JsValue |
last()
Returns the last element of this array.
|
JsArray |
mapKeys(BiFunction<? super JsPath,? super JsValue,String> fn)
Maps all the keys of this JSON object, recursively traversing the entire JSON structure.
|
JsArray |
mapKeys(Function<? super String,String> fn)
Maps all the keys of this JSON object, recursively traversing the entire JSON structure.
|
JsArray |
mapObjs(BiFunction<? super JsPath,? super JsObj,? extends JsValue> fn)
Maps all the JSON objects of this JSON, traversing the entire JSON if necessary.
|
JsArray |
mapObjs(Function<? super JsObj,? extends JsValue> fn)
Maps all the JSON objects of this JSON, traversing the entire JSON if necessary.
|
JsArray |
mapValues(BiFunction<? super JsPath,? super JsPrimitive,? extends JsValue> fn)
Recursively maps all the values of this JSON, replacing each value with the result of applying the given mapping function.
|
JsArray |
mapValues(Function<? super JsPrimitive,? extends JsValue> fn)
Recursively maps all the values of this JSON, replacing each value with the result of applying the given mapping function.
|
static JsArray |
of(BigInteger number,
BigInteger... others)
Creates a new
JsArray containing the specified BigInteger elements. |
static JsArray |
of(boolean bool,
boolean... others)
Creates a new
JsArray containing the specified boolean elements. |
static JsArray |
of(double number,
double... others)
Creates a new
JsArray containing the specified double elements. |
static JsArray |
of(int number,
int... others)
Creates a new
JsArray containing the specified integer elements. |
static JsArray |
of(JsValue e,
JsValue... rest)
Creates a new
JsArray containing the specified elements. |
static JsArray |
of(long number,
long... others)
Creates a new
JsArray containing the specified long elements. |
static JsArray |
of(String str,
String... others)
Creates a new
JsArray containing the specified string elements. |
static JsArray |
ofIterable(Iterable<? extends JsValue> iterable)
|
static JsArray |
parse(byte[] bytes)
Parses a JSON array represented as a byte array and returns a new
JsArray instance. |
static JsArray |
parse(String str)
Parses a JSON array represented as a string and returns a new
JsArray instance. |
JsArray |
prepend(JsValue e,
JsValue... others)
Adds one or more elements, starting from the last, to the front of this array.
|
JsArray |
prependAll(JsArray array)
Adds all the elements of the
JsArray , starting from the last, to the front of this array. |
<R> Optional<R> |
reduce(BinaryOperator<R> op,
BiFunction<? super JsPath,? super JsPrimitive,R> map,
BiPredicate<? super JsPath,? super JsPrimitive> predicate)
Reduces the values of this JSON object that satisfy the given predicate, allowing access to the element's path.
|
<R> Optional<R> |
reduce(BinaryOperator<R> op,
Function<? super JsPrimitive,R> map,
Predicate<? super JsPrimitive> predicate)
Reduces the values of this JSON object that satisfy the given predicate.
|
JsArray |
set(int index,
JsValue element) |
JsArray |
set(int index,
JsValue value,
JsValue padElement)
Sets the value at the specified index within the JSON-like array to the provided JsValue.
|
JsArray |
set(JsPath path,
JsValue element)
Inserts the given element at the specified path in this JSON, replacing any existing element.
|
JsArray |
set(JsPath path,
JsValue value,
JsValue padElement)
Inserts an element at the specified path in this JSON, replacing any existing element.
|
int |
size()
Returns the number of elements in the first level of this JSON object or array.
|
Stream<JsPair> |
stream()
Returns a stream over all the key-value pairs
JsPair of elements in this JSON object. |
Stream<JsValue> |
streamOfValues()
Returns a non-recursive stream of values contained within the JSON-like array.
|
JsArray |
tail()
Returns a JSON array consisting of all elements of this array except the first one.
|
String |
toString()
// Single-check idiom Item 83 from effective java
|
JsArray |
union(JsArray that,
JsArray.TYPE ARRAY_AS)
Computes the union of this JSON and another JSON object 'that' with respect to the given array merging strategy.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
containsPath, equals, getArray, getArray, getBigDec, getBigDec, getBigInt, getBigInt, getBinary, getBinary, getBool, getBool, getDouble, getDouble, getInstant, getInstant, getInt, getInt, getLong, getLong, getObj, getObj, getStr, getStr, ifEmptyElse, isNotEmpty, serialize, serialize, toJsPrimitive, toPrettyString, toPrettyString
ifNothing, ifNull, isArray, isBigDec, isBigDec, isBigInt, isBigInt, isBinary, isBool, isDecimal, isDouble, isDouble, isFalse, isInstant, isInstant, isInt, isInt, isIntegral, isJson, isJson, isLong, isLong, isNothing, isNotNothing, isNotNull, isNotNumber, isNull, isNumber, isObj, isObj, isPrimitive, isSameType, isStr, isStr, isTrue, toJsArray, toJsBigDec, toJsBigInt, toJsBinary, toJsBool, toJsDouble, toJsInstant, toJsInt, toJsLong, toJsNumber, toJsObj, toJson, toJsStr
forEach, spliterator
public static final JsOptics.JsArrayLenses lens
The JsArrayLenses
class offers a collection of optics that allow you to focus on specific elements within a JSON array, making it easier to perform targeted modifications and transformations. These optics are designed to work seamlessly with the JsArray
class, enabling precise handling of JSON array data.
public static final JsOptics.JsArrayOptionals optional
The JsArrayOptionals
class offers a collection of optional optics that allow you to work with JSON arrays more flexibly. These optics provide ways to safely access and manipulate elements within a JSON array, taking into account the possibility of absent or missing elements.
public static JsArray empty()
public static JsArray of(JsValue e, JsValue... rest)
JsArray
containing the specified elements.
The of
method returns a new JsArray
instance with the specified elements in the order they
appear in the method's argument list. You can provide one or more JsValue
elements to include in the
resulting array.
e
- The first JsValue
element to include in the array.rest
- Additional JsValue
elements to include in the array (optional).JsArray
containing the specified elements.NullPointerException
- if any of the provided elements (including e
and rest
) are null.public static JsArray of(String str, String... others)
JsArray
containing the specified string elements.
The of
method returns a new JsArray
instance with the specified string elements in the order they
appear in the method's argument list. You can provide one or more strings to include in the resulting array.
Example usage:
// Creating a JsArray with specified string elements
JsArray array = JsArray.of("Hello", "World");
str
- The first string element to include in the array.others
- Additional string elements to include in the array (optional).JsArray
containing the specified string elements.NullPointerException
- if any of the provided string elements (including str
and others
) are null.public static JsArray of(int number, int... others)
JsArray
containing the specified integer elements.
The of
method returns a new JsArray
instance with the specified integer elements in the order they
appear in the method's argument list. You can provide one or more integers to include in the resulting array.
number
- The first integer element to include in the array.others
- Additional integer elements to include in the array (optional).JsArray
containing the specified integer elements.public static JsArray of(boolean bool, boolean... others)
JsArray
containing the specified boolean elements.
The of
method returns a new JsArray
instance with the specified boolean elements in the order they
appear in the method's argument list. You can provide one or more boolean values to include in the resulting array.
bool
- The first boolean element to include in the array.others
- Additional boolean elements to include in the array (optional).JsArray
containing the specified boolean elements.public static JsArray of(long number, long... others)
JsArray
containing the specified long elements.
The of
method returns a new JsArray
instance with the specified long elements in the order they
appear in the method's argument list. You can provide one or more long values to include in the resulting array.
number
- The first long element to include in the array.others
- Additional long elements to include in the array (optional).JsArray
containing the specified long elements.public static JsArray of(BigInteger number, BigInteger... others)
JsArray
containing the specified BigInteger
elements.
The of
method returns a new JsArray
instance with the specified BigInteger
elements in the order they
appear in the method's argument list. You can provide one or more BigInteger
values to include in the resulting array.
number
- The first BigInteger
element to include in the array.others
- Additional BigInteger
elements to include in the array (optional).JsArray
containing the specified BigInteger
elements.public static JsArray of(double number, double... others)
JsArray
containing the specified double
elements.
The of
method returns a new JsArray
instance with the specified double
elements in the order they
appear in the method's argument list. You can provide one or more double
values to include in the resulting array.
number
- The first double
element to include in the array.others
- Additional double
elements to include in the array (optional).JsArray
containing the specified double
elements.public static JsArray parse(String str) throws JsParserException
JsArray
instance.
The parse
method takes a JSON array string as input, parses it, and returns a new JsArray
containing
the parsed JSON values. If the input string is not a valid JSON array representation, a JsParserException
is
thrown.
str
- The JSON array string to parse.JsArray
containing the parsed JSON values.JsParserException
- If the input string is not a valid JSON array representation.JsParserException
public static JsArray parse(byte[] bytes) throws JsParserException
JsArray
instance.
The parse
method takes a JSON array represented as a byte array, parses it, and returns a new JsArray
containing the parsed JSON values. If the input byte array does not represent a valid JSON array, a JsParserException
is thrown.
bytes
- The byte array representing the JSON array to parse.JsArray
containing the parsed JSON values.JsParserException
- If the input byte array does not represent a valid JSON array.JsParserException
public boolean equals(JsArray array, JsArray.TYPE ARRAY_AS)
The equals
method compares this JSON array to another JSON array to determine if they are equal.
Equality is defined based on the specified JsArray.TYPE
of array comparison.
If ARRAY_AS
is JsArray.TYPE.SET
, both arrays must contain the same elements (order doesn't matter, duplicates are ignored).
If ARRAY_AS
is JsArray.TYPE.LIST
, both arrays must have the same elements in the same order.
If ARRAY_AS
is JsArray.TYPE.MULTISET
, both arrays must contain the same elements (order doesn't matter, duplicates are counted).
array
- The JsArray
to compare to this array.ARRAY_AS
- The JsArray.TYPE
specifying the type of array comparison (SET, LIST, or MULTISET).true
if the arrays are equal according to the specified type, false
otherwise.JsArray.TYPE
public Integer getInt(int index)
This method retrieves the JSON value at the specified index in the array and attempts to parse it as an integral number.
If the value at the index is a valid integral number that can be represented as an integer, it is returned as an Integer
.
If the value is not an integral number or cannot fit in an integer, this method returns null
.
Example usage:
// Create a JSON array and retrieve an integral number as an integer
JsArray array = JsArray.of(1, 2, 3);
Integer value = array.getInt(1); // Returns 2
index
- The index of the JSON value to retrieve as an integer.Integer
, or null
if it doesn't exist or is not a valid integral number.public Integer getInt(int index, Supplier<Integer> orElse)
This method retrieves the JSON value at the specified index in the array and attempts to parse it as an integral number.
If the value at the index is a valid integral number that can be represented as an integer, it is returned as an Integer
.
If the value is not an integral number or cannot fit in an integer, the default value provided by the orElse
supplier
is returned.
index
- The index of the JSON value to retrieve as an integer.orElse
- A supplier that provides a default integer value to return if the JSON value at the index is not a valid integral number or cannot fit in an integer.Integer
, or the default value provided by orElse
if it doesn't exist or is not a valid integral number.JsArray
public Long getLong(int index)
This method retrieves the JSON value at the specified index in the array and attempts to parse it as an integral number.
If the value at the index is a valid integral number that can be represented as a long, it is returned as a Long
.
If the value is not an integral number or cannot fit in a long, null
is returned.
index
- The index of the JSON value to retrieve as a long.Long
, or null
if it doesn't exist or is not a valid integral number.public Long getLong(int index, Supplier<Long> orElse)
orElse
supplier 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.
This method retrieves the JSON value at the specified index in the array and attempts to parse it as an integral number.
If the value at the index is a valid integral number that can be represented as a long, it is returned as a Long
.
If the value is not an integral number or cannot fit in a long, the orElse
supplier is used to provide a default value.
index
- The index of the JSON value to retrieve as a long.orElse
- A Supplier
that provides the default value to return if the value at the given index is not a valid integral number or cannot fit in a long.Long
, or the default value provided by orElse
if it doesn't exist or is not a valid integral number.public String getStr(int index)
null
if it doesn't exist or it's not a string.
This method retrieves the JSON value at the specified index in the array and attempts to interpret it as a string.
If the value at the index is a string, it is returned as a String
. If the value is not a string,
or if it doesn't exist at the specified index, null
is returned.
index
- The index of the JSON value to retrieve as a string.null
if it doesn't exist or is not a string.public String getStr(int index, Supplier<String> orElse)
orElse
function
if it doesn't exist or is not a string.
This method retrieves the JSON value at the specified index in the array and attempts to interpret it as a string.
If the value at the index is a string, it is returned as a String
. If the value is not a string,
or if it doesn't exist at the specified index, the orElse
function is invoked to provide a default value.
index
- The index of the JSON value to retrieve as a string.orElse
- A Supplier<String>
providing a default value if the value is not a string or doesn't exist.orElse
if it doesn't exist or is not a string.public Instant getInstant(int index)
Instant
or null
if it doesn't exist or
is not a valid instant representation.
This method retrieves the JSON value at the specified index in the array and attempts to interpret it as
an instant. If the value at the index is a valid instant representation, it is returned as an Instant
.
If the value is not a valid instant representation, or if it doesn't exist at the specified index, null
is returned.
public Instant getInstant(int index, Supplier<Instant> orElse)
Instant
or a default Instant
provided by
the orElse
supplier if it doesn't exist or is not a valid instant representation.
This method retrieves the JSON value at the specified index in the array and attempts to interpret it as
an instant. If the value at the index is a valid instant representation, it is returned as an Instant
.
If the value is not a valid instant representation, or if it doesn't exist at the specified index, the default
Instant
provided by the orElse
supplier is returned.
index
- The index of the JSON value to retrieve as an Instant
.orElse
- A Supplier
providing the default Instant
to return if the value at the specified
index is not a valid instant representation or doesn't exist.Instant
, or the default Instant
provided
by the orElse
supplier if it doesn't exist or is not a valid instant representation.public byte[] getBinary(int index)
index
- The index at which to retrieve the binary data.public byte[] getBinary(int index, Supplier<byte[]> orElse)
index
- The index at which to retrieve the binary data.orElse
- A supplier function that provides a default value (an array of bytes) to be returned when the data does not
exist at the specified index or is not a valid binary representation.public Boolean getBool(int index)
index
- The index at which to retrieve the value.public Boolean getBool(int index, Supplier<Boolean> orElse)
index
- The index at which to retrieve the boolean value.orElse
- A supplier function that provides a default boolean value to be returned when the value does not exist at
the specified index or is not a valid boolean representation.public Double getDouble(int index)
The conversion process is designed to handle decimal numbers, but it's important to note that if the value is a BigDecimal, the conversion to a double may result in a potential loss of precision. BigDecimal numbers can represent decimal values with high precision, whereas double has limited precision. Therefore, when converting a BigDecimal to a double, there may be a loss of information beyond the double's precision, potentially leading to rounding or truncation.
index
- The index at which to retrieve the value.public Double getDouble(int index, Supplier<Double> orElse)
orElse
supplier.
The conversion process is designed to handle decimal numbers, but it's important to note that if the value is a BigDecimal, the conversion to a double may result in a potential loss of precision. BigDecimal numbers can represent decimal values with high precision, whereas double has limited precision. Therefore, when converting a BigDecimal to a double, there may be a loss of information beyond the double's precision, potentially leading to rounding or truncation.
index
- The index at which to retrieve the value.orElse
- A supplier providing the default double value to return if the value is not a decimal
number or the index doesn't exist.orElse
if it doesn't exist or the value at the index is not a decimal number.public BigDecimal getBigDec(int index)
index
- The index at which to retrieve the value.public BigDecimal getBigDec(int index, Supplier<BigDecimal> orElse)
index
- The index at which to retrieve the value.orElse
- A supplier function that provides a default BigDecimal value if the value at the
index is not a decimal number or the index doesn't exist.public BigInteger getBigInt(int index)
index
- The index at which to retrieve the value.public BigInteger getBigInt(int index, Supplier<BigInteger> orElse)
index
- The index at which to retrieve the value.orElse
- The default value to return if the value at the index is not an integral number
or if the index doesn't exist.public JsObj getObj(int index)
index
- The index at which to retrieve the value.public JsObj getObj(int index, Supplier<JsObj> orElse)
index
- The index at which to retrieve the value.orElse
- A supplier that provides the default JsObj if the index is out of bounds or the value
at the index is not a JSON object.public JsArray getArray(int index)
index
- The index at which to retrieve the value.public JsArray getArray(int index, Supplier<JsArray> orElse)
index
- The index at which to retrieve the value.orElse
- A Supplier that provides the default JsArray value if the index doesn't exist or
the value is not a JSON array.public boolean containsValue(JsValue el)
Json
containsValue
in interface Json<JsArray>
el
- The value to check for.public JsValue get(JsPath path)
Json
JsNothing
if it doesn't exist.public JsArray filterValues(BiPredicate<? super JsPath,? super JsPrimitive> filter)
Json
filterValues
in interface Json<JsArray>
filter
- the predicate which takes as input every JsPair of this jsonpublic JsArray filterValues(Predicate<? super JsPrimitive> filter)
Json
filterValues
in interface Json<JsArray>
filter
- the predicate which takes as the input every JsPair of this jsonpublic JsArray filterKeys(BiPredicate<? super JsPath,? super JsValue> filter)
Json
filterKeys
in interface Json<JsArray>
filter
- the predicate which takes as input every JsPair of this jsonpublic JsArray filterKeys(Predicate<? super String> filter)
Json
filterKeys
in interface Json<JsArray>
filter
- the predicate which takes as the input every JsPair of this jsonpublic JsArray filterObjs(BiPredicate<? super JsPath,? super JsObj> filter)
Json
filterObjs
in interface Json<JsArray>
filter
- the predicate which takes as input every JsPair of this jsonpublic JsArray filterObjs(Predicate<? super JsObj> filter)
Json
filterObjs
in interface Json<JsArray>
filter
- the predicate which takes as the input every JsPair of this jsonpublic boolean isEmpty()
Json
public JsArray mapValues(BiFunction<? super JsPath,? super JsPrimitive,? extends JsValue> fn)
Json
public JsArray mapValues(Function<? super JsPrimitive,? extends JsValue> fn)
Json
public JsArray mapKeys(BiFunction<? super JsPath,? super JsValue,String> fn)
Json
public JsArray mapKeys(Function<? super String,String> fn)
Json
public JsArray mapObjs(BiFunction<? super JsPath,? super JsObj,? extends JsValue> fn)
Json
public JsArray mapObjs(Function<? super JsObj,? extends JsValue> fn)
Json
public JsArray set(JsPath path, JsValue element)
Json
JsNull
. You have the option to use
Json.set(JsPath, JsValue, JsValue)
to specify a custom padding element.public JsArray set(int index, JsValue value, JsValue padElement)
index
- The index at which to set the value.value
- The JsValue to set at the specified index.padElement
- The JsValue to use for padding the array if necessary.public JsArray set(JsPath path, JsValue value, JsValue padElement)
Json
set
in interface Json<JsArray>
path
- The path to insert the element.value
- The element to insert.padElement
- The element to use for padding in arrays when necessary.public <R> Optional<R> reduce(BinaryOperator<R> op, BiFunction<? super JsPath,? super JsPrimitive,R> map, BiPredicate<? super JsPath,? super JsPrimitive> predicate)
Json
reduce
in interface Json<JsArray>
R
- the type of the reduction resultop
- the operator to apply to values of type Rmap
- the mapping function to convert JsPath and JsPrimitive to type Rpredicate
- the predicate that determines which values are included in the reductionOptional
describing the result of the reduction, or empty if no values satisfy the predicatepublic <R> Optional<R> reduce(BinaryOperator<R> op, Function<? super JsPrimitive,R> map, Predicate<? super JsPrimitive> predicate)
Json
reduce
in interface Json<JsArray>
R
- the type of the reduction resultop
- the operator to apply to values of type Rmap
- the mapping function to convert JsValue to type Rpredicate
- the predicate that determines which values are included in the reductionOptional
describing the result of the reduction, or empty if no values satisfy the predicatepublic JsArray delete(JsPath path)
Json
public int size()
Json
public Stream<JsPair> stream()
Json
JsPair
of elements in this JSON object.
This method provides a way to traverse and operate on the key-value pairs within the JSON object.public Stream<JsValue> streamOfValues()
for traversing recursively
public JsValue get(int i)
JsNothing
if it doesn't exist.
This method is a total function and never throws exceptions.public int hashCode()
public String toString()
public JsValue head()
public JsArray tail()
public JsArray init()
public JsArray intersection(JsArray that, JsArray.TYPE ARRAY_AS)
this.union(that, SET)
returns this
plus those elements from that
that
don't exist in this
.
this.union(that, MULTISET)
returns this
plus those elements from that
appended to the back.
this.union(that, LIST)
returns this
plus those elements from that
which
position is >= this.size()
. 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 intersectionintersection
in interface Json<JsArray>
that
- the other arrayARRAY_AS
- the array merging strategy, either 'MERGE' or 'REPLACE'public boolean isArray()
JsValue
public JsValue last()
public JsArray prepend(JsValue e, JsValue... others)
public JsArray prependAll(JsArray array)
JsArray
, starting from the last, to the front of this array.public JsArray delete(int index)
JsArray
.index
- The index of the element to be deleted.JsArray
with the element at the specified index removed.IllegalArgumentException
- if the index is negative.public JsArray union(JsArray that, JsArray.TYPE ARRAY_AS)
Json
Copyright © 2023. All rights reserved.