Package jsonvalues
Interface JsArray
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classJsArray.TYPEType of arrays: SET, MULTISET or LIST.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description JsArrayadd(int index, JsElem elem)JsArrayappend(JsElem elem, JsElem... others)Adds one or more elements, starting from the first, to the back of this array.JsArrayappendAll(JsArray array)Adds all the elements of the given array, starting from the head, to the back of this array.default booleanequals(JsArray array, JsArray.TYPE ARRAY_AS)Returns true if this array is equal to the given as a parameter.JsElemhead()Returns the first element of this array.default <T> Trampoline<T>ifEmptyElse(Trampoline<T> empty, BiFunction<JsElem,JsArray,Trampoline<T>> fn)JsArrayinit()Returns all the elements of this array except the last one.JsArrayintersection(JsArray that, JsArray.TYPE ARRAY_AS)this.intersection(that, SET)returns an array with the elements that exist in boththisandthat.JsArrayintersection_(JsArray that)this.intersection_(that)behaves asthis.intersection(that, LIST), but for those elements that are containers of the same type and are located at the same position, the result is their intersection.default booleanisArray()JsElemlast()Returns the last element of this array.JsArrayprepend(JsElem elem, JsElem... others)Adds one or more elements, starting from the last, to the front of this array.JsArrayprependAll(JsArray array)Adds all the elements of the array, starting from the last, to the front of this array.booleansame(JsArray other)JsArraytail()Returns a json array consisting of all elements of this array except the first one.JsArrayunion(JsArray that, JsArray.TYPE ARRAY_AS)this.union(that, SET)returnsthisplus those elements fromthatthat don't exist inthis.JsArrayunion_(JsArray that)returnsthisplus those elements fromthatwhich position is>= this.size(), and, at the positions where a container of the same type exists in boththisandthat, the result is their union.-
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, 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
-
Methods inherited from interface jsonvalues.Json
add, add, add, add, add, add, add, append, append, append, append, append, append, append, appendAll, appendAllIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, appendIfPresent, containsElem, containsElem_, containsPath, equals, filterElems, filterElems_, filterKeys, filterKeys_, filterObjs, filterObjs_, get, get, getArray, getBigDecimal, getBigInt, getBool, getDouble, getInt, getLong, getObj, getStr, ifEmptyElse, isEmpty, isImmutable, isMutable, isNotEmpty, map, mapElems, mapElems, mapElems_, mapElems_, mapKeys, mapKeys, mapKeys_, mapKeys_, mapObjs, mapObjs, mapObjs_, mapObjs_, merge, patch, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prependAll, prependAllIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, prependIfPresent, put, put, put, put, put, put, put, put, putIf, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsent, putIfPresent, putIfPresent, putIfPresent, putIfPresent, reduce, reduce_, remove, size, size, size_, size_, stream, stream_, times, times_
-
-
-
-
Method Detail
-
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
-
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
-
head
JsElem head()
Returns the first element of this array.- Returns:
- the first JsElem of this JsArray
- Throws:
UserError- 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:
UserError- if this JsArray is empty
-
last
JsElem last()
Returns the last element of this array.- Returns:
- the last JsElem of this JsArray
- Throws:
UserError- if this JsArray is empty
-
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:
UserError- if this JsArray is empty.
-
intersection
JsArray intersection(JsArray that, JsArray.TYPE ARRAY_AS)
this.intersection(that, SET)returns an array with the elements that exist in boththisandthat.this.intersection(that, MULTISET)returns an array with the elements that exist in boththisandthat, being duplicates allowed.this.intersection(that, LIST)returns an array with the elements that exist in boththisandthatand are located at the same position.- 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)
this.intersection_(that)behaves asthis.intersection(that, LIST), but for those elements that are containers of the same type and are located at the same position, the result is their intersection. So this operation is kind of a recursive intersection- Parameters:
that- the other array- Returns:
- a JsArray of the same type as the inputs (mutable or immutable)
-
union
JsArray union(JsArray that, JsArray.TYPE ARRAY_AS)
this.union(that, SET)returnsthisplus those elements fromthatthat don't exist inthis.this.union(that, MULTISET)returnsthisplus those elements fromthatappended to the back.this.union(that, LIST)returnsthisplus those elements fromthatwhich position is>= this.size().- 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)
returnsthisplus those elements fromthatwhich position is>= this.size(), and, at the positions where a container of the same type exists in boththisandthat, 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.- Parameters:
that- the other array- Returns:
- a new JsArray of the same type as the inputs (mutable or immutable)
-
ifEmptyElse
default <T> Trampoline<T> ifEmptyElse(Trampoline<T> empty, BiFunction<JsElem,JsArray,Trampoline<T>> fn)
-
isArray
default boolean isArray()
-
same
boolean same(JsArray other)
-
-