/** * Returns the <code>index</code>th item in the collection. If * <code>index</code> is greater than or equal to the number of nodes in * the list, this returns <code>null</code>. * * TODO: What happens if index is out of range? * * @param index Index into the collection. * @return The node at the <code>index</code>th position in the * <code>NodeList</code>, or <code>null</code> if that is not a valid * index. */ public Node item(int index) { runTo(index); return (Node) this.elementAt(index); }
/** * Return the last fetched node. Needed to support the UnionPathIterator. * * @return the last fetched node. * @throws RuntimeException thrown if this NodeSet is not of * a cached type, and thus doesn't permit indexed access. */ public Node getCurrentNode() { if (!m_cacheNodes) throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!"); int saved = m_next; Node n = (m_next < m_firstFree) ? elementAt(m_next) : null; m_next = saved; // HACK: I think this is a bit of a hack. -sb return n; }
/** * Returns the next node in the set and advances the position of the * iterator in the set. After a NodeIterator is created, the first call * to nextNode() returns the first node in the set. * @return The next <code>Node</code> in the set being iterated over, or * <code>null</code> if there are no more members in that set. * @throws DOMException * INVALID_STATE_ERR: Raised if this method is called after the * <code>detach</code> method was invoked. */ public Node nextNode() throws DOMException { if ((m_next) < this.size()) { Node next = this.elementAt(m_next); m_next++; return next; } else return null; }
/** * Returns the <code>index</code>th item in the collection. If * <code>index</code> is greater than or equal to the number of nodes in * the list, this returns <code>null</code>. * * TODO: What happens if index is out of range? * * @param index Index into the collection. * @return The node at the <code>index</code>th position in the * <code>NodeList</code>, or <code>null</code> if that is not a valid * index. */ public Node item(int index) { runTo(index); return (Node) this.elementAt(index); }
/** * Return the last fetched node. Needed to support the UnionPathIterator. * * @return the last fetched node. * @throws RuntimeException thrown if this NodeSet is not of * a cached type, and thus doesn't permit indexed access. */ public Node getCurrentNode() { if (!m_cacheNodes) throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!"); int saved = m_next; Node n = (m_next < m_firstFree) ? elementAt(m_next) : null; m_next = saved; // HACK: I think this is a bit of a hack. -sb return n; }
/** * Returns the previous node in the set and moves the position of the * iterator backwards in the set. * @return The previous <code>Node</code> in the set being iterated over, * or<code>null</code> if there are no more members in that set. * @throws DOMException * INVALID_STATE_ERR: Raised if this method is called after the * <code>detach</code> method was invoked. * @throws RuntimeException thrown if this NodeSet is not of * a cached type, and hence doesn't know what the previous node was. */ public Node previousNode() throws DOMException { if (!m_cacheNodes) throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_ITERATE, null)); //"This NodeSet can not iterate to a previous node!"); if ((m_next - 1) > 0) { m_next--; return this.elementAt(m_next); } else return null; }
/** * Returns the next node in the set and advances the position of the * iterator in the set. After a NodeIterator is created, the first call * to nextNode() returns the first node in the set. * @return The next <code>Node</code> in the set being iterated over, or * <code>null</code> if there are no more members in that set. * @throws DOMException * INVALID_STATE_ERR: Raised if this method is called after the * <code>detach</code> method was invoked. */ public Node nextNode() throws DOMException { if ((m_next) < this.size()) { Node next = this.elementAt(m_next); m_next++; return next; } else return null; }
/** * Returns the previous node in the set and moves the position of the * iterator backwards in the set. * @return The previous <code>Node</code> in the set being iterated over, * or<code>null</code> if there are no more members in that set. * @throws DOMException * INVALID_STATE_ERR: Raised if this method is called after the * <code>detach</code> method was invoked. * @throws RuntimeException thrown if this NodeSet is not of * a cached type, and hence doesn't know what the previous node was. */ public Node previousNode() throws DOMException { if (!m_cacheNodes) throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_ITERATE, null)); //"This NodeSet can not iterate to a previous node!"); if ((m_next - 1) > 0) { m_next--; return this.elementAt(m_next); } else return null; }
/** * The set:has-same-node function returns true if the node set passed as the first argument shares * any nodes with the node set passed as the second argument. If there are no nodes that are in both * node sets, then it returns false. * * The Xalan extensions MethodResolver converts 'has-same-node' to 'hasSameNode'. * * Note: Not to be confused with hasSameNodes in the Xalan namespace, which returns true if * the two node sets contain the exactly the same nodes (perhaps in a different order), * otherwise false. * * @see <a href="http://www.exslt.org/">EXSLT</a> */ public static boolean hasSameNode(NodeList nl1, NodeList nl2) { NodeSet ns1 = new NodeSet(nl1); NodeSet ns2 = new NodeSet(nl2); for (int i = 0; i < ns1.getLength(); i++) { if (ns2.contains(ns1.elementAt(i))) return true; } return false; }
Node child = (Node) elementAt(i);
Node child = (Node) elementAt(i);
Node child = (Node) elementAt(i);
Node child = (Node) elementAt(i);
/** * Returns true if both node-sets contain the same set of nodes. * * @param nl1 NodeList for first node-set * @param nl2 NodeList for second node-set * @return true if nl1 and nl2 contain exactly the same set of nodes. */ public static boolean hasSameNodes(NodeList nl1, NodeList nl2) { NodeSet ns1 = new NodeSet(nl1); NodeSet ns2 = new NodeSet(nl2); if (ns1.getLength() != ns2.getLength()) return false; for (int i = 0; i < ns1.getLength(); i++) { Node n = ns1.elementAt(i); if (!ns2.contains(n)) return false; } return true; }
/** * The set:difference function returns the difference between two node sets - those nodes that * are in the node set passed as the first argument that are not in the node set passed as the * second argument. * * @param nl1 NodeList for first node-set. * @param nl2 NodeList for second node-set. * @return a NodeList containing the nodes in nl1 that are not in nl2. * * @see <a href="http://www.exslt.org/">EXSLT</a> */ public static NodeList difference(NodeList nl1, NodeList nl2) { NodeSet ns1 = new NodeSet(nl1); NodeSet ns2 = new NodeSet(nl2); NodeSet diff = new NodeSet(); diff.setShouldCacheNodes(true); for (int i = 0; i < ns1.getLength(); i++) { Node n = ns1.elementAt(i); if (!ns2.contains(n)) diff.addElement(n); } return diff; }
/** * The set:intersection function returns a node set comprising the nodes that are within * both the node sets passed as arguments to it. * * @param nl1 NodeList for first node-set. * @param nl2 NodeList for second node-set. * @return a NodeList containing the nodes in nl1 that are also * in nl2. * * @see <a href="http://www.exslt.org/">EXSLT</a> */ public static NodeList intersection(NodeList nl1, NodeList nl2) { NodeSet ns1 = new NodeSet(nl1); NodeSet ns2 = new NodeSet(nl2); NodeSet inter = new NodeSet(); inter.setShouldCacheNodes(true); for (int i = 0; i < ns1.getLength(); i++) { Node n = ns1.elementAt(i); if (ns2.contains(n)) inter.addElement(n); } return inter; }
/** * Returns the <code>index</code>th item in the collection. If * <code>index</code> is greater than or equal to the number of nodes in * the list, this returns <code>null</code>. * * TODO: What happens if index is out of range? * * @param index Index into the collection. * @return The node at the <code>index</code>th position in the * <code>NodeList</code>, or <code>null</code> if that is not a valid * index. */ public Node item(int index) { runTo(index); return (Node) this.elementAt(index); }
/** * Return the last fetched node. Needed to support the UnionPathIterator. * * @return the last fetched node. * @throws RuntimeException thrown if this NodeSet is not of * a cached type, and thus doesn't permit indexed access. */ public Node getCurrentNode() { if (!m_cacheNodes) throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!"); int saved = m_next; Node n = (m_next < m_firstFree) ? elementAt(m_next) : null; m_next = saved; // HACK: I think this is a bit of a hack. -sb return n; }
/** * Return the last fetched node. Needed to support the UnionPathIterator. * * @return the last fetched node. * @throws RuntimeException thrown if this NodeSet is not of * a cached type, and thus doesn't permit indexed access. */ public Node getCurrentNode() { if (!m_cacheNodes) throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!"); int saved = m_next; Node n = (m_next < m_firstFree) ? elementAt(m_next) : null; m_next = saved; // HACK: I think this is a bit of a hack. -sb return n; }
/** * Return the last fetched node. Needed to support the UnionPathIterator. * * @return the last fetched node. * @throws RuntimeException thrown if this NodeSet is not of * a cached type, and thus doesn't permit indexed access. */ public Node getCurrentNode() { if (!m_cacheNodes) throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!"); int saved = m_next; Node n = (m_next < m_firstFree) ? elementAt(m_next) : null; m_next = saved; // HACK: I think this is a bit of a hack. -sb return n; }