Class JSONValueObjectMutable
- 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.JSONValueObjectMutable
-
- All Implemented Interfaces:
Map<JSONValueString,JSONValue>
public class JSONValueObjectMutable extends JSONValueObject
Represents one JSON 'object' value (mutable).This implementation retains the order.
- See Also:
JSONValueObjectImmutable
-
-
Constructor Summary
Constructors Constructor Description JSONValueObjectMutable()
Create an instance of a Java representation of an empty JSON 'object' value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object o)
boolean
containsKey(String s)
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)
void
putAll(@NotNull Map<? extends JSONValueString,? extends JSONValue> map)
JSONValue
remove(Object o)
int
size()
JSONValueObjectImmutable
toImmutable()
Return the copy of this JSON object as an immutable Java object.JSONValueObjectImmutable
toImmutable(@Nullable JSONToken begin, @Nullable JSONToken end)
Return the copy of this JSON object as an immutable Java object with token information.@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
-
-
-
-
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:
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 s)
Check if this JSON object has a value which has the given name.- Specified by:
containsKey
in classJSONValueObject
- Parameters:
s
- 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
public JSONValue put(JSONValueString jsonValueString, JSONValue jsonValue)
- Specified by:
put
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
put
in classJSONValueObject
-
remove
public JSONValue remove(Object o)
- Specified by:
remove
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
remove
in classJSONValueObject
-
putAll
public void putAll(@NotNull @NotNull Map<? extends JSONValueString,? extends JSONValue> map)
- Specified by:
putAll
in interfaceMap<JSONValueString,JSONValue>
- Specified by:
putAll
in classJSONValueObject
-
clear
public void clear()
- 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
-
toImmutable
public JSONValueObjectImmutable toImmutable()
Return the copy of this JSON object as an immutable Java object.All inner JSON objects and JSON arrays are also turned to be immutable.
- Returns:
- an immutable version of the same JSON object.
-
toImmutable
public JSONValueObjectImmutable toImmutable(@Nullable @Nullable JSONToken begin, @Nullable @Nullable JSONToken end)
Return the copy of this JSON object as an immutable Java object with token information.All inner JSON objects and JSON arrays are also turned to be immutable.
- Parameters:
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.- Returns:
- an immutable 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
-
-