public interface Group extends Item
AbstractGroup, rather than
implement this interface directly.
Design consideration: we don't support removeChildren and setChild or alike, because they can be done easily with List's methods and getAttributeIndex.
Item,
Attributable,
Namespaceable,
BinableFIND_BY_PREFIX, FIND_BY_REGEX, FIND_BY_TAGNAME, FIND_IGNORE_CASE, FIND_RECURSIVE| Modifier and Type | Method and Description |
|---|---|
int |
coalesce(boolean recursive)
Coalesces children if they are siblings with the same type
instances of Textual, Textual.isCoalesceable returns true.
|
List<Item> |
detachChildren()
Detaches all children and returns them in a list.
|
List<Item> |
getChildren()
Gets all children.
|
Element |
getElement(String tname)
Gets the first Element-type child with the tag name.
|
Element |
getElement(String namespace,
String name,
int mode)
Gets the first Element-type child that matches the giving criteria.
|
int |
getElementIndex(int indexFrom,
String tname)
Gets the index of the first Element-type child with the specified name.
|
int |
getElementIndex(int indexFrom,
String namespace,
String name,
int mode)
Gets the index of the Element-type first child that match the specified
criteria.
|
Set<String> |
getElementNames()
Returns a readonly set of names of element children.
|
List<Element> |
getElements()
Returns a cloned copy of all element children
|
List<Element> |
getElements(String tname)
Gets a readonly list of children with the tag name.
|
List<Element> |
getElements(String namespace,
String name,
int mode)
Gets a readonly list of Element-type children that match the giving
criteria.
|
String |
getElementValue(String tname,
boolean trim)
Gets the text of the first Element-type child with the tag name,
with a trimming option.
|
String |
getElementValue(String namespace,
String name,
int mode,
boolean trim)
Gets the value of the first Element-type child that matches
the giving criteria, with a trimming option.
|
clone, detach, getDocument, getLocator, getName, getParent, getText, setLocator, setName, setParent, setTextList<Item> getChildren()
The returned list is "live". Any modification to it affects
the node. On the other hand, getElements(String) returns
a copy.
Unlike JDOM, it won't coalesce adjacent children automatically since it might violate the caller's expectation about List. Rather, we provide coalesce to let caller do the merging explicitly. Note: when building a iDOM tree from a source (SAXBuilder.build), coalesce() will be invoked automatically.
Note: not all items supports children. If this item doesn't, it returns an empty list. And, if any invocation tries to add vertices to the returned list will cause UnsupportOperationException.
List<Item> detachChildren()
Note: you cannot add children to anther Group by doing
group.addAll(e.getChildren()), because you have to detach
them first. Then, you could use this method:
group.addAll(e.detachChildren());
int coalesce(boolean recursive)
SAXBuilder.build will do the merging automatically.
recursive - true to coalesce all descendants;
false to coalesce only the direct childrenint getElementIndex(int indexFrom,
String namespace,
String name,
int mode)
Note: only Element-type children are returned, since others have no name.
indexFrom - the index to start searching from; 0 for beginningnamespace - the namespace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ignorename - the local name if FIND_BY_TAGNAME is not specified;
the tag name if FIND_BY_TAGNAME specified; null to ignoremode - the search mode; zero or any combination of
Item.FIND_xxx, except FIND_RECURSIVEint getElementIndex(int indexFrom,
String tname)
Note: only Element-type children are returned, since others have no name.
getChildren().add(getElementIndex(0, "pre:name"),
new Element("pre:another"));
indexFrom - the index to start searching from; 0 for beginningtname - the tag name (i.e., Namespaceable.getName)String getElementValue(String namespace, String name, int mode, boolean trim)
namespace - the namespace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ignorename - the local name if FIND_BY_TAGNAME is not specified;
the tag name if FIND_BY_TAGNAME specified; null to ignoreString getElementValue(String tname, boolean trim)
tname - the tag name (i.e., Namespaceable.getName)Element getElement(String namespace, String name, int mode)
Note: only Element-type children are returned. Depending on the mode, the searching is usually linear -- take O(n) to complete.
namespace - the namespace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ignorename - the local name if FIND_BY_TAGNAME is not specified;
the tag name if FIND_BY_TAGNAME specified; null to ignoremode - the search mode; zero or any combination of FIND_xxx.Element getElement(String tname)
Note: only Element-type children are returned. Also, we did some optimization for this method so its access time is nearly constant.
tname - the tag name (i.e., Namespaceable.getName)List<Element> getElements(String namespace, String name, int mode)
Unlike Element.getElementsByTagName(java.lang.String), this method only
returns child elements, excluding grand children and other descendants.
The returned list is a 'live-facade' of the real ones, so
the performance is good, and any modification to getChildren()
will affect it.
Note: only Element-type children are returned. Depending on the mode, the searching is usually linear -- take O(n) to complete.
namespace - the namespace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ignorename - the local name if FIND_BY_TAGNAME is not specified;
the tag name if FIND_BY_TAGNAME specified; null to ignoremode - the search mode; zero or any combination of FIND_xxx.List<Element> getElements(String tname)
Unlike Element.getElementsByTagName(java.lang.String), this method only
returns child elements, excluding grand children and other descendants.
The returned list is a 'live-facade' of the real ones, so
the performance is good, and any modification to getChildren()
will affect it.
Note: only Element-type children are returned. Also, we did some optimization for this method so its access time is nearly constant.
tname - the tag name (i.e., Namespaceable.getName)Set<String> getElementNames()
getElements(java.lang.String, java.lang.String, int) to get elements.
The returned list is a 'live-facade' of the real ones, so
the performance is good, and any modification to getChildren()
will affect it.
getElements()List<Element> getElements()
Unlike getChildren() and getElementNames(),
the returned list is NOT a 'live-facade' of the real ones.
getElementNames()Copyright © 2018. All rights reserved.