Package jsonvalues
Interface JsObj
-
-
Field Summary
Fields Modifier and Type Field Description static longserialVersionUID
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static Collector<JsPair,JsObj,JsObj>_collector_()Returns a collector that accumulates the pairs from a stream into an mutable object.static JsObj_empty_()Returns a mutable empty object.static JsObj_of_(String key, JsElem el)Returns a mutable one-pair object.static JsObj_of_(String key1, JsElem el1, String key2, JsElem el2)Returns a mutable two-pair object.static JsObj_of_(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3)Returns a mutable three-pair object.static JsObj_of_(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4)Returns a mutable four-pair object.static JsObj_of_(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4, String key5, JsElem el5)Returns a mutable five-pair object.static JsObj_of_(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4, String key5, JsElem el5, String key6, JsElem el6)Returns a mutable six-pair object.static JsObj_of_(Map<String,JsElem> map)Returns a mutable object from a map of elements.static JsObj_of_(JsPair pair, JsPair... others)Returns a mutable object from one or more pairs.static TryObj_parse_(String str)Tries to parse the string into a mutable json object.static TryObj_parse_(String str, ParseBuilder builder)Tries to parse the string into an mutable object, performing the specified transformations while the parsing.static Collector<JsPair,JsObj,JsObj>collector()Returns a collector that accumulates the pairs from a stream into an immutable object.static JsObjempty()Returns the immutable empty object.default booleanequals(JsObj that, JsArray.TYPE ARRAY_AS)return true if this obj is equal to the given as a parameter.Set<String>fields()Returns a set containing each key fo this object.Map.Entry<String,JsElem>head()Returns a pair with an arbitrary key of this object and its associated element.default <T> Trampoline<T>ifEmptyElse(Trampoline<T> empty, BiFunction<Map.Entry<String,JsElem>,JsObj,Trampoline<T>> fn)JsObjintersection(JsObj that, JsArray.TYPE ARRAY_AS)this.intersection(that, SET)returns an array with the elements that exist in boththisandthatthis.intersection(that, MULTISET)returns an array with the elements that exist in boththisandthat, being duplicates allowed.JsObjintersection_(JsObj that, JsArray.TYPE ARRAY_AS)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()default booleanisObj()static JsObjof(String key, JsElem el)Returns an immutable one-element object.static JsObjof(String key1, JsElem el1, String key2, JsElem el2)Returns a two-element immutable object.static JsObjof(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3)Returns a three-element immutable json object.static JsObjof(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4)Returns a four-element immutable object.static JsObjof(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4, String key5, JsElem el5)Returns a five-element immutable object.static JsObjof(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4, String key5, JsElem el5, String key6, JsElem el6)Returns a six-element immutable object.static JsObjof(Map<String,JsElem> map)Returns a immutable object from a map of elements.static JsObjof(JsPair pair, JsPair... others)Returns an immutable object from one or more pairs.static TryObjparse(String str)Tries to parse the string into an immutable object.static TryObjparse(String str, ParseBuilder builder)Tries to parse the string into an immutable object, performing the specified transformations during the parsing.default TryPatch<JsObj>patch(JsArray ops)Implementation of the Json Patch specification.JsObjtail(String key)Returns a new object with all the entries of this json object except the one with the given key.JsObjunion(JsObj that)returnsthisjson object plus those pairs from the given json objectthatwhich keys don't exist inthis.JsObjunion_(JsObj that, JsArray.TYPE ARRAY_AS)behaves like theunion(JsObj)but, for those keys that exit in boththisandthatjson objects, which associated elements are **containers of the same type**, 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, 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
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, 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, 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_, toImmutable, toMutable
-
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
_empty_
static JsObj _empty_()
Returns a mutable empty object.- Returns:
- a mutable empty JsObj
-
_of_
static JsObj _of_(String key, JsElem el)
Returns a mutable one-pair object.- Parameters:
key- name of the keyel- JsElem to be associated to the key- Returns:
- a mutable one-pair JsObj
- Throws:
UserError- if the elem is an immutable Json
-
_of_
static JsObj _of_(String key1, JsElem el1, String key2, JsElem el2)
Returns a mutable two-pair object.- Parameters:
key1- name of a keyel1- JsElem to be associated to the key1key2- name of a keyel2- JsElem to be associated to the key2- Returns:
- a two-pair mutable JsObj
- Throws:
UserError- if an elem is an immutable Json
-
_of_
static JsObj _of_(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3)
Returns a mutable three-pair object.- Parameters:
key1- name of a keyel1- JsElem to be associated to the key1key2- name of a keyel2- JsElem to be associated to the key2key3- name of a keyel3- JsElem to be associated to the key3- Returns:
- a three-pair mutable JsObj
- Throws:
UserError- if an elem is an immutable Json
-
_of_
static JsObj _of_(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4)
Returns a mutable four-pair object.- Parameters:
key1- name of a keyel1- JsElem to be associated to the key1key2- name of a keyel2- JsElem to be associated to the key2key3- name of a keyel3- JsElem to be associated to the key3key4- name of a keyel4- JsElem to be associated to the key4- Returns:
- a mutable four-pair JsObj
- Throws:
UserError- if an elem is an immutable Json
-
_of_
static JsObj _of_(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4, String key5, JsElem el5)
Returns a mutable five-pair object.- Parameters:
key1- name parse a keyel1- JsElem to be associated to the key1key2- name parse a keyel2- JsElem to be associated to the key2key3- name parse a keyel3- JsElem to be associated to the key3key4- name parse a keyel4- JsElem to be associated to the key4key5- name parse a keyel5- JsElem to be associated to the key5- Returns:
- a mutable five-element JsObj
- Throws:
UserError- if an elem is an immutable Json
-
_of_
static JsObj _of_(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4, String key5, JsElem el5, String key6, JsElem el6)
Returns a mutable six-pair object.- Parameters:
key1- name parse a keyel1- JsElem to be associated to the key1key2- name parse a keyel2- JsElem to be associated to the key2key3- name parse a keyel3- JsElem to be associated to the key3key4- name parse a keyel4- JsElem to be associated to the key4key5- name parse a keyel5- JsElem to be associated to the key5key6- name parse a keyel6- JsElem to be associated to the key6- Returns:
- a mutable six-element JsObj
- Throws:
UserError- if an elem is an immutable Json
-
_of_
static JsObj _of_(Map<String,JsElem> map)
Returns a mutable object from a map of elements.- Parameters:
map- the map of JsElem- Returns:
- a mutable JsObj
- Throws:
UserError- if an elem of the map is an immutable Json
-
_parse_
static TryObj _parse_(String str)
Tries to parse the string into a mutable json object.- Parameters:
str- the string to be parsed- Returns:
- a
TryObjcomputation
-
equals
default boolean equals(JsObj that, JsArray.TYPE ARRAY_AS)
return true if this obj is equal to the given as a parameter. In the case of ARRAY_AS=LIST, this method is equivalent to JsObj.equals(Object).- Parameters:
that- the given arrayARRAY_AS- enum to specify if arrays are considered as lists or sets or multisets- Returns:
- true if both objs are equals
-
_parse_
static TryObj _parse_(String str, ParseBuilder builder)
Tries to parse the string into an mutable object, performing the specified transformations while 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 parsedbuilder- builder with the transformations that will be applied during the parsing- Returns:
- a
TryObjcomputation
-
collector
static Collector<JsPair,JsObj,JsObj> collector()
Returns a collector that accumulates the pairs from a stream into an immutable object.- Returns:
- a Collector which collects all the pairs of elements into an immutable JsObj, in encounter order
-
_collector_
static Collector<JsPair,JsObj,JsObj> _collector_()
Returns a collector that accumulates the pairs from a stream into an mutable object.- Returns:
- a Collector which collects all the pairs of elements into an mutable JsObj, in encounter order
-
empty
static JsObj empty()
Returns the immutable empty object. The same instance is always returned.- Returns:
- the singleton immutable empty JsObj
-
fields
Set<String> fields()
Returns a set containing each key fo this object.- Returns:
- a Set containing each key of this JsObj
-
head
Map.Entry<String,JsElem> head()
Returns a pair with an arbitrary key of this object and its associated element. When using head and tail to process a JsObj, the key of the pair returned must be passed in to get the tail using the methodtail(String).- Returns:
- an arbitrary
Map.Entry<String,JsElem>of this JsObj - Throws:
UserError- if this json object is empty
-
of
static JsObj of(String key, JsElem el)
Returns an immutable one-element object.- Parameters:
key- name of the keyel- JsElem to be associated to the key- Returns:
- an immutable one-element JsObj
- Throws:
UserError- if the elem is a mutable Json
-
of
static JsObj of(String key1, JsElem el1, String key2, JsElem el2)
Returns a two-element immutable object.- Parameters:
key1- name of a keyel1- JsElem to be associated to the key1key2- name of a keyel2- JsElem to be associated to the key2- Returns:
- an immutable two-element JsObj
- Throws:
UserError- if an elem is a mutable Json
-
of
static JsObj of(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3)
Returns a three-element immutable json object.- Parameters:
key1- name of a keyel1- JsElem to be associated to the key1key2- name of a keyel2- JsElem to be associated to the key2key3- name of a keyel3- JsElem to be associated to the key3- Returns:
- an immutable three-element JsObj
- Throws:
UserError- if an elem is a mutable Json
-
of
static JsObj of(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4)
Returns a four-element immutable object.- Parameters:
key1- name of a keyel1- JsElem to be associated to the key1key2- name of a keyel2- JsElem to be associated to the key2key3- name of a keyel3- JsElem to be associated to the key3key4- name of a keyel4- JsElem to be associated to the key4- Returns:
- an immutable four-element JsObj
- Throws:
UserError- if an elem is a mutable Json
-
of
static JsObj of(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4, String key5, JsElem el5)
Returns a five-element immutable object.- Parameters:
key1- name of a keyel1- JsElem to be associated to the key1key2- name of a keyel2- JsElem to be associated to the key2key3- name of a keyel3- JsElem to be associated to the key3key4- name of a keyel4- JsElem to be associated to the key4key5- name of a keyel5- JsElem to be associated to the key5- Returns:
- an immutable five-element JsObj
- Throws:
UserError- if an elem is a mutable Json
-
of
static JsObj of(String key1, JsElem el1, String key2, JsElem el2, String key3, JsElem el3, String key4, JsElem el4, String key5, JsElem el5, String key6, JsElem el6)
Returns a six-element immutable object.- Parameters:
key1- name of a keyel1- JsElem to be associated to the key1key2- name of a keyel2- JsElem to be associated to the key2key3- name of a keyel3- JsElem to be associated to the key3key4- name of a keyel4- JsElem to be associated to the key4key5- name of a keyel5- JsElem to be associated to the key5key6- name of a keyel6- JsElem to be associated to the key6- Returns:
- an immutable six-element JsObj
- Throws:
UserError- if an elem is a mutable Json
-
of
static JsObj of(Map<String,JsElem> map)
Returns a immutable object from a map of elements.- Parameters:
map- the map of JsElem- Returns:
- an immutable JsObj
- Throws:
UserError- if an elem of the map is a mutable Json
-
parse
static TryObj parse(String str)
Tries to parse the string into an immutable object.- Parameters:
str- the string to be parsed- Returns:
- a
TryObjcomputation
-
parse
static TryObj parse(String str, ParseBuilder builder)
Tries to parse the string into an immutable object, performing the specified transformations 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 parsedbuilder- builder with the transformations that will be applied during the parsing- Returns:
- a
TryObjcomputation
-
tail
JsObj tail(String key)
Returns a new object with all the entries of this json object except the one with the given key.- Parameters:
key- the given key, which associated pair will be excluded- Returns:
- a new JsObj
- Throws:
UserError- if this json object is empty
-
intersection
JsObj intersection(JsObj that, JsArray.TYPE ARRAY_AS)
this.intersection(that, SET)returns an array with the elements that exist in boththisandthatthis.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 boththisandthat, and are located at the same position.- Parameters:
that- the other objARRAY_AS- option to define if arrays are considered SETS, LISTS OR MULTISET- Returns:
- a new JsObj of the same type as the inputs (mutable or immutable)
-
intersection_
JsObj intersection_(JsObj that, JsArray.TYPE ARRAY_AS)
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 objectARRAY_AS- option to define if arrays are considered SETS, LISTS OR MULTISET- Returns:
- a new JsObj of the same type as the inputs (mutable or immutable)
-
union
JsObj union(JsObj that)
returnsthisjson object plus those pairs from the given json objectthatwhich keys don't exist inthis. Taking that into account, it's not a commutative operation unless the elements associated with the keys that exist in both json objects are equals.- Parameters:
that- the given json object- Returns:
- a new JsObj of the same type as the inputs (mutable or immutable)
-
union_
JsObj union_(JsObj that, JsArray.TYPE ARRAY_AS)
behaves like theunion(JsObj)but, for those keys that exit in boththisandthatjson objects, which associated elements are **containers of the same type**, the result is their union. In this case, we can specify if arrays are considered Sets, Lists, or MultiSets. So this operation is kind of a 'recursive' union.- Parameters:
that- the given json objectARRAY_AS- option to define if arrays are considered SETS, LISTS OR MULTISET- Returns:
- a new JsObj of the same type as the inputs (mutable or immutable)
-
of
static JsObj of(JsPair pair, JsPair... others)
Returns an immutable object from one or more pairs.- Parameters:
pair- a pairothers- more optional pairs- Returns:
- an immutable JsObject
- Throws:
UserError- if an elem of a pair is mutable
-
_of_
static JsObj _of_(JsPair pair, JsPair... others)
Returns a mutable object from one or more pairs.- Parameters:
pair- a pairothers- more optional pairs- Returns:
- a mutable JsObject
- Throws:
UserError- if an elem of a pair is immutable
-
ifEmptyElse
default <T> Trampoline<T> ifEmptyElse(Trampoline<T> empty, BiFunction<Map.Entry<String,JsElem>,JsObj,Trampoline<T>> fn)
-
isObj
default boolean isObj()
-
isArray
default boolean isArray()
-
-