public final class Nodes extends Object implements Iterable<Node>
Implements a list of nodes for traversal purposes.
Changes to the document from which this list was generated
are not reflected in this list, nor are changes to the list
reflected in the document. Changes to the individual
Node
objects in the list and the document
are reflected in the other one.
There is no requirement that the list not contain duplicates, or that all the members come from the same document. It is simply a list of nodes.
Constructor and Description |
---|
Nodes()
Creates an empty node list.
|
Nodes(Node node)
Creates a node list containing a single node.
|
Modifier and Type | Method and Description |
---|---|
void | append(Node node)
Adds a node at the end of this list.
|
boolean | contains(Node node)
Determines whether a node is contained in this list.
|
Node | get(int index)
Returns the indexth node in the list.
|
void | insert(Node node,
int index)
Inserts a node at the indexth position in the list.
|
java.util.Iterator<Node> | iterator() |
Node | remove(int index)
Removes the indexthnode in the list.
|
int | size()
Returns the number of nodes in the list.
|
public Nodes()
Creates an empty node list.
public Nodes(Node node)
Creates a node list containing a single node.
node
- the node to insert in the listNullPointerException
- if node
is nullpublic int size()
Returns the number of nodes in the list. This is guaranteed to be non-negative.
public Node get(int index)
Returns the indexth node in the list.
The first node has index 0. The last node
has index size()-1
.
index
- the node to returnIndexOutOfBoundsException
- if index
is
negative or greater than or equal to the size of the listpublic Node remove(int index)
Removes the indexthnode in the list. Subsequent nodes have their indexes reduced by one.
index
- the node to removeIndexOutOfBoundsException
- if index is
negative or greater than or equal to the size of the listpublic void insert(Node node, int index)
Inserts a node at the indexth position in the list. Subsequent nodes have their indexes increased by one.
node
- the node to insertindex
- the position at which to insert the nodeIndexOutOfBoundsException
- if index
is
negative or strictly greater than the size of the listNullPointerException
- if node
is nullpublic void append(Node node)
Adds a node at the end of this list.
node
- the node to add to the listNullPointerException
- if node
is nullpublic boolean contains(Node node)
Determines whether a node is contained in this list.
node
- the node to search forCopyright 2002-2023 Elliotte Rusty Harold
elharo@ibiblio.org