📄 nodesetdtm.java
字号:
insertIndex = this.size(); boolean foundit = false; for (int i = 0; i < insertIndex; i++) { if (i == node) { foundit = true; break; } } if (!foundit) addElement(node); } // checkDups(); return insertIndex; } // end addNodeInDocOrder(Vector v, Object obj) /** * Add the node into a vector of nodes where it should occur in * document order. * @param node The node to be added. * @param support The XPath runtime context. * * @return The index where it was inserted. * @throws RuntimeException thrown if this NodeSetDTM is not of * a mutable type. */ public int addNodeInDocOrder(int node, XPathContext support) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!"); return addNodeInDocOrder(node, true, support); } // end addNodeInDocOrder(Vector v, Object obj) /** * Get the length of the list. * * @return The size of this node set. */ public int size() { return super.size(); } /** * Append a Node onto the vector. * * @param value The node to be added. * @throws RuntimeException thrown if this NodeSetDTM is not of * a mutable type. */ public void addElement(int value) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!"); super.addElement(value); } /** * Inserts the specified node in this vector at the specified index. * Each component in this vector with an index greater or equal to * the specified index is shifted upward to have an index one greater * than the value it had previously. * * @param value The node to be inserted. * @param at The index where the insert should occur. * @throws RuntimeException thrown if this NodeSetDTM is not of * a mutable type. */ public void insertElementAt(int value, int at) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!"); super.insertElementAt(value, at); } /** * Append the nodes to the list. * * @param nodes The nodes to be appended to this node set. * @throws RuntimeException thrown if this NodeSetDTM is not of * a mutable type. */ public void appendNodes(NodeVector nodes) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!"); super.appendNodes(nodes); } /** * Inserts the specified node in this vector at the specified index. * Each component in this vector with an index greater or equal to * the specified index is shifted upward to have an index one greater * than the value it had previously. * @throws RuntimeException thrown if this NodeSetDTM is not of * a mutable type. */ public void removeAllElements() { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!"); super.removeAllElements(); } /** * Removes the first occurrence of the argument from this vector. * If the object is found in this vector, each component in the vector * with an index greater or equal to the object's index is shifted * downward to have an index one smaller than the value it had * previously. * * @param s The node to be removed. * * @return True if the node was successfully removed * @throws RuntimeException thrown if this NodeSetDTM is not of * a mutable type. */ public boolean removeElement(int s) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!"); return super.removeElement(s); } /** * Deletes the component at the specified index. Each component in * this vector with an index greater or equal to the specified * index is shifted downward to have an index one smaller than * the value it had previously. * * @param i The index of the node to be removed. * @throws RuntimeException thrown if this NodeSetDTM is not of * a mutable type. */ public void removeElementAt(int i) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!"); super.removeElementAt(i); } /** * Sets the component at the specified index of this vector to be the * specified object. The previous component at that position is discarded. * * The index must be a value greater than or equal to 0 and less * than the current size of the vector. * * @param node The node to be set. * @param index The index of the node to be replaced. * @throws RuntimeException thrown if this NodeSetDTM is not of * a mutable type. */ public void setElementAt(int node, int index) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!"); super.setElementAt(node, index); } /** * Same as setElementAt. * * @param node The node to be set. * @param index The index of the node to be replaced. * @throws RuntimeException thrown if this NodeSetDTM is not of * a mutable type. */ public void setItem(int node, int index) { if (!m_mutable) throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!"); super.setElementAt(node, index); } /** * Get the nth element. * * @param i The index of the requested node. * * @return Node at specified index. */ public int elementAt(int i) { runTo(i); return super.elementAt(i); } /** * Tell if the table contains the given node. * * @param s Node to look for * * @return True if the given node was found. */ public boolean contains(int s) { runTo(-1); return super.contains(s); } /** * Searches for the first occurence of the given argument, * beginning the search at index, and testing for equality * using the equals method. * * @param elem Node to look for * @param index Index of where to start the search * @return the index of the first occurrence of the object * argument in this vector at position index or later in the * vector; returns -1 if the object is not found. */ public int indexOf(int elem, int index) { runTo(-1); return super.indexOf(elem, index); } /** * Searches for the first occurence of the given argument, * beginning the search at index, and testing for equality * using the equals method. * * @param elem Node to look for * @return the index of the first occurrence of the object * argument in this vector at position index or later in the * vector; returns -1 if the object is not found. */ public int indexOf(int elem) { runTo(-1); return super.indexOf(elem); } /** If this node is being used as an iterator, the next index that nextNode() * will return. */ transient protected int m_next = 0; /** * Get the current position, which is one less than * the next nextNode() call will retrieve. i.e. if * you call getCurrentPos() and the return is 0, the next * fetch will take place at index 1. * * @return The the current position index. */ public int getCurrentPos() { return m_next; } /** * Set the current position in the node set. * @param i Must be a valid index. * @throws RuntimeException thrown if this NodeSetDTM is not of * a cached type, and thus doesn't permit indexed access. */ public void setCurrentPos(int i) { if (!m_cacheNodes) throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null)); //"This NodeSetDTM can not do indexing or counting functions!"); m_next = i; } /** * Return the last fetched node. Needed to support the UnionPathIterator. * * @return the last fetched node. * @throws RuntimeException thrown if this NodeSetDTM is not of * a cached type, and thus doesn't permit indexed access. */ public int getCurrentNode() { if (!m_cacheNodes) throw new RuntimeException( "This NodeSetDTM can not do indexing or counting functions!"); int saved = m_next; // because nextNode always increments // But watch out for copy29, where the root iterator didn't // have nextNode called on it. int current = (m_next > 0) ? m_next-1 : m_next; int n = (current < m_firstFree) ? elementAt(current) : DTM.NULL; m_next = saved; // HACK: I think this is a bit of a hack. -sb return n; } /** True if this list can be mutated. */ transient protected boolean m_mutable = true; /** True if this list is cached. * @serial */ transient protected boolean m_cacheNodes = true; /** The root of the iteration, if available. */ protected int m_root = DTM.NULL; /** * Get whether or not this is a cached node set. * * * @return True if this list is cached. */ public boolean getShouldCacheNodes() { return m_cacheNodes; } /** * If setShouldCacheNodes(true) is called, then nodes will * be cached. They are not cached by default. This switch must * be set before the first call to nextNode is made, to ensure * that all nodes are cached. * * @param b true if this node set should be cached. * @throws RuntimeException thrown if an attempt is made to * request caching after we've already begun stepping through the * nodes in this set. */ public void setShouldCacheNodes(boolean b) { if (!isFresh()) throw new RuntimeException( XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_CALL_SETSHOULDCACHENODE, null)); //"Can not call setShouldCacheNodes after nextNode has been called!"); m_cacheNodes = b; m_mutable = true; } /** * Tells if this iterator can have nodes added to it or set via * the <code>setItem(int node, int index)</code> method. * * @return True if the nodelist can be mutated. */ public boolean isMutable() { return m_mutable; } transient private int m_last = 0; public int getLast() { return m_last; } public void setLast(int last) { m_last = last; } /** * Returns true if all the nodes in the iteration well be returned in document * order. * * @return true as a default. */ public boolean isDocOrdered() { return true; } /** * Returns the axis being iterated, if it is known. * * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple * types. */ public int getAxis() { return -1; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -