Java Code Examples for com.sun.org.apache.xml.internal.dtm.DTM#isNodeAfter()

The following examples show how to use com.sun.org.apache.xml.internal.dtm.DTM#isNodeAfter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnionPathIterator.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 *  Returns the next node in the set and advances the position of the
 * iterator in the set. After a DTMIterator 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.
 */
public int nextNode()
{
      if(m_foundLast)
              return DTM.NULL;

  // Loop through the iterators getting the current fetched
  // node, and get the earliest occuring in document order
  int earliestNode = DTM.NULL;

  if (null != m_iterators)
  {
    int n = m_iterators.length;
    int iteratorUsed = -1;

    for (int i = 0; i < n; i++)
    {
      int node = m_iterators[i].getCurrentNode();

      if (DTM.NULL == node)
        continue;
      else if (DTM.NULL == earliestNode)
      {
        iteratorUsed = i;
        earliestNode = node;
      }
      else
      {
        if (node == earliestNode)
        {

          // Found a duplicate, so skip past it.
          m_iterators[i].nextNode();
        }
        else
        {
          DTM dtm = getDTM(node);

          if (dtm.isNodeAfter(node, earliestNode))
          {
            iteratorUsed = i;
            earliestNode = node;
          }
        }
      }
    }

    if (DTM.NULL != earliestNode)
    {
      m_iterators[iteratorUsed].nextNode();

      incrementCurrentPos();
    }
    else
      m_foundLast = true;
  }

  m_lastFetched = earliestNode;

  return earliestNode;
}
 
Example 2
Source File: UnionPathIterator.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 *  Returns the next node in the set and advances the position of the
 * iterator in the set. After a DTMIterator 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.
 */
public int nextNode()
{
      if(m_foundLast)
              return DTM.NULL;

  // Loop through the iterators getting the current fetched
  // node, and get the earliest occuring in document order
  int earliestNode = DTM.NULL;

  if (null != m_iterators)
  {
    int n = m_iterators.length;
    int iteratorUsed = -1;

    for (int i = 0; i < n; i++)
    {
      int node = m_iterators[i].getCurrentNode();

      if (DTM.NULL == node)
        continue;
      else if (DTM.NULL == earliestNode)
      {
        iteratorUsed = i;
        earliestNode = node;
      }
      else
      {
        if (node == earliestNode)
        {

          // Found a duplicate, so skip past it.
          m_iterators[i].nextNode();
        }
        else
        {
          DTM dtm = getDTM(node);

          if (dtm.isNodeAfter(node, earliestNode))
          {
            iteratorUsed = i;
            earliestNode = node;
          }
        }
      }
    }

    if (DTM.NULL != earliestNode)
    {
      m_iterators[iteratorUsed].nextNode();

      incrementCurrentPos();
    }
    else
      m_foundLast = true;
  }

  m_lastFetched = earliestNode;

  return earliestNode;
}
 
Example 3
Source File: NodeSequence.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
* Add the node into a vector of nodes where it should occur in
* document order.
* @param node The node to be added.
* @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;
 }
 
Example 4
Source File: NodeSetDTM.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 NodeSetDTM is not of
 * a mutable type.
 */
public int addNodeInDocOrder(int node, boolean test, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM 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--)
    {
      int child = elementAt(i);

      if (child == node)
      {
        i = -2;  // Duplicate, suppress insert

        break;
      }

      DTM dtm = support.getDTM(node);
      if (!dtm.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 (i == node)
      {
        foundit = true;

        break;
      }
    }

    if (!foundit)
      addElement(node);
  }

  // checkDups();
  return insertIndex;
}
 
Example 5
Source File: UnionPathIterator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Returns the next node in the set and advances the position of the
 * iterator in the set. After a DTMIterator 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.
 */
