Package org.exolab.adaptx.xpath
Class NodeSet
java.lang.Object
org.exolab.adaptx.xpath.XPathResult
org.exolab.adaptx.xpath.NodeSet
- All Implemented Interfaces:
Serializable
Represents a node-set. A node-set is used as the result of an XPath
expression, and during the expression to keep track of nodes being
evaluated. As such, it is a mutable object. Care must be taken, as
a node-set is not thread-safe and must not be used by two XPath
expressions evaluating concurrently.
- Version:
- $Revision: 3739 $ $Date: 2003-05-13 10:01:12 +0200 (Tue, 13 May 2003) $
- Author:
- Keith Visco, Assaf Arkin
- See Also:
-
Field Summary
Fields inherited from class org.exolab.adaptx.xpath.XPathResult
BOOLEAN, NODE_SET, NUMBER, STRING, USER_DEFINED
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds all nodes from the specified node-set to this node-set without duplication.void
Adds all nodes from the specified node-set to this node-set.boolean
Adds the specified node to this node-set without duplication.boolean
Adds the specified node to this node-set.boolean
Returns the result as a boolean value.void
clear()
Removes all elements from this node-set.boolean
Returns true if the specified node is contained in this node-set.boolean
equals
(XPathResult result) Returns true if the given result is a node-set result and has the same set of nodes.int
Returns the type of this result.int
Returns the position of the specified node in this node-set.item
(int index) Returns the node at the specified index.Returns the result as a Java object.double
Returns the result as a number value.void
remove
(int index) Removes the specified node from the node-set.boolean
Removes the specified node from the node-set.int
size()
Returns the number of nodes in the node-set.Returns the result as a string value.toArray()
Returns an array containing all the nodes in this node-set.toString()
Returns the string representation of this NodeSet.
-
Constructor Details
-
NodeSet
public NodeSet()Constructs a new empty node-set. -
NodeSet
Constructs a new node-set with the specified node.- Parameters:
node
- The node to include in the node-set
-
NodeSet
public NodeSet(int size) Constructs a new empty node-set with the specified size. This constructor is used if the node-set is known to hold only the specified number of nodes.- Parameters:
size
- The expected node-set size
-
-
Method Details
-
getResultType
public int getResultType()Returns the type of this result.- Specified by:
getResultType
in classXPathResult
- Returns:
XPathResult.NODE_SET
-
booleanValue
public boolean booleanValue()Returns the result as a boolean value. Returns true if the node-set is not empty.- Specified by:
booleanValue
in classXPathResult
- Returns:
- The result as a boolean value
-
numberValue
public double numberValue()Returns the result as a number value. Returns the number value of the node's string value, orDouble.NaN
if the node-set is empty.- Specified by:
numberValue
in classXPathResult
- Returns:
- The result as a number value
-
stringValue
Returns the result as a string value. Returns the string value of the node that is first in document order, or the empty string if the node-set is empty.Note: currently returns the string value of the first node in the node-set.
- Specified by:
stringValue
in classXPathResult
- Returns:
- The result as a string value
-
javaObject
Returns the result as a Java object. Returns an object of typeNodeSet
representing this node-set.- Specified by:
javaObject
in classXPathResult
- Returns:
- The result as a Java object
-
equals
Returns true if the given result is a node-set result and has the same set of nodes.- Specified by:
equals
in classXPathResult
- Parameters:
result
- An XPath result- Returns:
- True if a node-set result and has same set of nodes
-
size
public int size()Returns the number of nodes in the node-set.- Returns:
- The number of nodes in the node-set
-
add
Adds the specified node to this node-set without duplication.- Parameters:
node
- The node to add to this node-set- Returns:
- True if the node was added, false if the node was already in this node-set
-
add
Adds the specified node to this node-set. This method allows control over whether or not to perform duplicate checking.- Parameters:
node
- The node to add to this node-setignoreDuplicates
- If true, do not perform duplicate checking- Returns:
- True if the node was added, false if the node was already in this node-set
-
add
Adds all nodes from the specified node-set to this node-set without duplication.- Parameters:
nodeSet
- The node-set from which to add nodes
-
add
Adds all nodes from the specified node-set to this node-set. This method allows control over whether or not to perform duplicate checking.- Parameters:
nodeSet
- The node-set from which to add nodesignoreDuplicates
- If true, do not perform duplicate checking *
-
contains
Returns true if the specified node is contained in this node-set.- Parameters:
node
- The specified node to search- Returns:
- True if the specified node is contained in this node-set
-
item
Returns the node at the specified index. ThrowsIndexOutOfBoundsException
is the index is out of range. The index is as returned byindexOf(org.exolab.adaptx.xpath.XPathNode)
.- Parameters:
index
- The position of the node to return
-
indexOf
Returns the position of the specified node in this node-set. Returns -1 i the node is not included in this node-set.The node's index is based on the order in which it was added to the node-set, minus any nodes of lower index position that were removed from the node-set. The index ranges between zero and size() - 1 (inclusive).
- Parameters:
node
- the Node to get the index for
-
remove
Removes the specified node from the node-set. Returns true if the node was found and removed, false if the node was not included in this node-set.- Parameters:
node
- The node to remove from this node-set- Returns:
- True if the node was removed
-
remove
public void remove(int index) Removes the specified node from the node-set. The node is identified by position. ThrowsIndexOutOfBoundsException
is the index is out of range. The index is as returned byindexOf(org.exolab.adaptx.xpath.XPathNode)
.- Parameters:
index
- The position of the node to remove
-
clear
public void clear()Removes all elements from this node-set. -
toArray
Returns an array containing all the nodes in this node-set. Returns an empty array if the node-set is empty.- Returns:
- An array containing all the nodes in this node-set
-
toString
Returns the string representation of this NodeSet. This will be the concatenation of the string values of all the nodes contained within this NodeSet
-