Class JsonObject
- java.lang.Object
-
- com.alachisoft.ncache.runtime.JSON.JsonValueBase
-
- com.alachisoft.ncache.runtime.JSON.JsonObject
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<java.util.Map.Entry<java.lang.String,JsonValueBase>>
public final class JsonObject extends JsonValueBase implements java.io.Serializable, java.lang.Iterable<java.util.Map.Entry<java.lang.String,JsonValueBase>>
Class represents JObject in JSON standards- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JsonObject()
Defafault constructorJsonObject(java.lang.String json, java.lang.String type)
Overloaded constructor which populates attributes by parsing given JSONObject string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttribute(java.lang.String attributeName, JsonValue attributeValue)
Adds an attribute in the object.void
addAttribute(java.lang.String attributeName, JsonValueBase attributeValue)
Adds an attribute in the object.void
clear()
Removes all attributes from JSONObject.boolean
containsAttribute(java.lang.String attributeName)
Checks if the attribute exits.boolean
equals(java.lang.Object obj)
Checks if an obj is equal to this instance of JSONObjectjava.util.Collection<java.lang.String>
getAttributeNames()
Retruns collection of all the attribute names.JsonValueBase
getAttributeValue(java.lang.String attributeName)
Gets attribute value identified by the attribute name.int
getCount()
Gets the number of attributes in the json object.protected int
getInMemorySize()
Gets the In-Memory size of the json object.JsonValueBase
getItem(java.lang.String attributeName)
Gets the value of the specified attribute in java object.java.util.Iterator<java.util.Map.Entry<java.lang.String,JsonValueBase>>
getIterator()
Returns theIterator
that iterates through JSONObject attributes.protected int
getSize()
Gets the size occupied by the json object.java.lang.String
getType()
Gets the type attribute of the json object.java.lang.Object
getValue()
Gets the instance of the json object.java.util.Iterator<java.util.Map.Entry<java.lang.String,JsonValueBase>>
iterator()
boolean
removeAttribute(java.lang.String attributeName)
Removes attribute from object on the basis of attribute name providedvoid
setItem(java.lang.String attributeName, JsonValueBase value)
Sets the value against the specified attribute name in the json object.void
setType(java.lang.String type)
Sets the type attribute of the json object.java.lang.String
toString()
Returns JSONObject in string representation.-
Methods inherited from class com.alachisoft.ncache.runtime.JSON.JsonValueBase
getDataType, parse, toJson
-
-
-
-
Method Detail
-
getItem
public JsonValueBase getItem(java.lang.String attributeName)
Gets the value of the specified attribute in java object.- Parameters:
attributeName
- The name of the attribute.- Returns:
- The value that exists against the attribure name.
-
iterator
public java.util.Iterator<java.util.Map.Entry<java.lang.String,JsonValueBase>> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.util.Map.Entry<java.lang.String,JsonValueBase>>
-
setItem
public void setItem(java.lang.String attributeName, JsonValueBase value) throws OperationFailedException
Sets the value against the specified attribute name in the json object.- Parameters:
attributeName
- The name of the attribute.value
- The value that is to be set against the attribute name.- Throws:
OperationFailedException
-
getCount
public int getCount()
Gets the number of attributes in the json object.- Returns:
- The number of attributes.
-
getValue
public java.lang.Object getValue()
Gets the instance of the json object.- Overrides:
getValue
in classJsonValueBase
- Returns:
- The instance of the json object.
-
getSize
protected int getSize()
Gets the size occupied by the json object.- Overrides:
getSize
in classJsonValueBase
- Returns:
- The size occupied by json object.
-
getInMemorySize
protected int getInMemorySize()
Gets the In-Memory size of the json object.- Overrides:
getInMemorySize
in classJsonValueBase
- Returns:
- The In-Memory size of the json object.
-
setType
public void setType(java.lang.String type)
Sets the type attribute of the json object.- Parameters:
type
- The type attribute of the json object as string.
-
getType
public java.lang.String getType()
Gets the type attribute of the json object.- Returns:
- The type attribute of the json object.
-
getAttributeNames
public java.util.Collection<java.lang.String> getAttributeNames()
Retruns collection of all the attribute names.- Returns:
- All attribute name as collection.
-
addAttribute
public void addAttribute(java.lang.String attributeName, JsonValue attributeValue) throws OperationFailedException
Adds an attribute in the object.- Parameters:
attributeName
- Name of the attribute.attributeValue
- JSONValue as the attribute value.- Throws:
OperationFailedException
-
addAttribute
public void addAttribute(java.lang.String attributeName, JsonValueBase attributeValue) throws OperationFailedException
Adds an attribute in the object.- Parameters:
attributeName
- Name of the attribute.attributeValue
- JsonValueBase as the attribute value.- Throws:
OperationFailedException
-
removeAttribute
public boolean removeAttribute(java.lang.String attributeName)
Removes attribute from object on the basis of attribute name provided- Parameters:
attributeName
- The name of the attribute that is to be removed.- Returns:
- True if exists and removed succcessfully otherwise false.
-
getAttributeValue
public JsonValueBase getAttributeValue(java.lang.String attributeName)
Gets attribute value identified by the attribute name.- Parameters:
attributeName
- The name of the attribute.- Returns:
- The JsonValueBase corresponding to the attribute name and null if doesn't exist.
-
containsAttribute
public boolean containsAttribute(java.lang.String attributeName)
Checks if the attribute exits.- Parameters:
attributeName
- The name of attribute.- Returns:
- True if attribute exits otherwise false.
-
clear
public void clear()
Removes all attributes from JSONObject.
-
getIterator
public java.util.Iterator<java.util.Map.Entry<java.lang.String,JsonValueBase>> getIterator()
Returns theIterator
that iterates through JSONObject attributes.- Returns:
- The iterator instance.
-
equals
public boolean equals(java.lang.Object obj)
Checks if an obj is equal to this instance of JSONObject- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- The object that is to be compared with this object.- Returns:
- True if the specified object was equal to this object otherwise false.
-
toString
public java.lang.String toString()
Returns JSONObject in string representation.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The string representation of the json object.
-
-