public int nextNode()
{
      if(m_foundLast)
              return DTM.NULL;

  // Loop through the iterators getting the current fetched
  // node, and get the earliest occuring in document order
  int earliestNode = DTM.NULL;

  if (null != m_iterators)
  {
    int n = m_iterators.length;
    int iteratorUsed = -1;

    for (int i = 0; i < n; i++)
    {
      int node = m_iterators[i].getCurrentNode();

      if (DTM.NULL == node)
        continue;
      else if (DTM.NULL == earliestNode)
      {
        iteratorUsed = i;
        earliestNode = node;
      }
      else
      {
        if (node == earliestNode)
        {

          // Found a duplicate, so skip past it.
          m_iterators[i].nextNode();
        }
        else
        {
          DTM dtm = getDTM(node);

          if (dtm.isNodeAfter(node, earliestNode))
          {
            iteratorUsed = i;
            earliestNode = node;
          }
        }
      }
    }

    if (DTM.NULL != earliestNode)
    {
      m_iterators[iteratorUsed].nextNode();

      incrementCurrentPos();
    }
    else
      m_foundLast = true;
  }

  m_lastFetched = earliestNode;

  return earliestNode;
}
 
Example 6
Source File: UnionPathIterator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Returns the next node in the set and advances the position of the
 * iterator in the set. After a DTMIterator 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.
 */
public int nextNode()
{
      if(m_foundLast)
              return DTM.NULL;

  // Loop through the iterators getting the current fetched
  // node, and get the earliest occuring in document order
  int earliestNode = DTM.NULL;

  if (null != m_iterators)
  {
    int n = m_iterators.length;
    int iteratorUsed = -1;

    for (int i = 0; i < n; i++)
    {
      int node = m_iterators[i].getCurrentNode();

      if (DTM.NULL == node)
        continue;
      else if (DTM.NULL == earliestNode)
      {
        iteratorUsed = i;
        earliestNode = node;
      }
      else
      {
        if (node == earliestNode)
        {

          // Found a duplicate, so skip past it.
          m_iterators[i].nextNode();
        }
        else
        {
          DTM dtm = getDTM(node);

          if (dtm.isNodeAfter(node, earliestNode))
          {
            iteratorUsed = i;
            earliestNode = node;
          }
        }
      }
    }

    if (DTM.NULL != earliestNode)
    {
      m_iterators[iteratorUsed].nextNode();

      incrementCurrentPos();
    }
    else
      m_foundLast = true;
  }

  m_lastFetched = earliestNode;

  return earliestNode;
}
 
Example 7
Source File: NodeSetDTM.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 NodeSetDTM is not of
 * a mutable type.
 */
public int addNodeInDocOrder(int node, boolean test, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM 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--)
    {
      int child = elementAt(i);

      if (child == node)
      {
        i = -2;  // Duplicate, suppress insert

        break;
      }

      DTM dtm = support.getDTM(node);
      if (!dtm.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 (i == node)
      {
        foundit = true;

        break;
      }
    }

    if (!foundit)
      addElement(node);
  }

  // checkDups();
  return insertIndex;
}
 
Example 8
Source File: UnionPathIterator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Returns the next node in the set and advances the position of the
 * iterator in the set. After a DTMIterator 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.
 */
public int nextNode()
{
      if(m_foundLast)
              return DTM.NULL;

  // Loop through the iterators getting the current fetched
  // node, and get the earliest occuring in document order
  int earliestNode = DTM.NULL;

  if (null != m_iterators)
  {
    int n = m_iterators.length;
    int iteratorUsed = -1;

    for (int i = 0; i < n; i++)
    {
      int node = m_iterators[i].getCurrentNode();

      if (DTM.NULL == node)
        continue;
      else if (DTM.NULL == earliestNode)
      {
        iteratorUsed = i;
        earliestNode = node;
      }
      else
      {
        if (node == earliestNode)
        {

          // Found a duplicate, so skip past it.
          m_iterators[i].nextNode();
        }
        else
        {
          DTM dtm = getDTM(node);

          if (dtm.isNodeAfter(node, earliestNode))
          {
            iteratorUsed = i;
            earliestNode = node;
          }
        }
      }
    }

    if (DTM.NULL != earliestNode)
    {
      m_iterators[iteratorUsed].nextNode();

      incrementCurrentPos();
    }
    else
      m_foundLast = true;
  }

  m_lastFetched = earliestNode;

  return earliestNode;
}
 
