⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nodeset.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   *    * <p> In case you're wondering why this function is needed: NodeSet   * implements both NodeIterator and NodeList. If this method isn't   * provided, Java can't decide which of those to use when addNodes()   * is invoked. Providing the more-explicit match avoids that   * ambiguity.)</p>   *   * @param ns NodeSet whose members should be merged into this NodeSet.   * @throws RuntimeException thrown if this NodeSet is not of    * a mutable type.   */  public void addNodes(NodeSet ns)  {    if (!m_mutable)      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");    addNodes((NodeIterator) ns);  }  /**   * Copy NodeList members into this nodelist, adding in   * document order.  Null references are not added.   *   * @param iterator NodeIterator which yields the nodes to be added.   * @throws RuntimeException thrown if this NodeSet is not of    * a mutable type.   */  public void addNodes(NodeIterator iterator)  {    if (!m_mutable)      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");    if (null != iterator)  // defensive to fix a bug that Sanjiva reported.    {      Node obj;      while (null != (obj = iterator.nextNode()))      {        addElement(obj);      }    }    // checkDups();  }  /**   * Copy NodeList members into this nodelist, adding in   * document order.  If a node is null, don't add it.   *   * @param nodelist List of nodes to be added   * @param support The XPath runtime context.   * @throws RuntimeException thrown if this NodeSet is not of    * a mutable type.   */  public void addNodesInDocOrder(NodeList nodelist, XPathContext support)  {    if (!m_mutable)      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");    int nChildren = nodelist.getLength();    for (int i = 0; i < nChildren; i++)    {      Node node = nodelist.item(i);      if (null != node)      {        addNodeInDocOrder(node, support);      }    }  }  /**   * Copy NodeList members into this nodelist, adding in   * document order.  If a node is null, don't add it.   *   * @param iterator NodeIterator which yields the nodes to be added.   * @param support The XPath runtime context.   * @throws RuntimeException thrown if this NodeSet is not of    * a mutable type.   */  public void addNodesInDocOrder(NodeIterator iterator, XPathContext support)  {    if (!m_mutable)      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");    Node node;    while (null != (node = iterator.nextNode()))    {      addNodeInDocOrder(node, support);    }  }  /**   * Add the node list to this node set in document order.   *   * @param start index.   * @param end index.   * @param testIndex index.   * @param nodelist The nodelist to add.   * @param support The XPath runtime context.   *   * @return false always.   * @throws RuntimeException thrown if this NodeSet is not of    * a mutable type.   */  private boolean addNodesInDocOrder(int start, int end, int testIndex,                                     NodeList nodelist, XPathContext support)  {    if (!m_mutable)      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");    boolean foundit = false;    int i;    Node node = nodelist.item(testIndex);    for (i = end; i >= start; i--)    {      Node child = (Node) elementAt(i);      if (child == node)      {        i = -2;  // Duplicate, suppress insert        break;      }      if (!DOM2Helper.isNodeAfter(node, child))      {        insertElementAt(node, i + 1);        testIndex--;        if (testIndex > 0)        {          boolean foundPrev = addNodesInDocOrder(0, i, testIndex, nodelist,                                                 support);          if (!foundPrev)          {            addNodesInDocOrder(i, size() - 1, testIndex, nodelist, support);          }        }        break;      }    }    if (i == -1)    {      insertElementAt(node, 0);    }    return foundit;  }  /**   * Add the node into a vector of nodes where it should occur in   * document order.   * @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 NodeSet is not of    * a mutable type.   */  public int addNodeInDocOrder(Node node, boolean test, XPathContext support)  {    if (!m_mutable)      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");    int insertIndex = -1;    if (test)    {      // This needs to do a binary search, but a binary search       // is somewhat tough because the sequence test involves       // two nodes.      int size = size(), i;      for (i = size - 1; i >= 0; i--)      {        Node child = (Node) elementAt(i);        if (child == node)        {          i = -2;  // Duplicate, suppress insert          break;        }        if (!DOM2Helper.isNodeAfter(node, child))        {          break;        }      }      if (i != -2)      {        insertIndex = i + 1;        insertElementAt(node, insertIndex);      }    }    else    {      insertIndex = this.size();      boolean foundit = false;      for (int i = 0; i < insertIndex; i++)      {        if (this.item(i).equals(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 NodeSet is not of    * a mutable type.   */  public int addNodeInDocOrder(Node node, XPathContext support)  {    if (!m_mutable)      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");    return addNodeInDocOrder(node, true, support);  }  // end addNodeInDocOrder(Vector v, Object obj)  /** 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 NodeSet 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_NODESET_CANNOT_INDEX, null)); //"This NodeSet 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 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;  }  /** 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;  /**   * 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;  }      transient private int m_last = 0;    public int getLast()  {    return m_last;  }    public void setLast(int last)  {    m_last = last;  }    /** Size of blocks to allocate.   *  @serial          */  private int m_blocksize;  /** Array of nodes this points to.   *  @serial          */  Node m_map[];  /** Number of nodes in this NodeVector.   *  @serial          */  protected int m_firstFree = 0;  /** Size of the array this points to.   *  @serial           */  private int m_mapSize;  // lazy initialization  /**   * Get a cloned LocPathIterator.   *   * @return A clone of this   *   * @throws CloneNotSupportedException   */  public Object clone() throws CloneNotSupportedException  {    NodeSet clone = (NodeSet) super.clone();    if ((null != this.m_map) && (this.m_map == clone.m_map))    {      clone.m_map = new Node[this.m_map.length];      System.arraycopy(this.m_map, 0, clone.m_map, 0, this.m_map.length);    }    return clone;  }  /**   * Get the length of the list.   *   * @return Number of nodes in this NodeVector   */  public int size()  {    return m_firstFree;  }  /**   * Append a Node onto the vector.   *   * @param value Node to add to the vector   */  public void addElement(Node value)  {    if (!m_mutable)      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");    if ((m_firstFree + 1) >= m_mapSize)    {      if (null == m_map)      {        m_map = new Node[m_blocksize];        m_mapSize = m_blocksize;      }      else      {        m_mapSize += m_blocksize;        Node newMap[] = new Node[m_mapSize];        System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);        m_map = newMap;      }    }    m_map[m_firstFree] = value;    m_firstFree++;  }  /**   * Append a Node onto the vector.   *   * @param value Node to add to the vector   */  public final void push(Node value)  {    int ff = m_firstFree;    if ((ff + 1) >= m_mapSize)    {      if (null == m_map)

⌨️ 快捷键说明

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