Class JSONValueObjectImmutable
- java.lang.Object
-
- com.github.tnakamot.json.value.JSONValue
-
- com.github.tnakamot.json.value.JSONValueStructured
-
- com.github.tnakamot.json.value.JSONValueObject
-
- com.github.tnakamot.json.value.JSONValueObjectImmutable
-
- All Implemented Interfaces:
Map<JSONValueString,JSONValue>
public class JSONValueObjectImmutable extends JSONValueObject
Represents one JSON 'object' value (immutable).Instances of this class are immutable. Any method call that may result in the modification of the object (e.g.
put(JSONValueString, JSONValue)results inUnsupportedOperationException.This implementation retains the order.
- See Also:
JSONValueObjectMutable
-
-
Constructor Summary
Constructors Constructor Description JSONValueObjectImmutable(@Nullable Map<JSONValueString,JSONValue> members)Create an instance of a Java representation of a JSON 'object' value.JSONValueObjectImmutable(@Nullable Map<JSONValueString,JSONValue> members, @Nullable JSONToken begin, @Nullable JSONToken end)Create an instance of a Java representation of a JSON 'object' value.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()Deprecated.booleancontainsKey(Object o)booleancontainsKey(String name)Check if this JSON object has a value which has the given name.booleancontainsValue(Object o)@NotNull Set<Map.Entry<JSONValueString,JSONValue>>entrySet()JSONValueget(JSONValueString name)Returns the JSON value of the given name.JSONValueget(Object o)JSONValueget(String name)Returns the JSON value which has the given name.booleanisEmpty()@NotNull Set<JSONValueString>keySet()JSONValueput(JSONValueString jsonValueString, JSONValue jsonValue)Deprecated.voidputAll(@NotNull Map<? extends JSONValueString,? extends JSONValue> map)Deprecated.JSONValueremove(Object o)Deprecated.intsize()JSONValueObjectMutabletoMutable()Return the copy of this JSON object as a mutable Java object.@NotNull StringtoTokenString()Convert this JSON value toStringwhich can be saved as a JSON text to a file or transmitted to network.@NotNull StringtoTokenString(String newline, String indent)Convert this JSON value toStringwhich can be saved as a JSON text to a file or transmitted to network.@NotNull Collection<JSONValue>values()-
Methods inherited from class com.github.tnakamot.json.value.JSONValueObject
equals, getArray, getBoolean, getDouble, getLong, getObject, getString, hashCode, put, put, put, put, put, remove
-
Methods inherited from class com.github.tnakamot.json.value.JSONValueStructured
begin, end
-
Methods inherited from class com.github.tnakamot.json.value.JSONValue
toTokenBytes, toTokenBytes, type
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
JSONValueObjectImmutable
public JSONValueObjectImmutable(@Nullable @Nullable Map<JSONValueString,JSONValue> members)Create an instance of a Java representation of a JSON 'object' value.- Parameters:
members- name/value pairs. Null is considered as an empty object.
-
JSONValueObjectImmutable
public JSONValueObjectImmutable(@Nullable @Nullable Map<JSONValueString,JSONValue> members, @Nullable @Nullable JSONToken begin, @Nullable @Nullable JSONToken end)Create an instance of a Java representation of a JSON 'object' value.- Parameters:
members- name/value pairs. Null is considered as an empty object.begin- the beginning token of this JSON object. Null if this JSON object does not originate from an exsiting JSON text.end- the end token of this JSON object. Null if this JSON object does not originate from an exsiting JSON text.
-
-
Method Detail
-
get
public JSONValue get(JSONValueString name)
Returns the JSON value of the given name.If a value of the given name does not exist, this method returns null. Do not confuse it with a JSON 'null' value. If there is a JSON 'null' value of the given name, this method returns an instance of
JSONValueNullinstead.- Specified by:
getin classJSONValueObject- Parameters:
name- a JSON string value which represents a name- Returns:
- a JSON value of the given name
-
get
public JSONValue get(String name)
Returns the JSON value which has the given name.- Specified by:
getin classJSONValueObject- Parameters:
name- name- Returns:
- a JSON value of the given name
- See Also:
JSONValueObject.get(JSONValueString)
-
size
public int size()
- Specified by:
sizein interfaceMap<JSONValueString,JSONValue>- Specified by:
sizein classJSONValueObject
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceMap<JSONValueString,JSONValue>- Specified by:
isEmptyin classJSONValueObject
-
containsKey
public boolean containsKey(Object o)
- Specified by:
containsKeyin interfaceMap<JSONValueString,JSONValue>- Specified by:
containsKeyin classJSONValueObject
-
containsKey
public boolean containsKey(String name)
Check if this JSON object has a value which has the given name.- Specified by:
containsKeyin classJSONValueObject- Parameters:
name- name- Returns:
- true if a value with the given name exists
- See Also:
JSONValueObject.containsKey(Object)
-
containsValue
public boolean containsValue(Object o)
- Specified by:
containsValuein interfaceMap<JSONValueString,JSONValue>- Specified by:
containsValuein classJSONValueObject
-
get
public JSONValue get(Object o)
- Specified by:
getin interfaceMap<JSONValueString,JSONValue>- Specified by:
getin classJSONValueObject
-
put
@Deprecated public JSONValue put(JSONValueString jsonValueString, JSONValue jsonValue)
Deprecated.- Specified by:
putin interfaceMap<JSONValueString,JSONValue>- Specified by:
putin classJSONValueObject
-
remove
@Deprecated public JSONValue remove(Object o)
Deprecated.- Specified by:
removein interfaceMap<JSONValueString,JSONValue>- Specified by:
removein classJSONValueObject
-
putAll
@Deprecated public void putAll(@NotNull @NotNull Map<? extends JSONValueString,? extends JSONValue> map)
Deprecated.- Specified by:
putAllin interfaceMap<JSONValueString,JSONValue>- Specified by:
putAllin classJSONValueObject
-
clear
@Deprecated public void clear()
Deprecated.- Specified by:
clearin interfaceMap<JSONValueString,JSONValue>- Specified by:
clearin classJSONValueObject
-
keySet
@NotNull public @NotNull Set<JSONValueString> keySet()
- Specified by:
keySetin interfaceMap<JSONValueString,JSONValue>- Specified by:
keySetin classJSONValueObject
-
values
@NotNull public @NotNull Collection<JSONValue> values()
- Specified by:
valuesin interfaceMap<JSONValueString,JSONValue>- Specified by:
valuesin classJSONValueObject
-
entrySet
@NotNull public @NotNull Set<Map.Entry<JSONValueString,JSONValue>> entrySet()
- Specified by:
entrySetin interfaceMap<JSONValueString,JSONValue>- Specified by:
entrySetin classJSONValueObject
-
toMutable
public JSONValueObjectMutable toMutable()
Return the copy of this JSON object as a mutable Java object.All inner JSON objects and JSON arrays are also turned to be mutable.
- Returns:
- a mutable version of the same JSON object.
-
toTokenString
@NotNull public @NotNull String toTokenString()
Description copied from class:JSONValueConvert this JSON value toStringwhich can be saved as a JSON text to a file or transmitted to network. The output text is optimized for machine, so no indent or new lines will be inserted.Note that, according to RFC 8259 - 8.1 Character Encoding, your application program must encode the returned String using UTF-8 without BOM before writing the returned
Stringto a file or a network stream, or network datagram(s). It is caller's responsibility to correctly encode it.- Specified by:
toTokenStringin classJSONValue- Returns:
- a string representation of this JSON value
-
toTokenString
@NotNull public @NotNull String toTokenString(String newline, String indent)
Description copied from class:JSONValueConvert this JSON value toStringwhich can be saved as a JSON text to a file or transmitted to network. The output text is optimized for human. Indents and new line characters are inserted accordingly.Note that, according to RFC 8259 - 8.1 Character Encoding, your application program must encode the returned String using UTF-8 without BOM before writing the returned
Stringto a file or a network stream, or network datagram(s). It is caller's responsibility to correctly encode it.- Specified by:
toTokenStringin classJSONValue- Parameters:
newline- line separator; "\r", "\n" or "\r\n"indent- indent string. Must consist of " " and "\t".- Returns:
- a string representation of this JSON value
-
-