Package com.kii.cloud.storage
Class KiiBaseObject
- java.lang.Object
-
- com.kii.cloud.storage.KiiBaseObject
-
- Direct Known Subclasses:
KiiObject
,KiiThing
,KiiUser
,ThingFields
,UserFields
public abstract class KiiBaseObject extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected org.json.JSONObject
mJSON
protected org.json.JSONObject
mJSONPatch
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Boolean
getBoolean(java.lang.String key)
Get boolean in the Entity associated with the key.java.lang.Boolean
getBoolean(java.lang.String key, java.lang.Boolean default_value)
Get boolean in the KiiBaseObject associated with the key.byte[]
getByteArray(java.lang.String key)
Get byte array associated with the key if exists, otherwise returns null.double
getDouble(java.lang.String key)
Get double in the Entity associated with the key.double
getDouble(java.lang.String key, double default_value)
Get double in the KiiBaseObject associated with the key.int
getInt(java.lang.String key)
Get int in the KiiBaseObject associated with the key.int
getInt(java.lang.String key, int default_value)
Get int in the KiiBaseObject associated with the key.org.json.JSONArray
getJsonArray(java.lang.String key)
Get JSONArray in the Entity associated with the key.org.json.JSONArray
getJSONArray(java.lang.String key, org.json.JSONArray default_value)
Get JSONArray in the KiiBaseObject associated with the key.org.json.JSONObject
getJSONObject(java.lang.String key)
Get JSONObject in the KiiBaseObject associated with the key.protected org.json.JSONObject
getJSONOfArbitraryFields()
Return json that contains key/value of keyset.long
getLong(java.lang.String key)
Get long in the KiiBaseObject associated with the key.long
getLong(java.lang.String key, long default_value)
Get long in the KiiBaseObject associated with the key.java.lang.Object
getObject(java.lang.String key)
Obtain value as Object.java.lang.Object
getObject(java.lang.String key, java.lang.Object fallback)
Get Object in the KiiBaseObject associated with the key.java.lang.String
getString(java.lang.String key)
Get String in the KiiBaseObject associated with the key.java.lang.String
getString(java.lang.String key, java.lang.String value)
Get String in the KiiBaseObject associated with the key.android.net.Uri
getUri(java.lang.String key)
Get Uri in the Entity associated with the key.boolean
has(java.lang.String key)
Determine if the KiiBaseObject contains a specific key.java.util.HashSet<java.lang.String>
keySet()
Get the key set of the object.void
remove(java.lang.String key)
Remove a pair of key/value from KiiBaseObjectprotected void
removeReserveProperty(java.lang.String key)
void
set(java.lang.String key, byte[] value)
Create/Update the key/value byte array in the KiiBaseObjectvoid
set(java.lang.String key, double value)
Create/Update association of the specified key with the specified double value in the KiiObject.void
set(java.lang.String key, int value)
Create/Update the key/value int in the KiiBaseObjectvoid
set(java.lang.String key, long value)
Create/Update the key/value long in the KiiBaseObjectvoid
set(java.lang.String key, android.net.Uri value)
Create/Update the key/value Uri in the KiiBaseObjectvoid
set(java.lang.String key, java.lang.Boolean value)
Create/Update the key/value boolean in the KiiBaseObjectvoid
set(java.lang.String key, java.lang.String value)
Create/Update the key/value string in the KiiBaseObjectvoid
set(java.lang.String key, org.json.JSONArray value)
Create/Update association of the specified key with the specified JSONArray value in the KiiObject.void
set(java.lang.String key, org.json.JSONObject value)
Create/Update the key/value JSONObject in the KiiBaseObject
-
-
-
Method Detail
-
keySet
@NonNull public java.util.HashSet<java.lang.String> keySet()
Get the key set of the object. The key set from local cache will be returned.
To get the latest key set from cloud, calling#refresh()
is necessary prior calling this method. On refresh, it replaces the local cache with the cloud one.
The returned key set does not include reserved keys such as email, username, etc.
Only includes arbitrary field keys set by application.
-
getJSONOfArbitraryFields
protected org.json.JSONObject getJSONOfArbitraryFields()
Return json that contains key/value of keyset.- Throws:
org.json.JSONException
-
set
public void set(@NonNull java.lang.String key, int value)
Create/Update the key/value int in the KiiBaseObject- Parameters:
key
- is Key stringvalue
- is Value int- Throws:
java.lang.IllegalArgumentException
- when key is empty, null or any reserve key.IllegalKiiBaseObjectFormatException
- if value contains illegal syntax
-
set
public void set(@NonNull java.lang.String key, long value)
Create/Update the key/value long in the KiiBaseObject- Parameters:
key
- is Key stringvalue
- is Value long- Throws:
java.lang.IllegalArgumentException
- when key is empty, null or any reserve key.IllegalKiiBaseObjectFormatException
- if value contains illegal syntax
-
has
public boolean has(@NonNull java.lang.String key)
Determine if the KiiBaseObject contains a specific key.- Parameters:
key
- is Key string- Returns:
- true if the key in exist in the KiiBaseObject
-
remove
public void remove(@NonNull java.lang.String key)
Remove a pair of key/value from KiiBaseObject- Parameters:
key
- to remove.- Throws:
java.lang.IllegalArgumentException
- when key is empty, null or any reserve key.
-
getByteArray
@Nullable public byte[] getByteArray(@NonNull java.lang.String key)
Get byte array associated with the key if exists, otherwise returns null.- Parameters:
key
- Key string.- Returns:
- value in byte array or null if the array is empty.
- Throws:
IllegalKiiBaseObjectFormatException
- Value retrieve error.
-
set
public void set(@NonNull java.lang.String key, @NonNull byte[] value)
Create/Update the key/value byte array in the KiiBaseObject- Parameters:
key
- is Key stringvalue
- in byte array- Throws:
IllegalKiiBaseObjectFormatException
- if contains illegal syntaxjava.lang.IllegalArgumentException
- when value is null, key is empty,null or or any reserve key.
-
getString
@NonNull public java.lang.String getString(@NonNull java.lang.String key)
Get String in the KiiBaseObject associated with the key.- Parameters:
key
- is Key string- Returns:
- value in String
- Throws:
IllegalKiiBaseObjectFormatException
- if not exist or contains illegal syntax
-
getObject
@NonNull public java.lang.Object getObject(@NonNull java.lang.String key)
Obtain value as Object.- Parameters:
key
- which corresponds to value to obtain.- Returns:
- value in Object.
- Throws:
IllegalKiiBaseObjectFormatException
- when the specified key is not exist in the object.
-
getObject
@Nullable public java.lang.Object getObject(@NonNull java.lang.String key, @Nullable java.lang.Object fallback)
Get Object in the KiiBaseObject associated with the key. Returns fallback when specified key is not exist.- Parameters:
key
- which corresponds to value to obtain.fallback
- returned when specified key is not exist.- Returns:
- value in Object.
-
getString
@Nullable public java.lang.String getString(@NonNull java.lang.String key, @Nullable java.lang.String value)
Get String in the KiiBaseObject associated with the key. If not exist or error, it will return default_value.- Parameters:
key
- is Key stringvalue
- is Default Value string- Returns:
- value in String
-
set
public void set(@NonNull java.lang.String key, @NonNull java.lang.String value)
Create/Update the key/value string in the KiiBaseObject- Parameters:
key
- is Key stringvalue
- is Value string- Throws:
java.lang.IllegalArgumentException
- when key is empty, null, any reserve key or value is nullIllegalKiiBaseObjectFormatException
- if value contains illegal syntax
-
getBoolean
@NonNull public java.lang.Boolean getBoolean(@NonNull java.lang.String key)
Get boolean in the Entity associated with the key.- Parameters:
key
- is Key string- Returns:
- value in boolean
- Throws:
IllegalKiiBaseObjectFormatException
- if not exist or contains illegal syntax
-
getBoolean
@NonNull public java.lang.Boolean getBoolean(@NonNull java.lang.String key, @NonNull java.lang.Boolean default_value)
Get boolean in the KiiBaseObject associated with the key. If not exit or error, it will return the default value- Parameters:
key
- is Key stringdefault_value
- is default value in boolean- Returns:
- value in boolean
-
getDouble
public double getDouble(@NonNull java.lang.String key)
Get double in the Entity associated with the key.- Parameters:
key
- is Key string- Returns:
- value in double
- Throws:
IllegalKiiBaseObjectFormatException
- if not exist or contains illegal syntax
-
getDouble
public double getDouble(@NonNull java.lang.String key, double default_value)
Get double in the KiiBaseObject associated with the key. If not exit or error, it will return the default value- Parameters:
key
- is Key stringdefault_value
- is default value in double- Returns:
- value in double
-
getJsonArray
@NonNull public org.json.JSONArray getJsonArray(@NonNull java.lang.String key)
Get JSONArray in the Entity associated with the key.- Parameters:
key
- is Key string- Returns:
- value in JSONArray
- Throws:
IllegalKiiBaseObjectFormatException
- if not exist or contains illegal syntax
-
getJSONArray
@NonNull public org.json.JSONArray getJSONArray(@NonNull java.lang.String key, @NonNull org.json.JSONArray default_value)
Get JSONArray in the KiiBaseObject associated with the key. If not exit or error, it will return the default value- Parameters:
key
- is Key stringdefault_value
- is default value in JSONArray- Returns:
- value in JSONArray
-
set
public void set(@NonNull java.lang.String key, @NonNull java.lang.Boolean value)
Create/Update the key/value boolean in the KiiBaseObject- Parameters:
key
- is Key stringvalue
- is Value boolean- Throws:
java.lang.IllegalArgumentException
- when key or value is empty,null, or any reserve key.IllegalKiiBaseObjectFormatException
- if value contains illegal syntax
-
set
public void set(@NonNull java.lang.String key, double value)
Create/Update association of the specified key with the specified double value in the KiiObject.
NOTE: Before involving floating point value, please consider using integer(int/long) instead. For example, use percentage, permil, ppm, etc. The reason is:- Will dramatically improve the performance of bucket query.
- Bucket query does not support the mixed result of integer and floating point. ex.) If you use same key for integer and floating point and inquire object with the integer value, objects which has double value with the key would not be evaluated in the query. (and vice versa)
- Parameters:
key
- Key string.value
- double value.- Throws:
java.lang.IllegalArgumentException
- when key or value is empty, null, or any reserve key.IllegalKiiBaseObjectFormatException
- if value contains illegal syntax
-
set
public void set(@NonNull java.lang.String key, @NonNull org.json.JSONArray value)
Create/Update association of the specified key with the specified JSONArray value in the KiiObject.- Parameters:
key
- Key string.value
- JSONArray value.- Throws:
java.lang.IllegalArgumentException
- when key or value is empty or nullIllegalKiiBaseObjectFormatException
- if value contains illegal syntax
-
set
public void set(@NonNull java.lang.String key, @NonNull android.net.Uri value)
Create/Update the key/value Uri in the KiiBaseObject- Parameters:
key
- is Key stringvalue
- is Uri- Throws:
java.lang.IllegalArgumentException
- when key or value is empty, null or the key is or any reserve key.IllegalKiiBaseObjectFormatException
- if value contains illegal syntax
-
getUri
@NonNull public android.net.Uri getUri(@NonNull java.lang.String key)
Get Uri in the Entity associated with the key.- Parameters:
key
- is Key string- Returns:
- value in Uri
- Throws:
IllegalKiiBaseObjectFormatException
- if not exist or contains illegal syntax
-
getInt
public int getInt(@NonNull java.lang.String key)
Get int in the KiiBaseObject associated with the key.- Parameters:
key
- is Key string- Returns:
- value in int
- Throws:
IllegalKiiBaseObjectFormatException
- if not exist or contains illegal syntax
-
getInt
public int getInt(@NonNull java.lang.String key, int default_value)
Get int in the KiiBaseObject associated with the key. If not exit or error, it will return the default value.- Parameters:
key
- is Key stringdefault_value
- is default value in int- Returns:
- value in int
-
getLong
public long getLong(@NonNull java.lang.String key)
Get long in the KiiBaseObject associated with the key.- Parameters:
key
- is Key string- Returns:
- value in long
- Throws:
IllegalKiiBaseObjectFormatException
- if not exist or contains illegal syntax
-
getLong
public long getLong(@NonNull java.lang.String key, long default_value)
Get long in the KiiBaseObject associated with the key. If not exit or error, it will return the default value.- Parameters:
key
- is Key stringdefault_value
- is default value in long- Returns:
- value in long
-
getJSONObject
@NonNull public org.json.JSONObject getJSONObject(@NonNull java.lang.String key)
Get JSONObject in the KiiBaseObject associated with the key.- Parameters:
key
- is Key string- Returns:
- value in JSONObject
- Throws:
IllegalKiiBaseObjectFormatException
- if not exist or contains illegal syntax
-
set
public void set(@NonNull java.lang.String key, @NonNull org.json.JSONObject value)
Create/Update the key/value JSONObject in the KiiBaseObject- Parameters:
key
- is Key stringvalue
- is JSONObject- Throws:
java.lang.IllegalArgumentException
- when key or value is empty or nullIllegalKiiBaseObjectFormatException
- if value contains illegal syntax
-
removeReserveProperty
protected void removeReserveProperty(java.lang.String key)
-
-