|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractMap<K,V> java.util.HashMap<String,JsonValue> de.hpi.fgis.dude.util.data.json.JsonRecord
public class JsonRecord
JsonRecord
represents a Json record.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V> |
Nested classes/interfaces inherited from interface de.hpi.fgis.dude.util.data.json.JsonValue |
---|
JsonValue.JsonType |
Constructor Summary | |
---|---|
JsonRecord()
Initializes a JsonRecord . |
|
JsonRecord(int initialCapacity)
Initializes a JsonRecord with the passed initial capacity. |
|
JsonRecord(int initialCapacity,
float loadFactor)
Initializes a JsonRecord with the passed initial capacity and its load factor. |
|
JsonRecord(Map<? extends String,? extends JsonValue> initialData)
Initializes a new JsonRecord with the passed data. |
Method Summary | |
---|---|
int |
compareTo(JsonValue other)
Compares the current instance with the passed JsonValue . |
static JsonRecord |
createJsonRecord(String jsonCode)
Creates a JsonRecord instance based on the passed Json code. |
void |
fromJson(DuDeJsonParser<?> jsonParser)
Initializes the current instance using the passed DuDeJsonParser . |
String |
generateString()
Generates a concatenated String out of all values stored in this JsonRecord . |
JsonValue |
getJsonValue(String... path)
Returns the JsonValue specified by the passed path or null if the specified attribute does not exist. |
(package private) JsonValue |
getJsonValue(String currentAttributeName,
Iterator<String> path)
Returns the value that corresponds to the passed path. |
JsonValue.JsonType |
getType()
Returns JsonType.Record . |
JsonValue |
put(String key,
boolean value)
Puts the passed key and the corresponding JsonBoolean value into the JsonRecord . |
JsonValue |
put(String key,
double value)
Puts the passed key and the corresponding JsonNumber value into the JsonRecord . |
JsonValue |
put(String key,
int value)
Puts the passed key and the corresponding JsonNumber value into the JsonRecord . |
JsonValue |
put(String key,
JsonValue value)
Puts the passed key and JsonValue into the JsonRecord . |
JsonValue |
put(String key,
long value)
Puts the passed key and the corresponding JsonNumber value into the JsonRecord . |
JsonValue |
put(String key,
String str)
Puts the passed key and the corresponding JsonString value into the JsonRecord . |
JsonValue |
putCollection(String key,
Collection<? extends JsonValue> collection)
Puts a JsonArray generated out of the passed Collection and its key to this JsonRecord . |
JsonValue |
putMap(String key,
Map<String,? extends JsonValue> map)
Puts a JsonRecord generated out of the passed Map and its key to this JsonRecord . |
JsonValue |
putNull(String key)
Puts the passed key and JsonNull into the JsonRecord . |
JsonValue |
searchFor(String attributeName)
Returns the first occurrence of the passed attribute (using a recursive look-up). |
void |
toJson(DuDeJsonGenerator jsonGenerator)
Generates the Json code using the passed DuDeJsonGenerator . |
Methods inherited from class java.util.HashMap |
---|
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, remove, size, values |
Methods inherited from class java.util.AbstractMap |
---|
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface de.hpi.fgis.dude.util.data.json.JsonValue |
---|
size |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Constructor Detail |
---|
public JsonRecord()
JsonRecord
.
public JsonRecord(int initialCapacity)
JsonRecord
with the passed initial capacity.
initialCapacity
- The initial capacity of the record.public JsonRecord(Map<? extends String,? extends JsonValue> initialData)
JsonRecord
with the passed data.
initialData
- The data that will be added during the initialization.public JsonRecord(int initialCapacity, float loadFactor)
JsonRecord
with the passed initial capacity and its load factor.
initialCapacity
- The initial capacity of the record.loadFactor
- The load factor of the record.HashMap.HashMap(int, float)
Method Detail |
---|
public static JsonRecord createJsonRecord(String jsonCode) throws ParseException
JsonRecord
instance based on the passed Json code.
jsonCode
- The code that shall be converted into a JsonRecord
JsonRecord
.
ParseException
- If the passed Json code cannot be converted into a JsonRecord
.public JsonValue.JsonType getType()
JsonType.Record
.
getType
in interface JsonValue
JsonValue.getType()
public int compareTo(JsonValue other)
JsonValue
JsonValue
. Instances of different JsonValue.JsonType
s are ordered lexicographically except
for JsonValue.JsonType.Null
. The above mentioned requirements define the following order: null
== JsonValue.JsonType.Null
<
JsonValue.JsonType.Array
< JsonValue.JsonType.Boolean
< JsonValue.JsonType.Number
< JsonValue.JsonType.Record
< JsonValue.JsonType.String
.
compareTo
in interface JsonValue
compareTo
in interface Comparable<JsonValue>
Comparable.compareTo(Object)
public JsonValue searchFor(String attributeName)
attributeName
- The name of the attribute whose value is requested.
null
if such an attribute was not found.public JsonValue getJsonValue(String... path)
JsonValue
specified by the passed path or null
if the specified attribute does not exist.
path
- The path to the attribute.
JsonValue
.JsonValue getJsonValue(String currentAttributeName, Iterator<String> path)
currentAttributeName
- The currently observed attribute within the record. If this attribute does not exist, null
will be returned.path
- The rest of the path.
null
, if the path is invalid.public String generateString()
JsonRecord
. This method should be used instead of
AbstractMap.toString()
if the enclosed values should be concatenated without any separators and key information.
JsonRecord
.public JsonValue put(String key, JsonValue value)
JsonValue
into the JsonRecord
. If the passed value
is null
,
JsonNull
will be inserted instead.
put
in interface Map<String,JsonValue>
put
in class HashMap<String,JsonValue>
NullPointerException
- If null
was passed instead of a key.HashMap.put(Object, Object)
public JsonValue putNull(String key)
JsonNull
into the JsonRecord
.
key
- The key which shall be added with JsonNull
.
null
if there was no mapping for this key.
NullPointerException
- If null
was passed instead of a key.HashMap.put(Object, Object)
public JsonValue put(String key, boolean value)
JsonBoolean
value into the JsonRecord
. If the passed value
is
null
, JsonNull
will be inserted instead.
key
- The key that shall be added.value
- The boolean value whose Json representation shall be put into the JsonRecord
.
null
if there was no mapping for this key.
NullPointerException
- If null
was passed instead of a key.HashMap.put(Object, Object)
public JsonValue putCollection(String key, Collection<? extends JsonValue> collection)
JsonArray
generated out of the passed Collection
and its key to this JsonRecord
. If the passed value
is null
, JsonNull
will be used instead.
key
- The key that shall be put into the JsonRecord
.collection
- The Collection
that shall be converted into a JsonArray
and put into the JsonRecord
.
null
if there was no mapping for this key.
NullPointerException
- If null
was passed instead of a key.HashMap.put(Object, Object)
public JsonValue put(String key, int value)
JsonNumber
value into the JsonRecord
. If the passed value
is
null
, JsonNull
will be inserted instead.
key
- The key that shall be added.value
- The integer value whose Json representation shall be put into the JsonRecord
.
null
if there was no mapping for this key.
NullPointerException
- If null
was passed instead of a key.HashMap.put(Object, Object)
public JsonValue put(String key, long value)
JsonNumber
value into the JsonRecord
. If the passed value
is
null
, JsonNull
will be inserted instead.
key
- The key that shall be added.value
- The long value whose Json representation shall be put into the JsonRecord
.
null
if there was no mapping for this key.
NullPointerException
- If null
was passed instead of a key.HashMap.put(Object, Object)
public JsonValue put(String key, double value)
JsonNumber
value into the JsonRecord
. If the passed value
is
null
, JsonNull
will be inserted instead.
key
- The key that shall be added.value
- The double value whose Json representation shall be put into the JsonRecord
.
null
if there was no mapping for this key.
NullPointerException
- If null
was passed instead of a key.HashMap.put(Object, Object)
public JsonValue putMap(String key, Map<String,? extends JsonValue> map)
JsonRecord
generated out of the passed Map
and its key to this JsonRecord
. If the passed value is
null
, JsonNull
will be used instead.
key
- The key that shall be put into the JsonRecord
.map
- The Map
that shall be converted into a JsonRecord
and put into this JsonRecord
.
null
if there was no mapping for this key.
NullPointerException
- If null
was passed instead of a key.HashMap.put(Object, Object)
public JsonValue put(String key, String str)
JsonString
value into the JsonRecord
. If the passed value
is
null
, JsonNull
will be inserted instead.
key
- The key that shall be added.str
- The String whose Json representation shall be put into the JsonRecord
.
null
if there was no mapping for this key.
NullPointerException
- If null
was passed instead of a key.HashMap.put(Object, Object)
public void toJson(DuDeJsonGenerator jsonGenerator) throws org.codehaus.jackson.JsonGenerationException, IOException
Jsonable
DuDeJsonGenerator
.
toJson
in interface Jsonable
jsonGenerator
- The DuDeJsonGenerator
that is used internally.
org.codehaus.jackson.JsonGenerationException
- If an error occurs while generating the Json syntax.
IOException
- If an error occurs while writing to the output.public void fromJson(DuDeJsonParser<?> jsonParser) throws org.codehaus.jackson.JsonParseException, IOException
Jsonable
DuDeJsonParser
.
fromJson
in interface Jsonable
jsonParser
- The parser that is used for extracting the data out of the Json.
org.codehaus.jackson.JsonParseException
- If an error occurs while parsing the Json.
IOException
- If an error occurs while reading from the stream.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |