Modifier and Type | Class and Description |
---|---|
static class |
JsArray.TYPE
Type of arrays: SET, MULTISET or LIST.
|
Modifier and Type | Field and Description |
---|---|
static JsArray |
EMPTY |
static JsOptics.JsArrayLenses |
lens
lenses defined for a Json array
|
static JsOptics.JsArrayOptionals |
optional
optionals defined for a Json array
|
static fun.optic.Prism<JsValue,JsArray> |
prism
prism between the sum type JsValue and JsArray
|
static int |
TYPE_ID |
Constructor and Description |
---|
JsArray() |
Modifier and Type | Method and Description |
---|---|
JsArray |
append(JsValue e,
JsValue... others)
Adds one or more elements, starting from the first, to the back of this array.
|
JsArray |
appendAll(JsArray array)
Adds all the elements of the given array, starting from the head, to the back of this array.
|
boolean |
containsValue(JsValue el)
Returns true if this json contains the given element in the first level.
|
JsArray |
delete(int index) |
JsArray |
delete(JsPath path)
Removes the element in this json located at the given path, if it exists, returning the same this
instance otherwise
|
static JsArray |
empty() |
boolean |
equals(JsArray array,
JsArray.TYPE ARRAY_AS)
Returns true if this array is equal to the given as a parameter.
|
boolean |
equals(Object that) |
JsArray |
filterKeys(BiPredicate<? super JsPath,? super JsValue> filter)
Filters all the keys of this json, removing those that don't ifPredicateElse the 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 ifPredicateElse the 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 ifPredicateElse the 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)
Returns the element located at the given path or
JsNothing if it doesn't exist. |
JsArray |
getArray(int index)
Returns the array located at the given index or null if it doesn't exist or it's not a json array.
|
JsArray |
getArray(int index,
Supplier<JsArray> orElse)
Returns the array located at the given index or the default value provided if it doesn't exist
or it's not a json array.
|
BigDecimal |
getBigDec(int index)
Returns the number located at the given index as a big decimal or null if
it doesn't exist or it's not a decimal number.
|
BigDecimal |
getBigDec(int index,
Supplier<BigDecimal> orElse)
Returns the number located at the given index as a big decimal or the default value provided if
it doesn't exist or it's not a decimal number.
|
BigInteger |
getBigInt(int index)
Returns the number located at the given index as a big integer or null if
it doesn't exist or it's not an integral number.
|
BigInteger |
getBigInt(int index,
Supplier<BigInteger> orElse)
Returns the number located at the given index as a big integer or the default value provided
if it doesn't exist or it's not an integral number.
|
byte[] |
getBinary(int index)
Returns the array of bytes located at the given index or null if it doesn't exist or it's not an array of bytes.
|
byte[] |
getBinary(int index,
Supplier<byte[]> orElse)
Returns the array of bytes located at the given index or the default value provided if it doesn't exist or it's not an array of bytes.
|
Boolean |
getBool(int index)
Returns the boolean located at the given index or null if it doesn't exist.
|
Boolean |
getBool(int index,
Supplier<Boolean> orElse)
Returns the boolean located at the given index or the default value provided if it doesn't exist.
|
Double |
getDouble(int index)
Returns the number located at the given index as a double or null if it
doesn't exist or it's not a decimal number.
|
Double |
getDouble(int index,
Supplier<Double> orElse)
Returns the number located at the given index as a double or the default value provided if it
doesn't exist or it's not a decimal number.
|
Instant |
getInstant(int index)
Returns the instant located at the given index or null if it doesn't exist or it's not an instant.
|
Instant |
getInstant(int index,
Supplier<Instant> orElse)
Returns the instant located at the given index or the default value provided if it doesn't exist
or it's not an instant.
|
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 the default value provided if it
doesn't exist or it's not an integral number or it's an integral number but doesn't fit in an integer.
|
Long |
getLong(int index)
Returns the long number located at the given index as an 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 an long.
|
Long |
getLong(int index,
Supplier<Long> orElse)
Returns the long number located at the given index as an long or the default value provided if it
doesn't exist or it's not an integral number or it's an integral number but doesn't fit in an long.
|
JsObj |
getObj(int index)
Returns the object located at the given index or null if it doesn't exist or it's not a json object.
|
JsObj |
getObj(int index,
Supplier<JsObj> orElse)
Returns the object located at the given index or the default value provided if it doesn't exist or
it's not a json object.
|
String |
getStr(int index)
Returns the string located at the given index or null if it doesn't exist.
|
String |
getStr(int index,
Supplier<String> orElse)
Returns the string located at the given index or the default value provided
if it doesn't exist.
|
int |
hashCode()
equals method is inherited, so it's implemented.
|
JsValue |
head()
Returns the first element of this array.
|
int |
id() |
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()
return true if there's no element in this json
|
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.
|
JsArray |
mapKeys(Function<? super String,String> fn)
Maps all the keys of this json.
|
JsArray |
mapObjs(BiFunction<? super JsPath,? super JsObj,? extends JsValue> fn)
Maps all the jsons of this json.
|
JsArray |
mapObjs(Function<? super JsObj,? extends JsValue> fn)
Maps all the jsons of this json.
|
JsArray |
mapValues(BiFunction<? super JsPath,? super JsPrimitive,? extends JsValue> fn)
Maps all the values of this json.
|
JsArray |
mapValues(Function<? super JsPrimitive,? extends JsValue> fn)
Maps all the values of this json.
|
static JsArray |
of(BigInteger number,
BigInteger... others)
Returns an immutable array from one or more big integers.
|
static JsArray |
of(boolean bool,
boolean... others)
Returns an immutable array from one or more booleans.
|
static JsArray |
of(double number,
double... others)
Returns an immutable array from one or more doubles.
|
static JsArray |
of(int number,
int... others)
Returns an immutable array from one or more integers.
|
static JsArray |
of(JsValue e) |
static JsArray |
of(JsValue e,
JsValue e1)
Returns an immutable two-element array.
|
static JsArray |
of(JsValue e,
JsValue e1,
JsValue e2)
Returns an immutable three-element array.
|
static JsArray |
of(JsValue e,
JsValue e1,
JsValue e2,
JsValue e3)
Returns an immutable four-element array.
|
static JsArray |
of(JsValue e,
JsValue e1,
JsValue e2,
JsValue e3,
JsValue e4)
Returns an immutable five-element array.
|
static JsArray |
of(JsValue e,
JsValue e1,
JsValue e2,
JsValue e3,
JsValue e4,
JsValue... rest)
Returns an immutable array.
|
static JsArray |
of(long number,
long... others)
Returns an immutable array from one or more longs.
|
static JsArray |
of(String str,
String... others)
Returns an immutable array from one or more strings.
|
static JsArray |
ofIterable(Iterable<? extends JsValue> iterable)
returns an immutable json array from an iterable of json elements
|
static JsArray |
parse(String str)
Tries to parse the string into an immutable json array.
|
static JsArray |
parseYaml(String str)
Tries to parse the YAML string into an immutable json array.
|
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 array, 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)
Performs a reduction on the values of this json that satisfy the predicate.
|
<R> Optional<R> |
reduce(BinaryOperator<R> op,
Function<? super JsPrimitive,R> map,
Predicate<? super JsPrimitive> predicate)
Performs a reduction on the values of this json that satisfy the predicate.
|
JsArray |
set(int index,
JsValue element) |
JsArray |
set(int index,
JsValue value,
JsValue padElement) |
JsArray |
set(JsPath path,
JsValue element)
Inserts the element at the path in this json, replacing any existing element and filling with
JsNull empty indexes in arrays when necessary. |
JsArray |
set(JsPath path,
JsValue value,
JsValue padElement)
Inserts the element at the path in this json, replacing any existing element and filling with padElement
empty indexes in arrays when necessary.
|
int |
size()
Returns the number of elements in the first level of this json
|
Stream<fun.tuple.Pair<JsPath,JsValue>> |
stream()
Returns a stream over all the pairs of elements in this json object.
|
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)
returns
this plus those elements from that which position is >= this.size() ,
and, at the positions where a container of the same type exists in both this and that ,
the result is their union. |
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 int TYPE_ID
public static final JsOptics.JsArrayLenses lens
public static final JsOptics.JsArrayOptionals optional
public static final JsArray EMPTY
public static JsArray empty()
public static JsArray of(JsValue e, JsValue e1, JsValue e2, JsValue e3, JsValue e4, JsValue... rest)
e
- a JsValuee1
- a JsValuee2
- a JsValuee3
- a JsValuee4
- a JsValuerest
- more optional JsValuepublic static JsArray of(JsValue e, JsValue e1, JsValue e2, JsValue e3, JsValue e4)
e
- a JsValuee1
- a JsValuee2
- a JsValuee3
- a JsValuee4
- a JsValuepublic static JsArray of(JsValue e, JsValue e1, JsValue e2, JsValue e3)
e
- a JsValuee1
- a JsValuee2
- a JsValuee3
- a JsValuepublic static JsArray of(JsValue e, JsValue e1, JsValue e2)
e
- a JsValuee1
- a JsValuee2
- a JsValuepublic static JsArray of(JsValue e, JsValue e1)
e
- a JsValuee1
- a JsValuepublic static JsArray of(String str, String... others)
str
- a stringothers
- more optional stringspublic static JsArray of(int number, int... others)
number
- an integerothers
- more optional integerspublic static JsArray of(boolean bool, boolean... others)
bool
- an booleanothers
- more optional booleanspublic static JsArray of(long number, long... others)
number
- a longothers
- more optional longspublic static JsArray of(BigInteger number, BigInteger... others)
number
- a big integerothers
- more optional big integerspublic static JsArray of(double number, double... others)
number
- a doubleothers
- more optional doublespublic static JsArray ofIterable(Iterable<? extends JsValue> iterable)
iterable
- the iterable of json elementspublic static JsArray parseYaml(String str)
str
- the YAML to be parsedMalformedJson
- if the string doesnt represent a json arraypublic static JsArray parse(String str)
str
- the string to be parsedMalformedJson
- if the string doesnt represent a json arraypublic JsArray append(JsValue e, JsValue... others)
e
- the JsValue to be added to the back.others
- more optional JsValue to be added to the backpublic JsArray appendAll(JsArray array)
array
- the JsArray of elements to be added to the backpublic boolean equals(JsArray array, JsArray.TYPE ARRAY_AS)
array
- the given arrayARRAY_AS
- option to define if arrays are considered SETS, LISTS OR MULTISETpublic Integer getInt(int index)
index
- the indexpublic Integer getInt(int index, Supplier<Integer> orElse)
index
- the indexorElse
- the default valuepublic Long getLong(int index)
index
- the indexpublic Long getLong(int index, Supplier<Long> orElse)
index
- the indexorElse
- the default valuepublic String getStr(int index)
index
- the indexpublic String getStr(int index, Supplier<String> orElse)
index
- the indexorElse
- the default valuepublic Instant getInstant(int index)
index
- the given indexpublic Instant getInstant(int index, Supplier<Instant> orElse)
index
- the given indexorElse
- the default valuepublic byte[] getBinary(int index)
index
- the given indexpublic byte[] getBinary(int index, Supplier<byte[]> orElse)
index
- the given indexorElse
- the default valuepublic Boolean getBool(int index)
index
- the indexpublic Boolean getBool(int index, Supplier<Boolean> orElse)
index
- the indexorElse
- the default valuepublic Double getDouble(int index)
BigDecimal.doubleValue()
and in some cases it can lose information about
the precision of the BigDecimalindex
- the indexpublic Double getDouble(int index, Supplier<Double> orElse)
BigDecimal.doubleValue()
and in some cases it can lose information about
the precision of the BigDecimalindex
- the indexorElse
- the default valuepublic BigDecimal getBigDec(int index)
index
- the indexpublic BigDecimal getBigDec(int index, Supplier<BigDecimal> orElse)
index
- the indexorElse
- the default valuepublic BigInteger getBigInt(int index)
index
- the indexpublic BigInteger getBigInt(int index, Supplier<BigInteger> orElse)
index
- the indexorElse
- the default value providedpublic JsObj getObj(int index)
index
- the indexpublic JsObj getObj(int index, Supplier<JsObj> orElse)
index
- the indexorElse
- the default valuepublic JsArray getArray(int index)
index
- the indexpublic JsArray getArray(int index, Supplier<JsArray> orElse)
index
- the indexorElse
- the default valuepublic boolean containsValue(JsValue el)
Json
containsValue
in interface Json<JsArray>
el
- the give element JsValue whose presence in this JsArray is to be testedpublic 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 the 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 the 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 the 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
empty indexes in arrays when necessary.
The same instance is returned when the head of the path is a key and this is an array or the head
of the path is an index and this is an object or the element is JsNothing
public JsArray set(JsPath path, JsValue value, JsValue padElement)
Json
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
set
in interface Json<JsArray>
path
- the JsPath object where the element will be inserted atvalue
- the JsValue that will be insertedpadElement
- the JsValue that will be inserted in arrays when padding is necessarypublic <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 operands of the operatorop
- 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 reducedOptional
describing the result of the reductionpublic <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 operands of the operatorop
- 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 reducedOptional
describing the result of the reductionpublic JsArray delete(JsPath path)
Json
public int size()
Json
public Stream<fun.tuple.Pair<JsPath,JsValue>> stream()
Json
public JsValue get(int i)
i
- the indexpublic int hashCode()
public String toString()
public JsValue head()
UserError
- if this JsArray is emptypublic JsArray tail()
UserError
- if this JsArray is empty.public JsArray init()
UserError
- if this JsArray is emptypublic 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 arraypublic boolean isArray()
JsValue
public JsValue last()
UserError
- if this JsArray is emptypublic JsArray prepend(JsValue e, JsValue... others)
e
- the JsValue to be added to the front.others
- more optional JsValue to be added to the frontpublic JsArray prependAll(JsArray array)
array
- the JsArray of elements to be added to the frontpublic JsArray delete(int index)
public JsArray union(JsArray that, JsArray.TYPE ARRAY_AS)
this
plus those elements from that
which position is >= this.size()
,
and, at the positions where a container of the same type exists in both this
and that
,
the result is their union. This operations doesn't make any sense if arrays are not considered lists,
because there is no notion of order.Copyright © 2022. All rights reserved.