Example 9
Source File: NodeSequence.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
* Add the node into a vector of nodes where it should occur in
* document order.
* @param node The node to be added.
* @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;
 }
 
Example 10
Source File: NodeSetDTM.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 NodeSetDTM is not of
 * a mutable type.
 */
public int addNodeInDocOrder(int node, boolean test, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM 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--)
    {
      int child = elementAt(i);

      if (child == node)
      {
        i = -2;  // Duplicate, suppress insert

        break;
      }

      DTM dtm = support.getDTM(node);
      if (!dtm.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 (i == node)
      {
        foundit = true;

        break;
      }
    }

    if (!foundit)
      addElement(node);
  }

  // checkDups();
  return insertIndex;
}
 
Example 11
Source File: UnionPathIterator.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Returns the next node in the set and advances the position of the
 * iterator in the set. After a DTMIterator 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.
 */
public int nextNode()
{
      if(m_foundLast)
              return DTM.NULL;

  // Loop through the iterators getting the current fetched
  // node, and get the earliest occuring in document order
  int earliestNode = DTM.NULL;

  if (null != m_iterators)
  {
    int n = m_iterators.length;
    int iteratorUsed = -1;

    for (int i = 0; i < n; i++)
    {
      int node = m_iterators[i].getCurrentNode();

      if (DTM.NULL == node)
        continue;
      else if (DTM.NULL == earliestNode)
      {
        iteratorUsed = i;
        earliestNode = node;
      }
      else
      {
        if (node == earliestNode)
        {

          // Found a duplicate, so skip past it.
          m_iterators[i].nextNode();
        }
        else
        {
          DTM dtm = getDTM(node);

          if (dtm.isNodeAfter(node, earliestNode))
          {
            iteratorUsed = i;
            earliestNode = node;
          }
        }
      }
    }

    if (DTM.NULL != earliestNode)
    {
      m_iterators[iteratorUsed].nextNode();

      incrementCurrentPos();
    }
    else
      m_foundLast = true;
  }

  m_lastFetched = earliestNode;

  return earliestNode;
}
 
Example 12
Source File: NodeSequence.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
* Add the node into a vector of nodes where it should occur in
* document order.
* @param node The node to be added.
* @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;
 }
 
Example 13
Source File: NodeSetDTM.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 NodeSetDTM is not of
 * a mutable type.
 */
public int addNodeInDocOrder(int node, boolean test, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM 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--)
    {
      int child = elementAt(i);

      if (child == node)
      {
        i = -2;  // Duplicate, suppress insert

        break;
      }

      DTM dtm = support.getDTM(node);
      if (!dtm.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 (i == node)
      {
        foundit = true;

        break;
      }
    }

    if (!foundit)
      addElement(node);
  }

  // checkDups();
  return insertIndex;
}
 
Example 14
Source File: UnionPathIterator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Returns the next node in the set and advances the position of the
 * iterator in the set. After a DTMIterator 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.
 */
public int nextNode()
{
      if(m_foundLast)
              return DTM.NULL;

  // Loop through the iterators getting the current fetched
  // node, and get the earliest occuring in document order
  int earliestNode = DTM.NULL;

  if (null != m_iterators)
  {
    int n = m_iterators.length;
    int iteratorUsed = -1;

    for (int i = 0; i < n; i++)
    {
      int node = m_iterators[i].getCurrentNode();

      if (DTM.NULL == node)
        continue;
      else if (DTM.NULL == earliestNode)
      {
        iteratorUsed = i;
        earliestNode = node;
      }
      else
      {
        if (node == earliestNode)
        {

          // Found a duplicate, so skip past it.
          m_iterators[i].nextNode();
        }
        else
        {
          DTM dtm = getDTM(node);

          if (dtm.isNodeAfter(node, earliestNode))
          {
            iteratorUsed = i;
            earliestNode = node;
          }
        }
      }
    }

    if (DTM.NULL != earliestNode)
    {
      m_iterators[iteratorUsed].nextNode();

      incrementCurrentPos();
    }
    else
      m_foundLast = true;
  }

  m_lastFetched = earliestNode;

  return earliestNode;
}
 
