Package sk.antons.json.impl
Class JsonObjectImpl
- java.lang.Object
-
- sk.antons.json.impl.JsonValueImpl
-
- sk.antons.json.impl.JsonObjectImpl
-
- All Implemented Interfaces:
JsonGroup,JsonMember,JsonObject,JsonValue
public class JsonObjectImpl extends JsonValueImpl implements JsonObject, JsonGroup, JsonMember
- Author:
- antons
-
-
Field Summary
-
Fields inherited from class sk.antons.json.impl.JsonValueImpl
group
-
-
Constructor Summary
Constructors Constructor Description JsonObjectImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonObjectadd(String name, JsonValue value)Adds attribute ti this json object at last position.JsonObjectadd(String name, JsonValue value, int index)Adds attribute ti this json object at specified position.List<JsonValue>all(String name)Values of all attributes with specidied nameObjectasTemplateParam()Converts value to value usable for some template frameworks.JsonAttributeattr(int index)Reads n'th attribute of this json objectJsonAttributeattr(String name)Reads first attribute of this json object with specified nameList<JsonAttributeImpl>attrs()List<JsonAttribute>attrs(String name)Reads all attributes of this json object with specified namevoidclear()Clears all attributes from this json object.JsonValuecopy()Makes deep copy of this value.voidfindAll(PathMatcher matcher, List<JsonValue> values, List<String> path)JsonValuefindFirst(PathMatcher matcher, List<String> path)JsonValuefirst()Returns value of first attribute.JsonValuefirst(String name)Value of first attribute with specidied nameintfirstIndex(String name)Index of first attribute with specidied namebooleanisEmpty()Checks if object has any attribute.JsonValuelast()Returns value of last attribute.intmemberIndex(JsonMember m)voidremove()Removes this instance from parent object.voidremove(JsonAttribute attr)JsonObjectremoveAll(String name)Removes all values with specified name.JsonAttributeremoveAttr(int index)Removes n'th attribute from this json object.intsize()Size of json object.voidtoCompactString(StringBuilder sb)List<JsonAttribute>toList()Converts attributes to regular list.voidtoPrettyString(StringBuilder sb, String prefix, String indent)-
Methods inherited from class sk.antons.json.impl.JsonValueImpl
asArray, asBoolLiteral, asExpLiteral, asFracLiteral, asIntLiteral, asLiteral, asNullLiteral, asObject, asStringLiteral, findAll, findAllLiterals, findFirst, findFirstLiteral, group, isArray, isBoolLiteral, isDescendantOf, isExpLiteral, isFracLiteral, isIntLiteral, isLiteral, isNullLiteral, isObject, isStringLiteral, name, parent, parentIndex, path, pathAsString, replaceBy, setGroup, toCompactString, toPrettyString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface sk.antons.json.impl.JsonGroup
isDescendantOf
-
Methods inherited from interface sk.antons.json.impl.JsonMember
group, setGroup
-
Methods inherited from interface sk.antons.json.JsonValue
asArray, asBoolLiteral, asExpLiteral, asFracLiteral, asIntLiteral, asLiteral, asNullLiteral, asObject, asStringLiteral, findAll, findAllLiterals, findFirst, findFirstLiteral, isArray, isBoolLiteral, isDescendantOf, isExpLiteral, isFracLiteral, isIntLiteral, isLiteral, isNullLiteral, isObject, isStringLiteral, name, parent, parentIndex, path, pathAsString, replaceBy, toCompactString, toPrettyString
-
-
-
-
Method Detail
-
attrs
public List<JsonAttributeImpl> attrs()
-
toCompactString
public void toCompactString(StringBuilder sb)
- Specified by:
toCompactStringin classJsonValueImpl
-
toPrettyString
public void toPrettyString(StringBuilder sb, String prefix, String indent)
- Specified by:
toPrettyStringin classJsonValueImpl
-
isEmpty
public boolean isEmpty()
Description copied from interface:JsonObjectChecks if object has any attribute.- Specified by:
isEmptyin interfaceJsonObject- Returns:
- true if object has no attribute
-
size
public int size()
Description copied from interface:JsonObjectSize of json object.- Specified by:
sizein interfaceJsonObject- Returns:
- number of attributes.
-
clear
public void clear()
Description copied from interface:JsonObjectClears all attributes from this json object.- Specified by:
clearin interfaceJsonObject
-
attr
public JsonAttribute attr(int index)
Description copied from interface:JsonObjectReads n'th attribute of this json object- Specified by:
attrin interfaceJsonObject- Parameters:
index- of the attribute which is read (first attribute has index=0)- Returns:
- attribute at index position
-
first
public JsonValue first()
Description copied from interface:JsonObjectReturns value of first attribute.- Specified by:
firstin interfaceJsonObject- Returns:
- first attribute value or null if json object is empty
-
last
public JsonValue last()
Description copied from interface:JsonObjectReturns value of last attribute.- Specified by:
lastin interfaceJsonObject- Returns:
- last attribute value or null if json object is empty
-
removeAttr
public JsonAttribute removeAttr(int index)
Description copied from interface:JsonObjectRemoves n'th attribute from this json object.- Specified by:
removeAttrin interfaceJsonObject- Parameters:
index- position of attribute which should be removed- Returns:
- remoced attribute
-
toList
public List<JsonAttribute> toList()
Description copied from interface:JsonObjectConverts attributes to regular list.- Specified by:
toListin interfaceJsonObject- Returns:
-
add
public JsonObject add(String name, JsonValue value)
Description copied from interface:JsonObjectAdds attribute ti this json object at last position.- Specified by:
addin interfaceJsonObject- Parameters:
name- name of the attributevalue- value of the attribute- Returns:
- this json object
-
add
public JsonObject add(String name, JsonValue value, int index)
Description copied from interface:JsonObjectAdds attribute ti this json object at specified position.- Specified by:
addin interfaceJsonObject- Parameters:
name- name of the attributevalue- value of the attributeindex- position of the attribute- Returns:
- this json object
-
firstIndex
public int firstIndex(String name)
Description copied from interface:JsonObjectIndex of first attribute with specidied name- Specified by:
firstIndexin interfaceJsonObject- Parameters:
name- name of the attribute which should be found- Returns:
- index fist attribute with the name of null if it is not found
-
first
public JsonValue first(String name)
Description copied from interface:JsonObjectValue of first attribute with specidied name- Specified by:
firstin interfaceJsonObject- Parameters:
name- name of the attribute which should be found- Returns:
- value of fist attribute with the name of null if it is not found
-
all
public List<JsonValue> all(String name)
Description copied from interface:JsonObjectValues of all attributes with specidied name- Specified by:
allin interfaceJsonObject- Parameters:
name- name of the attributes which should be found- Returns:
- values of all attributes with the name
-
removeAll
public JsonObject removeAll(String name)
Description copied from interface:JsonObjectRemoves all values with specified name.- Specified by:
removeAllin interfaceJsonObject- Parameters:
name- of attributes to be removed- Returns:
- this json object
-
memberIndex
public int memberIndex(JsonMember m)
- Specified by:
memberIndexin interfaceJsonGroup
-
findFirst
public JsonValue findFirst(PathMatcher matcher, List<String> path)
- Specified by:
findFirstin classJsonValueImpl
-
findAll
public void findAll(PathMatcher matcher, List<JsonValue> values, List<String> path)
- Specified by:
findAllin classJsonValueImpl
-
attr
public JsonAttribute attr(String name)
Description copied from interface:JsonObjectReads first attribute of this json object with specified name- Specified by:
attrin interfaceJsonObject- Parameters:
name- of the attribute which is read (first attribute with the name will be returned)- Returns:
- first attribute with the name
-
attrs
public List<JsonAttribute> attrs(String name)
Description copied from interface:JsonObjectReads all attributes of this json object with specified name- Specified by:
attrsin interfaceJsonObject- Parameters:
name- of the attributes which is read (all attributes with the name will be returned)- Returns:
- all attributes with the name
-
remove
public void remove(JsonAttribute attr)
-
remove
public void remove()
Description copied from interface:JsonValueRemoves this instance from parent object.- Specified by:
removein interfaceJsonValue- Overrides:
removein classJsonValueImpl
-
copy
public JsonValue copy()
Description copied from interface:JsonValueMakes deep copy of this value.
-
asTemplateParam
public Object asTemplateParam()
Description copied from interface:JsonValueConverts value to value usable for some template frameworks. - JsonObjects is converted to read only Map - JsonArray is converted to read only List - JsonLiteral is converted to its java value- Specified by:
asTemplateParamin interfaceJsonValue- Returns:
- template parameter form of this value
-
-