Interface Parent
-
- All Superinterfaces:
Cloneable
,NamespaceAware
,Serializable
- All Known Implementing Classes:
Document
,Element
,LocatedElement
public interface Parent extends Cloneable, NamespaceAware, Serializable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Parent
addContent(int index, Collection<? extends Content> c)
Inserts the content in a collection into the content list at the given index.Parent
addContent(int index, Content child)
Inserts the child into the content list at the given index.Parent
addContent(Collection<? extends Content> c)
Appends all children in the given collection to the end of the content list.Parent
addContent(Content child)
Appends the child to the end of the content list.void
canContainContent(Content content, int index, boolean replace)
Test whether this Parent instance can contain the specified content at the specified position.Parent
clone()
Obtain a deep, unattached copy of this parent and it's children.List<Content>
cloneContent()
Returns a list containing detached clones of this parent's content list.List<Content>
getContent()
Content
getContent(int index)
Returns the child at the given index.<E extends Content>
List<E>getContent(Filter<E> filter)
Returns as aList
the content of this parent that matches the supplied filter.int
getContentSize()
Returns the number of children in this parent's content list.Iterator<Content>
getDescendants()
Returns anIterator
that walks over all descendants in document order.<E extends Content>
Iterator<E>getDescendants(Filter<E> filter)
Returns anIterator
that walks over all descendants in document order applying the Filter to return only content that match the filter rule.Document
getDocument()
Return this parent's owning document or null if the branch containing this parent is currently not attached to a document.Parent
getParent()
Return this parent's parent, or null if this parent is currently not attached to another parent.int
indexOf(Content child)
Returns the index of the supplied child in the content list, or -1 if not a child of this parent.List<Content>
removeContent()
Removes all content from this parent and returns the detached children.Content
removeContent(int index)
Removes and returns the child at the given index, or returns null if there's no such child.boolean
removeContent(Content child)
Removes a single child node from the content list.<E extends Content>
List<E>removeContent(Filter<E> filter)
Removes from this parent all child content matching the given filter and returns a list of the detached children.-
Methods inherited from interface org.jdom.NamespaceAware
getNamespacesInherited, getNamespacesInScope, getNamespacesIntroduced
-
-
-
-
Method Detail
-
getContentSize
int getContentSize()
Returns the number of children in this parent's content list. Children may be anyContent
type.- Returns:
- number of children
-
indexOf
int indexOf(Content child)
Returns the index of the supplied child in the content list, or -1 if not a child of this parent.- Parameters:
child
- child to search for- Returns:
- index of child, or -1 if not found
-
cloneContent
List<Content> cloneContent()
Returns a list containing detached clones of this parent's content list.- Returns:
- list of cloned child content
-
getContent
Content getContent(int index)
Returns the child at the given index.- Parameters:
index
- location of desired child- Returns:
- child at the given index
- Throws:
IndexOutOfBoundsException
- if index is negative or beyond the current number of childrenIllegalStateException
- if parent is a Document and the root element is not set
-
getContent
List<Content> getContent()
Returns the full content of this parent as aList
which contains objects of typeContent
. The returned list is "live" and in document order. Any modifications to it affect the element's actual contents. Modifications are checked for conformance to XML 1.0 rules.Sequential traversal through the List is best done with an Iterator since the underlying implement of
List.size()
may require walking the entire list and indexed lookups may require starting at the beginning each time.- Returns:
- a list of the content of the parent
- Throws:
IllegalStateException
- if parent is a Document and the root element is not set
-
getContent
<E extends Content> List<E> getContent(Filter<E> filter)
Returns as aList
the content of this parent that matches the supplied filter. The returned list is "live" and in document order. Any modifications to it affect the element's actual contents. Modifications are checked for conformance to XML 1.0 rules.Sequential traversal through the List is best done with an Iterator since the underlying implement of
List.size()
may require walking the entire list and indexed lookups may require starting at the beginning each time.- Type Parameters:
E
- The Generic type of the returned content (the Filter's type)- Parameters:
filter
- filter to apply. Note that theFilters
class has a number of predefined, useful filters.- Returns:
- a list of the content of the parent matching the filter
- Throws:
IllegalStateException
- if parent is a Document and the root element is not set
-
removeContent
List<Content> removeContent()
Removes all content from this parent and returns the detached children.- Returns:
- list of the old content detached from this parent
-
removeContent
<E extends Content> List<E> removeContent(Filter<E> filter)
Removes from this parent all child content matching the given filter and returns a list of the detached children.- Type Parameters:
E
- The Generic type of the content to remove.- Parameters:
filter
- filter to apply Note that theFilters
class has a number of predefined, useful filters.- Returns:
- list of the detached children matching the filter
-
removeContent
boolean removeContent(Content child)
Removes a single child node from the content list.- Parameters:
child
- child to remove- Returns:
- whether the removal occurred
-
removeContent
Content removeContent(int index)
Removes and returns the child at the given index, or returns null if there's no such child.- Parameters:
index
- index of child to remove- Returns:
- detached child at given index or null if no
- Throws:
IndexOutOfBoundsException
- if index is negative or beyond the current number of children
-
clone
Parent clone()
Obtain a deep, unattached copy of this parent and it's children.- Returns:
- a deep copy of this parent and it's children.
-
getDescendants
Iterator<Content> getDescendants()
Returns anIterator
that walks over all descendants in document order.Note that this method returns an IteratorIterable instance, which means that you can use it either as an Iterator, or an Iterable, allowing both:
for (Iterator
andit = parent.getDescendants(); it.hasNext();) { Content c = it.next(); .... } for (Content c : parent.getDescendants()) { .... }
The Iterator version is most useful if you need to do list modification on the iterator (using remove()), and for compatibility with JDOM 1.x- Returns:
- an iterator to walk descendants
-
getDescendants
<E extends Content> Iterator<E> getDescendants(Filter<E> filter)
Returns anIterator
that walks over all descendants in document order applying the Filter to return only content that match the filter rule. With filters you can match only Elements, only Comments, Elements or Comments, only Elements with a given name and/or prefix, and so on.Note that this method returns an IteratorIterable instance, which means that you can use it either as an Iterator, or an Iterable, allowing both:
for (Iterator
andit = parent.getDescendants(Filters.element()); it.hasNext();) { Element e = it.next(); .... } for (Element e : parent.getDescendants(Filters.element())) { .... }
The Iterator version is most useful if you need to do list modification on the iterator (using remove()), and for compatibility with JDOM 1.x- Type Parameters:
E
- The generic type of the returned descendant data- Parameters:
filter
- filter to select which descendants to see Note that theFilters
class has a number of predefined, useful filters.- Returns:
- an iterator to walk descendants that match a filter
-
getParent
Parent getParent()
Return this parent's parent, or null if this parent is currently not attached to another parent. This is the same method as in Content but also added to Parent to allow more easy up-the-tree walking.- Returns:
- this parent's parent or null if none
-
getDocument
Document getDocument()
Return this parent's owning document or null if the branch containing this parent is currently not attached to a document.- Returns:
- this child's owning document or null if none
-
canContainContent
void canContainContent(Content content, int index, boolean replace) throws IllegalAddException
Test whether this Parent instance can contain the specified content at the specified position.- Parameters:
content
- The content to be checkedindex
- The location where the content would be put.replace
- true if the intention is to replace the content already at the index.- Throws:
IllegalAddException
- if there is a problem with the content
-
addContent
Parent addContent(Content child)
Appends the child to the end of the content list.- Parameters:
child
- child to append to end of content list- Returns:
- the Parent instance on which the method was called
- Throws:
IllegalAddException
- if the given child already has a parent.
-
addContent
Parent addContent(Collection<? extends Content> c)
Appends all children in the given collection to the end of the content list. In event of an exception during add the original content will be unchanged and the objects in the supplied collection will be unaltered.- Parameters:
c
- collection to append- Returns:
- the document on which the method was called
- Throws:
IllegalAddException
- if any item in the collection already has a parent or is of an illegal type.
-
addContent
Parent addContent(int index, Content child)
Inserts the child into the content list at the given index.- Parameters:
index
- location for adding the collectionchild
- child to insert- Returns:
- the parent on which the method was called
- Throws:
IndexOutOfBoundsException
- if index is negative or beyond the current number of childrenIllegalAddException
- if the given child already has a parent.
-
addContent
Parent addContent(int index, Collection<? extends Content> c)
Inserts the content in a collection into the content list at the given index. In event of an exception the original content will be unchanged and the objects in the supplied collection will be unaltered.- Parameters:
index
- location for adding the collectionc
- collection to insert- Returns:
- the parent on which the method was called
- Throws:
IndexOutOfBoundsException
- if index is negative or beyond the current number of childrenIllegalAddException
- if any item in the collection already has a parent or is of an illegal type.
-
-