Example 15
Source File: NodeSequence.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
* Add the node into a vector of nodes where it should occur in
* document order.
* @param node The node to be added.
* @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;
 }
 
Example 16
Source File: NodeSequence.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
* Add the node into a vector of nodes where it should occur in
* document order.
* @param node The node to be added.
* @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;
 }
 
Example 17
Source File: NodeSetDTM.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 NodeSetDTM is not of
 * a mutable type.
 */
public int addNodeInDocOrder(int node, boolean test, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM 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--)
    {
      int child = elementAt(i);

      if (child == node)
      {
        i = -2;  // Duplicate, suppress insert

        break;
      }

      DTM dtm = support.getDTM(node);
      if (!dtm.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 (i == node)
      {
        foundit = true;

        break;
      }
    }

    if (!foundit)
      addElement(node);
  }

  // checkDups();
  return insertIndex;
}
 
Example 18
Source File: UnionPathIterator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Returns the next node in the set and advances the position of the
 * iterator in the set. After a DTMIterator 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.
 */
public int nextNode()
{
      if(m_foundLast)
              return DTM.NULL;

  // Loop through the iterators getting the current fetched
  // node, and get the earliest occuring in document order
  int earliestNode = DTM.NULL;

  if (null != m_iterators)
  {
    int n = m_iterators.length;
    int iteratorUsed = -1;

    for (int i = 0; i < n; i++)
    {
      int node = m_iterators[i].getCurrentNode();

      if (DTM.NULL == node)
        continue;
      else if (DTM.NULL == earliestNode)
      {
        iteratorUsed = i;
        earliestNode = node;
      }
      else
      {
        if (node == earliestNode)
        {

          // Found a duplicate, so skip past it.
          m_iterators[i].nextNode();
        }
        else
        {
          DTM dtm = getDTM(node);

          if (dtm.isNodeAfter(node, earliestNode))
          {
            iteratorUsed = i;
            earliestNode = node;
          }
        }
      }
    }

    if (DTM.NULL != earliestNode)
    {
      m_iterators[iteratorUsed].nextNode();

      incrementCurrentPos();
    }
    else
      m_foundLast = true;
  }

  m_lastFetched = earliestNode;

  return earliestNode;
}
 
Example 19
Source File: NodeSetDTM.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * 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 NodeSetDTM is not of
 * a mutable type.
 */
public int addNodeInDocOrder(int node, boolean test, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM 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--)
    {
      int child = elementAt(i);

      if (child == node)
      {
        i = -2;  // Duplicate, suppress insert

        break;
      }

      DTM dtm = support.getDTM(node);
      if (!dtm.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 (i == node)
      {
        foundit = true;

        break;
      }
    }

    if (!foundit)
      addElement(node);
  }

  // checkDups();
  return insertIndex;
}
 
Example 20
Source File: UnionPathIterator.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 *  Returns the next node in the set and advances the position of the
 * iterator in the set. After a DTMIterator 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.
 */
public int nextNode()
{
      if(m_foundLast)
              return DTM.NULL;

  // Loop through the iterators getting the current fetched
  // node, and get the earliest occuring in document order
  int earliestNode = DTM.NULL;

  if (null != m_iterators)
  {
    int n = m_iterators.length;
    int iteratorUsed = -1;

    for (int i = 0; i < n; i++)
    {
      int node = m_iterators[i].getCurrentNode();

      if (DTM.NULL == node)
        continue;
      else if (DTM.NULL == earliestNode)
      {
        iteratorUsed = i;
        earliestNode = node;
      }
      else
      {
        if (node == earliestNode)
        {

          // Found a duplicate, so skip past it.
          m_iterators[i].nextNode();
        }
        else
        {
          DTM dtm = getDTM(node);

          if (dtm.isNodeAfter(node, earliestNode))
          {
            iteratorUsed = i;
            earliestNode = node;
          }
        }
      }
    }

    if (DTM.NULL != earliestNode)
    {
      m_iterators[iteratorUsed].nextNode();

      incrementCurrentPos();
    }
    else
      m_foundLast = true;
  }

  m_lastFetched = earliestNode;

  return earliestNode;
}