public class JsonML extends Object
Constructor and Description |
---|
JsonML(TagType type)
Creates a new element with a given type.
|
JsonML(TagType type,
JsonML... children)
Creates a new element.
|
JsonML(TagType type,
List<? extends JsonML> children) |
JsonML(TagType type,
Map<? extends TagAttr,?> attributes) |
JsonML(TagType type,
Map<? extends TagAttr,?> attributes,
List<? extends JsonML> children) |
Modifier and Type | Method and Description |
---|---|
void |
addChild(int index,
JsonML element)
Inserts the given JsonML element at the given position in the
list of children.
|
void |
appendChild(JsonML element)
Appends a given child element to the list of children.
|
void |
appendChildren(Collection<? extends JsonML> elements)
Appends a collection of children to the back of the list of children.
|
int |
childrenSize()
Returns number of the children.
|
void |
clearChildren()
Removes all elements from the list of children.
|
Object |
getAttribute(TagAttr name)
Returns value associated with a given attribute.
|
Map<TagAttr,Object> |
getAttributes()
Returns a map with attributes and respective values.
|
JsonML |
getChild(int index)
Returns child at a given position.
|
List<JsonML> |
getChildren()
Returns a list of all children.
|
List<JsonML> |
getChildren(int fromIndex,
int toIndex)
Returns the portion of children list between the specified
fromIndex, inclusive, and toIndex, exclusive.
|
TagType |
getType()
Returns type of the JsonML element.
|
boolean |
hasChildren()
Returns true if the JsonML element has at least one child.
|
void |
setAttribute(TagAttr name,
Object value)
Sets value for a given attribute.
|
void |
setAttributes(Map<TagAttr,Object> attributes)
Sets attributes of the JsonML element.
|
void |
setChild(int index,
JsonML element)
Replaces the element at the given position in the list of children wit
the given JsonML element.
|
void |
setChildren(JsonML... children)
Replaces all elements in the list of children with the given
JsonML elements.
|
void |
setChildren(List<JsonML> children)
Replaces all elements in the list of children with the given
list of JsonML elements..
|
String |
toString() |
String |
toStringTree()
Prints a JsonML tree in a human readable format.
|
public JsonML(TagType type)
type
- public JsonML(TagType type, JsonML... children)
type
- type of the elementchildren
- children to append to the elementpublic void addChild(int index, JsonML element)
index
- index at which the given element is to be insertedelement
- JsonML element to be insertedpublic void appendChild(JsonML element)
element
- JsonML element to appendpublic void appendChildren(Collection<? extends JsonML> elements)
elements
- collection of JsonML elements to appendpublic int childrenSize()
public void clearChildren()
public Object getAttribute(TagAttr name)
name
- name of the attributepublic Map<TagAttr,Object> getAttributes()
public JsonML getChild(int index)
public List<JsonML> getChildren(int fromIndex, int toIndex)
fromIndex
- low endpoint (inclusive)toIndex
- high endpoint (exclusive)public TagType getType()
public boolean hasChildren()
public void setAttribute(TagAttr name, Object value)
name
- name of the attributevalue
- value to associate with the attributepublic void setAttributes(Map<TagAttr,Object> attributes)
attributes
- map with attributes and their valuespublic void setChild(int index, JsonML element)
index
- index of element to replaceelement
- JsonML element to appendpublic void setChildren(JsonML... children)
children
- a comma separated list of JsonML elementspublic void setChildren(List<JsonML> children)
children
- a list of JsonML elements.public String toStringTree()