nodesequence.java

来自「java jdk 1.4的源码」· Java 代码 · 共 686 行 · 第 1/2 页

JAVA
686
字号
    	m_next++;    }    	    return next;  }  /**   * @see DTMIterator#previousNode()   */  public int previousNode()  {  	if(hasCache())  	{  		if(m_next <= 0)  			return DTM.NULL;  		else  		{  			m_next--;  			return item(m_next);  		}  	}  	else  	{	    int n = m_iter.previousNode();	    m_next = m_iter.getCurrentPos();	    return m_next;  	}  }  /**   * @see DTMIterator#detach()   */  public void detach()  {  	if(null != m_iter)  		m_iter.detach();  	super.detach();  }  /**   * Calling this with a value of false will cause the nodeset    * to be cached.   * @see DTMIterator#allowDetachToRelease(boolean)   */  public void allowDetachToRelease(boolean allowRelease)  {  	if((false == allowRelease) && !hasCache())  	{  		setShouldCacheNodes(true);  	}  	  	if(null != m_iter)  		m_iter.allowDetachToRelease(allowRelease);  	super.allowDetachToRelease(allowRelease);  }  /**   * @see DTMIterator#getCurrentNode()   */  public int getCurrentNode()  {  	if(hasCache())  	{  		int currentIndex = m_next-1;  		NodeVector vec = getVector();  		if((currentIndex >= 0) && (currentIndex < vec.size()))  			return vec.elementAt(currentIndex);  		else  			return DTM.NULL;  	}  	  	if(null != m_iter)  	{    	return m_iter.getCurrentNode();  	}  	else  		return DTM.NULL;  }  /**   * @see DTMIterator#isFresh()   */  public boolean isFresh()  {    return (0 == m_next);  }  /**   * @see DTMIterator#setShouldCacheNodes(boolean)   */  public void setShouldCacheNodes(boolean b)  {    if (b)    {      if(!hasCache())      {        SetVector(new NodeVector());      }//	  else//	    getVector().RemoveAllNoClear();  // Is this good?    }    else      SetVector(null);  }  /**   * @see DTMIterator#isMutable()   */  public boolean isMutable()  {    return hasCache(); // though may be surprising if it also has an iterator!  }  /**   * @see DTMIterator#getCurrentPos()   */  public int getCurrentPos()  {    return m_next;  }  /**   * @see DTMIterator#runTo(int)   */  public void runTo(int index)  {    int n;        if (-1 == index)    {      int pos = m_next;      while (DTM.NULL != (n = nextNode()));      m_next = pos;    }    else if(m_next == index)    {      return;    }    else if(hasCache() && m_next < getVector().size())    {      m_next = index;    }    else if((null == getVector()) && (index < m_next))    {      while ((m_next >= index) && DTM.NULL != (n = previousNode()));    }    else    {         while ((m_next < index) && DTM.NULL != (n = nextNode()));    }      }  /**   * @see DTMIterator#setCurrentPos(int)   */  public void setCurrentPos(int i)  {  	runTo(i);  }  /**   * @see DTMIterator#item(int)   */  public int item(int index)  {  	setCurrentPos(index);  	int n = nextNode();  	m_next = index;  	return n;  }  /**   * @see DTMIterator#setItem(int, int)   */  public void setItem(int node, int index)  {  	NodeVector vec = getVector();  	if(null != vec)  	{  		vec.setElementAt(node, index);  		m_last = vec.size();  	}  	else  		m_iter.setItem(node, index);  }  /**   * @see DTMIterator#getLength()   */  public int getLength()  {  	if(hasCache())  	{        // If this NodeSequence wraps a mutable nodeset, then        // m_last will not reflect the size of the nodeset if        // it has been mutated...        if (m_iter instanceof NodeSetDTM)        {            return m_iter.getLength();        }            	  	if(-1 == m_last)	  	{	  		int pos = m_next;	  		runTo(-1);	  		m_next = pos;	  	}	    return m_last;  	}  	else  	{  		return (-1 == m_last) ? (m_last = m_iter.getLength()) : m_last;  	}  }  /**   * Note: Not a deep clone.   * @see DTMIterator#cloneWithReset()   */  public DTMIterator cloneWithReset() throws CloneNotSupportedException  {  	NodeSequence seq = (NodeSequence)super.clone();    seq.m_next = 0;    return seq;  }    /**   * Get a clone of this iterator, but don't reset the iteration in the    * process, so that it may be used from the current position.   * Note: Not a deep clone.   *   * @return A clone of this object.   *   * @throws CloneNotSupportedException   */  public Object clone() throws CloneNotSupportedException  {  	return super.clone();  }  /**   * @see DTMIterator#isDocOrdered()   */  public boolean isDocOrdered()  {  	if(null != m_iter)  		return m_iter.isDocOrdered();  	else    	return true; // can't be sure?  }  /**   * @see DTMIterator#getAxis()   */  public int getAxis()  {  	if(null != m_iter)    	return m_iter.getAxis();    else    {    	assertion(false, "Can not getAxis from a non-iterated node sequence!");    	return 0;    }  }  /**   * @see PathComponent#getAnalysisBits()   */  public int getAnalysisBits()  {  	if((null != m_iter) && (m_iter instanceof PathComponent))    	return ((PathComponent)m_iter).getAnalysisBits();    else    	return 0;  }  /**   * @see Expression#fixupVariables(Vector, int)   */  public void fixupVariables(Vector vars, int globalsSize)  {  	super.fixupVariables(vars, globalsSize);  }      /**   * Add the node into a vector of nodes where it should occur in   * document order.   * @param v Vector of nodes, presumably containing Nodes   * @param obj Node object.   *   * @param node The node to be added.   * @param test true if we should test for doc order   * @param support The XPath runtime context.   * @return insertIndex.   * @throws RuntimeException thrown if this NodeSetDTM is not of    * a mutable type.   */   protected int addNodeInDocOrder(int node)   {      assertion(hasCache(), "addNodeInDocOrder must be done on a mutable sequence!");      int insertIndex = -1;            NodeVector vec = getVector();      // This needs to do a binary search, but a binary search       // is somewhat tough because the sequence test involves       // two nodes.      int size = vec.size(), i;      for (i = size - 1; i >= 0; i--)      {        int child = vec.elementAt(i);        if (child == node)        {          i = -2; // Duplicate, suppress insert          break;        }        DTM dtm = m_dtmMgr.getDTM(node);        if (!dtm.isNodeAfter(node, child))        {          break;        }      }      if (i != -2)      {        insertIndex = i + 1;        vec.insertElementAt(node, insertIndex);      }      // checkDups();      return insertIndex;    } // end addNodeInDocOrder(Vector v, Object obj)}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?