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 void
clear()
Deprecated.boolean
containsKey(Object o)
boolean
containsKey(String name)
Check if this JSON object has a value which has the given name.boolean
containsValue(Object o)
@NotNull Set<Map.Entry<JSONValueString,JSONValue>>
entrySet()
JSONValue
get(JSONValueString name)
Returns the JSON value of the given name.JSONValue
get(Object o)
JSONValue
get(String name)
Returns the JSON value which has the given name.boolean
isEmpty()
@NotNull Set<JSONValueString>
keySet()
JSONValue
put(JSONValueString jsonValueString, JSONValue jsonValue)
Deprecated.void
putAll(@NotNull Map<? extends JSONValueString,? extends JSONValue> map)
Deprecated.JSONValue
remove(Object o)
Deprecated.int
size()
JSONValueObjectMutable
toMutable()
Return the copy of this JSON object as a mutable Java object.@NotNull String
toTokenString()
Convert this JSON value toString
which can be saved as a JSON text to a file or transmitted to network.@NotNull String
toTokenString(String newline, String indent)
Convert this JSON value toString
which 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
JSONValueNull
instead.- Specified by:
get
in 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:
get
in classJSONValueObject
- Parameters:
name
- name- Returns:
- a JSON value of the given name
- See Also:
JSONValueObject.get(JSONValueString)
-
size
public int size()
- Specified by:
size
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
size
in classJSONValueObject
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
isEmpty
in classJSONValueObject
-
containsKey
public boolean containsKey(Object o)
- Specified by:
containsKey
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
containsKey
in classJSONValueObject
-
containsKey
public boolean containsKey(String name)
Check if this JSON object has a value which has the given name.- Specified by:
containsKey
in 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:
containsValue
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
containsValue
in classJSONValueObject
-
get
public JSONValue get(Object o)
- Specified by:
get
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
get
in classJSONValueObject
-
put
@Deprecated public JSONValue put(JSONValueString jsonValueString, JSONValue jsonValue)
Deprecated.- Specified by:
put
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
put
in classJSONValueObject
-
remove
@Deprecated public JSONValue remove(Object o)
Deprecated.- Specified by:
remove
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
remove
in classJSONValueObject
-
putAll
@Deprecated public void putAll(@NotNull @NotNull Map<? extends JSONValueString,? extends JSONValue> map)
Deprecated.- Specified by:
putAll
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
putAll
in classJSONValueObject
-
clear
@Deprecated public void clear()
Deprecated.- Specified by:
clear
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
clear
in classJSONValueObject
-
keySet
@NotNull public @NotNull Set<JSONValueString> keySet()
- Specified by:
keySet
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
keySet
in classJSONValueObject
-
values
@NotNull public @NotNull Collection<JSONValue> values()
- Specified by:
values
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
values
in classJSONValueObject
-
entrySet
@NotNull public @NotNull Set<Map.Entry<JSONValueString,JSONValue>> entrySet()
- Specified by:
entrySet
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
entrySet
in 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:JSONValue
Convert this JSON value toString
which 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
String
to a file or a network stream, or network datagram(s). It is caller's responsibility to correctly encode it.- Specified by:
toTokenString
in classJSONValue
- Returns:
- a string representation of this JSON value
-
toTokenString
@NotNull public @NotNull String toTokenString(String newline, String indent)
Description copied from class:JSONValue
Convert this JSON value toString
which 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
String
to a file or a network stream, or network datagram(s). It is caller's responsibility to correctly encode it.- Specified by:
toTokenString
in 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
-
-