Package jsonvalues
Interface JsArray
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
JsArray.TYPE
Type of arrays: SET, MULTISET or LIST.
-
Field Summary
Fields Modifier and Type Field Description static long
serialVersionUID
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static Collector<JsPair,JsArray,JsArray>
_collector_()
Returns a collector that accumulates the pairs from a stream into a mutable array.static JsArray
_empty_()
Returns a mutable empty array.static JsArray
_of_(boolean bool, boolean... others)
Returns a mutable array from one or more booleans.static JsArray
_of_(double number, double... others)
Returns a mutable array from one or more doubles.static JsArray
_of_(int number, int... others)
Returns a mutable array from one or more integersstatic JsArray
_of_(long number, long... others)
Returns a mutable array from one or more longs.static JsArray
_of_(String str, String... others)
Returns a mutable array from one or more strings.static JsArray
_of_(List<JsElem> list)
Returns a mutable array copying the reference of the collection of elements.static JsArray
_of_(JsElem e)
Returns a mutable one-element array.static JsArray
_of_(JsElem e, JsElem e1)
Returns a mutable two-element array.static JsArray
_of_(JsElem e, JsElem e1, JsElem e2)
Returns a mutable three-element array.static JsArray
_of_(JsElem e, JsElem e1, JsElem e2, JsElem e3)
Returns a mutable four-element array.static JsArray
_of_(JsElem e, JsElem e1, JsElem e2, JsElem e3, JsElem e4)
Returns a mutable five-element array.static JsArray
_of_(JsElem e, JsElem e1, JsElem e2, JsElem e3, JsElem e4, JsElem... rest)
Returns a mutable array containing an arbitrary number of elements.static JsArray
_of_(JsPair pair, JsPair... pairs)
Returns a mutable array from one or more pairs.static TryArr
_parse_(String str)
Tries to parse the string into a mutable json array.static TryArr
_parse_(String str, ParseOptions options)
Tries to parse the string into a mutable array, performing some operations while the parsing.JsArray
append(JsElem elem, JsElem... 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.static Collector<JsPair,JsArray,JsArray>
collector()
Returns a collector that accumulates the pairs from a stream into an immutable array.static JsArray
empty()
Returns the immutable empty array.default boolean
equals(JsArray array, JsArray.TYPE ARRAY_AS)
Returns true if this array is equal to the given as a parameter.JsElem
head()
Returns the first element of this array.default <T> Trampoline<T>
ifEmptyElse(Trampoline<T> empty, BiFunction<JsElem,JsArray,Trampoline<T>> fn)
JsArray
init()
Returns all the elements of this array except the last one.JsArray
intersection(JsArray that, JsArray.TYPE ARRAY_AS)
Returns the intersection of this array and another given as a parameter, defining characteristics like order and duplicates occurrence with the given ARRAY_AS parameter.JsArray
intersection_(JsArray that)
Returns the intersection of this array and another given as parameter considering bothJsArray.TYPE.LIST
lists and applying recursively the intersection to those elements which are Json of the same type and are located at the same position.default boolean
isArray()
default boolean
isObj()
JsElem
last()
Returns the last element of this array.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(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
of(Collection<? extends JsElem> list)
Returns an immutable array from the collection of elements.static JsArray
of(JsElem e)
Returns an immutable one-element array.static JsArray
of(JsElem e, JsElem e1)
Returns an immutable two-element array.static JsArray
of(JsElem e, JsElem e1, JsElem e2)
Returns an immutable three-element array.static JsArray
of(JsElem e, JsElem e1, JsElem e2, JsElem e3)
Returns an immutable four-element array.static JsArray
of(JsElem e, JsElem e1, JsElem e2, JsElem e3, JsElem e4)
Returns an immutable five-element array.static JsArray
of(JsElem e, JsElem e1, JsElem e2, JsElem e3, JsElem e4, JsElem... rest)
Returns an immutable array.static JsArray
of(JsPair pair, JsPair... pairs)
Returns an immutable array from one or more pairs.static TryArr
parse(String str)
Tries to parse the string into an immutable array.static TryArr
parse(String str, ParseOptions options)
Tries to parse the string into an immutable array, performing some operations during the parsing.JsArray
prepend(JsElem elem, JsElem... 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.JsArray
tail()
Returns a json array consisting of all elements of this array except the first one.JsArray
union(JsArray that, JsArray.TYPE ARRAY_AS)
Returns the union of this array and another, defining characteristics like order and duplicates occurrence with the given ARRAY_AS parameter.JsArray
union_(JsArray that)
Returns the union of this array and another given as parameter considering bothJsArray.TYPE.LIST
lists and applying recursively the union to those elements which are Json of the same type and are located at the same position.-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Methods inherited from interface jsonvalues.JsElem
asJsArray, asJsBigDec, asJsBigInt, asJsBool, asJsDouble, asJsInt, asJsLong, asJsObj, asJson, asJsStr, isArray, isBigDec, isBigInt, isDecimal, isDouble, isInstant, isInstant, isInt, isIntegral, isJson, isJson, isLocalDate, isLocalDate, isLocalDateTime, isLocalDateTime, isLong, isNotJson, isNotNothing, isNotNull, isNotNumber, isObj, isSameType, isStr
-
Methods inherited from interface jsonvalues.Json
append, append, append, append, append, append, append, append, append, append, append, append, append, append, appendAll, appendAll, appendAllIfPresent, appendAllIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, containsElem, containsElem_, containsPath, containsPath, equals, filterElems, filterElems_, filterKeys, filterKeys_, filterObjs, filterObjs_, get, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInt, getBigInt, getBool, getBool, getDouble, getDouble, getInt, getInt, getLong, getLong, getObj, getObj, getStr, getStr, ifEmptyElse, isBigDec, isBigInt, isBool, isDouble, isEmpty, isFalse, isImmutable, isInt, isLong, isMutable, isNotEmpty, isNothing, isNull, isNumber, isStr, isTrue, map, mapElems, mapElems, mapElems_, mapElems_, mapKeys, mapKeys, mapKeys_, mapKeys_, mapObjs, mapObjs, mapObjs_, mapObjs_, merge, merge, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prependAll, prependAll, prependAllIfPresent, prependAllIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, put, put, put, put, put, put, put, put, put, put, putIf, putIf, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsent, putIfPresent, putIfPresent, putIfPresent, putIfPresent, putIfPresent, putIfPresent, putIfPresent, putIfPresent, reduce, reduce_, remove, remove, size, size, size, size_, size_, size_, stream, stream_, times, times_, toImmutable, toMutable
-
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
_empty_
static JsArray _empty_()
Returns a mutable empty array.- Returns:
- mutable empty JsArray
-
_of_
static JsArray _of_(List<JsElem> list)
Returns a mutable array copying the reference of the collection of elements. Since the reference is copied, changes in the array are reflected in the list and vice versa. If the collection is immutable (created using List.of or Arrays.asList factory methods for example), every modification in the array will throw an UnsupportedOperationException.- Parameters:
list
- the Collection of JsElem from which reference the JsArray will be created- Returns:
- a mutable JsArray
- Throws:
UnsupportedOperationException
- if an elem of the list is an immutable Json
-
_of_
static JsArray _of_(JsElem e)
Returns a mutable one-element array.- Parameters:
e
- the JsElem- Returns:
- a mutable one-element JsArray
- Throws:
UnsupportedOperationException
- if the elem is an immutable Json
-
_of_
static JsArray _of_(JsElem e, JsElem e1)
Returns a mutable two-element array.- Parameters:
e
- a JsEleme1
- a JsElem- Returns:
- a mutable two-element JsArray
- Throws:
UnsupportedOperationException
- if an elem is an immutable Json
-
_of_
static JsArray _of_(JsElem e, JsElem e1, JsElem e2)
Returns a mutable three-element array.- Parameters:
e
- a JsEleme1
- a JsEleme2
- a JsElem- Returns:
- a mutable three-element JsArray
- Throws:
UnsupportedOperationException
- if an elem is an immutable Json
-
_of_
static JsArray _of_(JsElem e, JsElem e1, JsElem e2, JsElem e3)
Returns a mutable four-element array.- Parameters:
e
- a JsEleme1
- a JsEleme2
- a JsEleme3
- a JsElem- Returns:
- a mutable four-element JsArray
- Throws:
UnsupportedOperationException
- if an elem is an immutable Json
-
_of_
static JsArray _of_(JsElem e, JsElem e1, JsElem e2, JsElem e3, JsElem e4)
Returns a mutable five-element array.- Parameters:
e
- a JsEleme1
- a JsEleme2
- a JsEleme3
- a JsEleme4
- a JsElem- Returns:
- a mutable five-element JsArray
- Throws:
UnsupportedOperationException
- if an elem is an immutable Json
-
_of_
static JsArray _of_(JsElem e, JsElem e1, JsElem e2, JsElem e3, JsElem e4, JsElem... rest)
Returns a mutable array containing an arbitrary number of elements.- Parameters:
e
- a JsEleme1
- a JsEleme2
- a JsEleme3
- a JsEleme4
- a JsElemrest
- more optional JsElem- Returns:
- a mutable JsArray
- Throws:
UnsupportedOperationException
- if an elem is an immutable Json
-
_parse_
static TryArr _parse_(String str)
Tries to parse the string into a mutable json array.- Parameters:
str
- the string to be parsed- Returns:
- a
TryArr
computation
-
equals
default boolean equals(JsArray array, JsArray.TYPE ARRAY_AS)
Returns true if this array is equal to the given as a parameter. In the case of ARRAY_AS=LIST, this method is equivalent to JsArray.equals(Object).- Parameters:
array
- the given arrayARRAY_AS
- option to define if arrays are considered SETS, LISTS OR MULTISET- Returns:
- true if both arrays are equals according to ARRAY_AS parameter
-
_parse_
static TryArr _parse_(String str, ParseOptions options)
Tries to parse the string into a mutable array, performing some operations while the parsing. It's faster to do certain operations right while the parsing instead of doing the parsing and apply them later.- Parameters:
str
- the string that will be parsed.options
- a builder with the filters and maps that, if specified, will be applied during the parsing- Returns:
- a
TryArr
computation
-
appendAll
JsArray appendAll(JsArray array)
Adds all the elements of the given array, starting from the head, to the back of this array.- Parameters:
array
- the JsArray of elements to be added to the back- Returns:
- a new JsArray
-
prependAll
JsArray prependAll(JsArray array)
Adds all the elements of the array, starting from the last, to the front of this array.- Parameters:
array
- the JsArray of elements to be added to the front- Returns:
- a new JsArray
-
append
JsArray append(JsElem elem, JsElem... others)
Adds one or more elements, starting from the first, to the back of this array.- Parameters:
elem
- the JsElem to be added to the back.others
- more optional JsElem to be added to the back- Returns:
- a new JsArray
-
prepend
JsArray prepend(JsElem elem, JsElem... others)
Adds one or more elements, starting from the last, to the front of this array.- Parameters:
elem
- the JsElem to be added to the front.others
- more optional JsElem to be added to the front- Returns:
- a new JsArray
-
collector
static Collector<JsPair,JsArray,JsArray> collector()
Returns a collector that accumulates the pairs from a stream into an immutable array.- Returns:
- a Collector which collects all the pairs of elements into an immutable JsArray, in encounter order
-
_collector_
static Collector<JsPair,JsArray,JsArray> _collector_()
Returns a collector that accumulates the pairs from a stream into a mutable array.- Returns:
- a Collector which collects all the pairs of elements into a mutable JsArray, in encounter order
-
empty
static JsArray empty()
Returns the immutable empty array. The same instance is always returned.- Returns:
- the singleton immutable empty JsArray.
-
head
JsElem head()
Returns the first element of this array.- Returns:
- the first JsElem of this JsArray
- Throws:
UnsupportedOperationException
- if this JsArray is empty
-
init
JsArray init()
Returns all the elements of this array except the last one.- Returns:
- JsArray with all the JsElem except the last one
- Throws:
UnsupportedOperationException
- if this JsArray is empty
-
last
JsElem last()
Returns the last element of this array.- Returns:
- the last JsElem of this JsArray
- Throws:
UnsupportedOperationException
- if this JsArray is empty
-
of
static JsArray of(Collection<? extends JsElem> list)
Returns an immutable array from the collection of elements.- Parameters:
list
- the Collection of JsElem from which the JsArray will be created- Returns:
- an immutable JsArray
- Throws:
UnsupportedOperationException
- if an elem of the list is a mutable Json
-
of
static JsArray of(JsElem e)
Returns an immutable one-element array.- Parameters:
e
- the JsElem- Returns:
- a mutable JsArray
- Throws:
UnsupportedOperationException
- if the elem is a mutable Json
-
of
static JsArray of(JsElem e, JsElem e1)
Returns an immutable two-element array.- Parameters:
e
- a JsEleme1
- a JsElem- Returns:
- an immutable two-element JsArray
- Throws:
UnsupportedOperationException
- if an elem is a mutable Json
-
of
static JsArray of(JsElem e, JsElem e1, JsElem e2)
Returns an immutable three-element array.- Parameters:
e
- a JsEleme1
- a JsEleme2
- a JsElem- Returns:
- an immutable three-element JsArray
- Throws:
UnsupportedOperationException
- if an elem is a mutable Json
-
of
static JsArray of(JsElem e, JsElem e1, JsElem e2, JsElem e3)
Returns an immutable four-element array.- Parameters:
e
- a JsEleme1
- a JsEleme2
- a JsEleme3
- a JsElem- Returns:
- an immutable four-element JsArray
- Throws:
UnsupportedOperationException
- if an elem is a mutable Json
-
of
static JsArray of(JsElem e, JsElem e1, JsElem e2, JsElem e3, JsElem e4)
Returns an immutable five-element array.- Parameters:
e
- a JsEleme1
- a JsEleme2
- a JsEleme3
- a JsEleme4
- a JsElem- Returns:
- an immutable five-element JsArray
- Throws:
UnsupportedOperationException
- if an elem is a mutable Json
-
of
static JsArray of(JsElem e, JsElem e1, JsElem e2, JsElem e3, JsElem e4, JsElem... rest)
Returns an immutable array.- Parameters:
e
- a JsEleme1
- a JsEleme2
- a JsEleme3
- a JsEleme4
- a JsElemrest
- more optional JsElem- Returns:
- an immutable JsArray
- Throws:
UnsupportedOperationException
- if an elem is a mutable Json
-
parse
static TryArr parse(String str)
Tries to parse the string into an immutable array.- Parameters:
str
- the string to be parsed- Returns:
- a
TryArr
computation
-
parse
static TryArr parse(String str, ParseOptions options)
Tries to parse the string into an immutable array, performing some operations during the parsing. It's faster to do certain operations right while the parsing instead of doing the parsing and applying them later.- Parameters:
str
- string to be parsedoptions
- a Options with the filters and maps that will be applied during the parsing- Returns:
- a
TryArr
computation
-
of
static JsArray of(String str, String... others)
Returns an immutable array from one or more strings.- Parameters:
str
- a stringothers
- more optional strings- Returns:
- an immutable JsArray
-
_of_
static JsArray _of_(String str, String... others)
Returns a mutable array from one or more strings.- Parameters:
str
- a stringothers
- more optional strings- Returns:
- a mutable JsArray
-
of
static JsArray of(int number, int... others)
Returns an immutable array from one or more integers.- Parameters:
number
- an integerothers
- more optional integers- Returns:
- an immutable JsArray
-
_of_
static JsArray _of_(int number, int... others)
Returns a mutable array from one or more integers- Parameters:
number
- an integerothers
- more optional integers- Returns:
- an mutable JsArray
-
of
static JsArray of(long number, long... others)
Returns an immutable array from one or more longs.- Parameters:
number
- a longothers
- more optional longs- Returns:
- an immutable JsArray
-
of
static JsArray of(boolean bool, boolean... others)
Returns an immutable array from one or more booleans.- Parameters:
bool
- a booleanothers
- more optional booleans- Returns:
- an immutable JsArray
-
of
static JsArray of(double number, double... others)
Returns an immutable array from one or more doubles.- Parameters:
number
- a doubleothers
- more optional doubles- Returns:
- an immutable JsArray
-
_of_
static JsArray _of_(long number, long... others)
Returns a mutable array from one or more longs.- Parameters:
number
- a longothers
- more optional longs- Returns:
- a mutable JsArray
-
_of_
static JsArray _of_(boolean bool, boolean... others)
Returns a mutable array from one or more booleans.- Parameters:
bool
- a booleanothers
- more optional booleans- Returns:
- a mutable JsArray
-
_of_
static JsArray _of_(double number, double... others)
Returns a mutable array from one or more doubles.- Parameters:
number
- a doubleothers
- more optional doubles- Returns:
- a mutable JsArray
-
tail
JsArray tail()
Returns a json array consisting of all elements of this array except the first one.- Returns:
- a JsArray consisting of all the elements of this JsArray except the head
- Throws:
UnsupportedOperationException
- if this JsArray is empty.
-
intersection
JsArray intersection(JsArray that, JsArray.TYPE ARRAY_AS)
Returns the intersection of this array and another given as a parameter, defining characteristics like order and duplicates occurrence with the given ARRAY_AS parameter.- Parameters:
that
- the other arrayARRAY_AS
- option to define if arrays are considered SETS, LISTS OR MULTISET- Returns:
- a new JsArray of the same type as the inputs (mutable or immutable)
-
intersection_
JsArray intersection_(JsArray that)
Returns the intersection of this array and another given as parameter considering bothJsArray.TYPE.LIST
lists and applying recursively the intersection to those elements which are Json of the same type and are located at the same position.- Parameters:
that
- the other array- Returns:
- a JsArray of the same type as the inputs (mutable or immutable)
-
union
JsArray union(JsArray that, JsArray.TYPE ARRAY_AS)
Returns the union of this array and another, defining characteristics like order and duplicates occurrence with the given ARRAY_AS parameter.- Parameters:
that
- the other arrayARRAY_AS
- option to define if arrays are considered SETS, LISTS OR MULTISET- Returns:
- a new json array of the same type as the inputs (mutable or immutable)
-
union_
JsArray union_(JsArray that)
Returns the union of this array and another given as parameter considering bothJsArray.TYPE.LIST
lists and applying recursively the union to those elements which are Json of the same type and are located at the same position.- Parameters:
that
- the other array- Returns:
- a new JsArray of the same type as the inputs (mutable or immutable)
-
of
static JsArray of(JsPair pair, JsPair... pairs)
Returns an immutable array from one or more pairs.- Parameters:
pair
- a pairpairs
- more optional pairs- Returns:
- an immutable JsArray
- Throws:
UnsupportedOperationException
- if an elem of a pair is mutable
-
_of_
static JsArray _of_(JsPair pair, JsPair... pairs)
Returns a mutable array from one or more pairs.- Parameters:
pair
- a pairpairs
- more optional pairs- Returns:
- a mutable JsArray
- Throws:
UnsupportedOperationException
- if an elem of a pair is immutable
-
ifEmptyElse
default <T> Trampoline<T> ifEmptyElse(Trampoline<T> empty, BiFunction<JsElem,JsArray,Trampoline<T>> fn)
-
isObj
default boolean isObj()
-
-