public interface Parent extends java.lang.Cloneable, NamespaceAware, java.io.Serializable
Modifier and Type | Method and Description |
---|---|
Parent |
addContent(java.util.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.
|
Parent |
addContent(int index,
java.util.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.
|
void |
canContainContent(Content content,
int index,
boolean replace)
Test whether this Parent instance can contain the specified content
at the specified position.
|
java.lang.Object |
clone()
Obtain a deep, unattached copy of this parent and its children.
|
java.util.List<Content> |
cloneContent()
Returns a list containing detached clones of this parent's content list.
|
java.util.List<Content> |
getContent()
Returns the full content of this parent as a
List
which contains objects of type Content . |
<E extends Content> |
getContent(Filter<E> filter)
Returns as a
List the content of
this parent that matches the supplied filter. |
Content |
getContent(int index)
Returns the child at the given index.
|
int |
getContentSize()
Returns the number of children in this parent's content list.
|
IteratorIterable<Content> |
getDescendants()
Returns an
Iterator that walks over all descendants
in document order. |
<E extends Content> |
getDescendants(Filter<E> filter)
Returns an
Iterator 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.
|
java.util.List<Content> |
removeContent()
Removes all content from this parent and returns the detached
children.
|
boolean |
removeContent(Content child)
Removes a single child node from the content list.
|
<E extends Content> |
removeContent(Filter<E> filter)
Removes from this parent all child content matching the given filter
and returns a list of 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.
|
getNamespacesInherited, getNamespacesInScope, getNamespacesIntroduced
int getContentSize()
Content
type.int indexOf(Content child)
child
- child to search forjava.util.List<Content> cloneContent()
Content getContent(int index)
index
- location of desired childjava.lang.IndexOutOfBoundsException
- if index is negative or beyond
the current number of childrenjava.lang.IllegalStateException
- if parent is a Document
and the root element is not setjava.util.List<Content> getContent()
List
which contains objects of type Content
. 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.
java.lang.IllegalStateException
- if parent is a Document
and the root element is not set<E extends Content> java.util.List<E> getContent(Filter<E> filter)
List
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.
E
- The Generic type of the returned content (the Filter's type)filter
- filter to apply.
Note that the Filters
class has a number of predefined, useful
filters.java.lang.IllegalStateException
- if parent is a Document
and the root element is not setjava.util.List<Content> removeContent()
<E extends Content> java.util.List<E> removeContent(Filter<E> filter)
E
- The Generic type of the content to remove.filter
- filter to apply
Note that the Filters
class has a number of predefined, useful
filters.boolean removeContent(Content child)
child
- child to removeContent removeContent(int index)
index
- index of child to removejava.lang.IndexOutOfBoundsException
- if index is negative or beyond
the current number of childrenjava.lang.Object clone()
IteratorIterable<Content> getDescendants()
Iterator
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 (Iteratorandit = 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
<E extends Content> IteratorIterable<E> getDescendants(Filter<E> filter)
Iterator
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 (Iteratorandit = 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
E
- The generic type of the returned descendant datafilter
- filter to select which descendants to see
Note that the Filters
class has a number of predefined, useful
filters.Parent getParent()
Document getDocument()
void canContainContent(Content content, int index, boolean replace) throws IllegalAddException
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.IllegalAddException
- if there is a problem with the contentParent addContent(Content child)
child
- child to append to end of content listIllegalAddException
- if the given child already has a parent.Parent addContent(java.util.Collection<? extends Content> c)
c
- collection to appendIllegalAddException
- if any item in the collection
already has a parent or is of an illegal type.Parent addContent(int index, Content child)
index
- location for adding the collectionchild
- child to insertjava.lang.IndexOutOfBoundsException
- if index is negative or beyond
the current number of childrenIllegalAddException
- if the given child already has a parent.Parent addContent(int index, java.util.Collection<? extends Content> c)
index
- location for adding the collectionc
- collection to insertjava.lang.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.Copyright © 2021 Jason Hunter, Brett McLaughlin. All Rights Reserved.