jaxp/src/com/sun/org/apache/xpath/internal/NodeSet.java
author joehw
Thu, 12 Apr 2012 08:38:26 -0700
changeset 12457 c348e06f0e82
parent 6 jaxp/src/share/classes/com/sun/org/apache/xpath/internal/NodeSet.java@7f561c08de6b
permissions -rw-r--r--
7160496: Rename JDK8 JAXP source directory Summary: moving src/share/classes to src Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: NodeSet.java,v 1.2.4.1 2005/09/10 17:39:49 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xpath.internal;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.xalan.internal.res.XSLMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xml.internal.utils.DOM2Helper;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xpath.internal.axes.ContextNodeList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import org.w3c.dom.DOMException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import org.w3c.dom.NodeList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import org.w3c.dom.traversal.NodeFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import org.w3c.dom.traversal.NodeIterator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * <p>The NodeSet class can act as either a NodeVector,
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * NodeList, or NodeIterator.  However, in order for it to
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * act as a NodeVector or NodeList, it's required that
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * setShouldCacheNodes(true) be called before the first
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * nextNode() is called, in order that nodes can be added
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * as they are fetched.  Derived classes that implement iterators
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * must override runTo(int index), in order that they may
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * run the iteration to the given index. </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * <p>Note that we directly implement the DOM's NodeIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * interface. We do not emulate all the behavior of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * standard NodeIterator. In particular, we do not guarantee
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * to present a "live view" of the document ... but in XSLT,
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * the source document should never be mutated, so this should
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * never be an issue.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * <p>Thought: Should NodeSet really implement NodeList and NodeIterator,
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * or should there be specific subclasses of it which do so? The
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * advantage of doing it all here is that all NodeSets will respond
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * to the same calls; the disadvantage is that some of them may return
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * less-than-enlightening results when you do so.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * @xsl.usage advanced
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
public class NodeSet
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
        implements NodeList, NodeIterator, Cloneable, ContextNodeList
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   * Create an empty nodelist.
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
  public NodeSet()
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    m_blocksize = 32;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    m_mapSize = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
   * Create an empty, using the given block size.
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
   * @param blocksize Size of blocks to allocate
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
  public NodeSet(int blocksize)
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    m_blocksize = blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    m_mapSize = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
   * Create a NodeSet, and copy the members of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
   * given nodelist into it.
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
   * @param nodelist List of Nodes to be made members of the new set.
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
  public NodeSet(NodeList nodelist)
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    this(32);
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    addNodes(nodelist);
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   * Create a NodeSet, and copy the members of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   * given NodeSet into it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
   * @param nodelist Set of Nodes to be made members of the new set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
  public NodeSet(NodeSet nodelist)
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    this(32);
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    addNodes((NodeIterator) nodelist);
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   * Create a NodeSet, and copy the members of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   * given NodeIterator into it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
   * @param ni Iterator which yields Nodes to be made members of the new set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
  public NodeSet(NodeIterator ni)
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    this(32);
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    addNodes(ni);
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   * Create a NodeSet which contains the given Node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
   * @param node Single node to be added to the new set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
  public NodeSet(Node node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    this(32);
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    addNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
   * @return The root node of the Iterator, as specified when it was created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
   * For non-Iterator NodeSets, this will be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
  public Node getRoot()
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   * Get a cloned Iterator, and reset its state to the beginning of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
   * iteration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
   * @return a new NodeSet of the same type, having the same state...
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
   * except that the reset() operation has been called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
   * @throws CloneNotSupportedException if this subclass of NodeSet
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
   * does not support the clone() operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
  public NodeIterator cloneWithReset() throws CloneNotSupportedException
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
    NodeSet clone = (NodeSet) clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
    clone.reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    return clone;
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
   * Reset the iterator. May have no effect on non-iterator Nodesets.
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
  public void reset()
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
    m_next = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
   *  This attribute determines which node types are presented via the
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
   * iterator. The available set of constants is defined in the
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
   * <code>NodeFilter</code> interface. For NodeSets, the mask has been
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
   * hardcoded to show all nodes except EntityReference nodes, which have
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
   * no equivalent in the XPath data model.
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
   * @return integer used as a bit-array, containing flags defined in
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
   * the DOM's NodeFilter class. The value will be
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
   * <code>SHOW_ALL & ~SHOW_ENTITY_REFERENCE</code>, meaning that
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
   * only entity references are suppressed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
  public int getWhatToShow()
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    return NodeFilter.SHOW_ALL & ~NodeFilter.SHOW_ENTITY_REFERENCE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
   * The filter object used to screen nodes. Filters are applied to
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
   * further reduce (and restructure) the NodeIterator's view of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
   * document. In our case, we will be using hardcoded filters built
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
   * into our iterators... but getFilter() is part of the DOM's
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
   * NodeIterator interface, so we have to support it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
   * @return null, which is slightly misleading. True, there is no
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
   * user-written filter object, but in fact we are doing some very
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
   * sophisticated custom filtering. A DOM purist might suggest
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
   * returning a placeholder object just to indicate that this is
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
   * not going to return all nodes selected by whatToShow.
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
  public NodeFilter getFilter()
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
   *  The value of this flag determines whether the children of entity
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
   * reference nodes are visible to the iterator. If false, they will be
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
   * skipped over.
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
   * <br> To produce a view of the document that has entity references
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
   * expanded and does not expose the entity reference node itself, use the
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
   * whatToShow flags to hide the entity reference node and set
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
   * expandEntityReferences to true when creating the iterator. To produce
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
   * a view of the document that has entity reference nodes but no entity
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
   * expansion, use the whatToShow flags to show the entity reference node
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
   * and set expandEntityReferences to false.
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
   * @return true for all iterators based on NodeSet, meaning that the
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
   * contents of EntityRefrence nodes may be returned (though whatToShow
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
   * says that the EntityReferences themselves are not shown.)
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
  public boolean getExpandEntityReferences()
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
   *  Returns the next node in the set and advances the position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
   * iterator in the set. After a NodeIterator is created, the first call
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
   * to nextNode() returns the first node in the set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
   * @return  The next <code>Node</code> in the set being iterated over, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
   *   <code>null</code> if there are no more members in that set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
   * @throws DOMException
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
   *    INVALID_STATE_ERR: Raised if this method is called after the
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
   *   <code>detach</code> method was invoked.
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
  public Node nextNode() throws DOMException
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    if ((m_next) < this.size())
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
      Node next = this.elementAt(m_next);
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
      m_next++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
      return next;
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
   *  Returns the previous node in the set and moves the position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
   * iterator backwards in the set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
   * @return  The previous <code>Node</code> in the set being iterated over,
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
   *   or<code>null</code> if there are no more members in that set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
   * @throws DOMException
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
   *    INVALID_STATE_ERR: Raised if this method is called after the
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
   *   <code>detach</code> method was invoked.
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
   * a cached type, and hence doesn't know what the previous node was.
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
  public Node previousNode() throws DOMException
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
    if (!m_cacheNodes)
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
      throw new RuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_ITERATE, null)); //"This NodeSet can not iterate to a previous node!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    if ((m_next - 1) > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
      m_next--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
      return this.elementAt(m_next);
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
   * Detaches the iterator from the set which it iterated over, releasing
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
   * any computational resources and placing the iterator in the INVALID
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
   * state. After<code>detach</code> has been invoked, calls to
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
   * <code>nextNode</code> or<code>previousNode</code> will raise the
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
   * exception INVALID_STATE_ERR.
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
   * This operation is a no-op in NodeSet, and will not cause
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
   * INVALID_STATE_ERR to be raised by later operations.
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
   * </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
  public void detach(){}
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
   * Tells if this NodeSet is "fresh", in other words, if
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
   * the first nextNode() that is called will return the
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
   * first node in the set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
   * @return true if nextNode() would return the first node in the set,
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
   * false if it would return a later one.
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
  public boolean isFresh()
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
    return (m_next == 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
   * If an index is requested, NodeSet will call this method
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
   * to run the iterator to the index.  By default this sets
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
   * m_next to the index.  If the index argument is -1, this
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
   * signals that the iterator should be run to the end.
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
   * @param index Position to advance (or retreat) to, with
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
   * 0 requesting the reset ("fresh") position and -1 (or indeed
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
   * any out-of-bounds value) requesting the final position.
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
   * @throws RuntimeException thrown if this NodeSet is not
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
   * one of the types which supports indexing/counting.
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
  public void runTo(int index)
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
    if (!m_cacheNodes)
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
      throw new RuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
    if ((index >= 0) && (m_next < m_firstFree))
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
      m_next = index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
      m_next = m_firstFree - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
   * Returns the <code>index</code>th item in the collection. If
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
   * <code>index</code> is greater than or equal to the number of nodes in
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
   * the list, this returns <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
   * TODO: What happens if index is out of range?
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
   * @param index Index into the collection.
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
   * @return The node at the <code>index</code>th position in the
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
   *   <code>NodeList</code>, or <code>null</code> if that is not a valid
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
   *   index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
  public Node item(int index)
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
    runTo(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
    return (Node) this.elementAt(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
   * The number of nodes in the list. The range of valid child node indices is
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
   * 0 to <code>length-1</code> inclusive. Note that this operation requires
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
   * finding all the matching nodes, which may defeat attempts to defer
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
   * that work.
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
   * @return integer indicating how many nodes are represented by this list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
  public int getLength()
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
    runTo(-1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
    return this.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
   * Add a node to the NodeSet. Not all types of NodeSets support this
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
   * operation
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
   * @param n Node to be added
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
  public void addNode(Node n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
    this.addElement(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
   * Insert a node at a given position.
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
   * @param n Node to be added
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
   * @param pos Offset at which the node is to be inserted,
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
   * with 0 being the first position.
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
  public void insertNode(Node n, int pos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
    insertElementAt(n, pos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
   * Remove a node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
   * @param n Node to be added
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
  public void removeNode(Node n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
    this.removeElement(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
   * Copy NodeList members into this nodelist, adding in
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
   * document order.  If a node is null, don't add it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
   * @param nodelist List of nodes which should now be referenced by
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
   * this NodeSet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
  public void addNodes(NodeList nodelist)
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
    if (null != nodelist)  // defensive to fix a bug that Sanjiva reported.
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
      int nChildren = nodelist.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
      for (int i = 0; i < nChildren; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
        Node obj = nodelist.item(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
        if (null != obj)
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
          addElement(obj);
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
    // checkDups();
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
   * <p>Copy NodeList members into this nodelist, adding in
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
   * document order.  Only genuine node references will be copied;
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
   * nulls appearing in the source NodeSet will
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
   * not be added to this one. </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
   * <p> In case you're wondering why this function is needed: NodeSet
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
   * implements both NodeIterator and NodeList. If this method isn't
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
   * provided, Java can't decide which of those to use when addNodes()
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
   * is invoked. Providing the more-explicit match avoids that
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
   * ambiguity.)</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
   * @param ns NodeSet whose members should be merged into this NodeSet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
  public void addNodes(NodeSet ns)
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
    addNodes((NodeIterator) ns);
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
   * Copy NodeList members into this nodelist, adding in
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
   * document order.  Null references are not added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
   * @param iterator NodeIterator which yields the nodes to be added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
  public void addNodes(NodeIterator iterator)
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
    if (null != iterator)  // defensive to fix a bug that Sanjiva reported.
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
      Node obj;
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
      while (null != (obj = iterator.nextNode()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
        addElement(obj);
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
    // checkDups();
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
   * Copy NodeList members into this nodelist, adding in
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
   * document order.  If a node is null, don't add it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
   * @param nodelist List of nodes to be added
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
   * @param support The XPath runtime context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
  public void addNodesInDocOrder(NodeList nodelist, XPathContext support)
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
    int nChildren = nodelist.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
    for (int i = 0; i < nChildren; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
      Node node = nodelist.item(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
      if (null != node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
        addNodeInDocOrder(node, support);
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
   * Copy NodeList members into this nodelist, adding in
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
   * document order.  If a node is null, don't add it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
   * @param iterator NodeIterator which yields the nodes to be added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
   * @param support The XPath runtime context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
  public void addNodesInDocOrder(NodeIterator iterator, XPathContext support)
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
    Node node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
    while (null != (node = iterator.nextNode()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
      addNodeInDocOrder(node, support);
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
   * Add the node list to this node set in document order.
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
   * @param start index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
   * @param end index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
   * @param testIndex index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
   * @param nodelist The nodelist to add.
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
   * @param support The XPath runtime context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
   * @return false always.
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
  private boolean addNodesInDocOrder(int start, int end, int testIndex,
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
                                     NodeList nodelist, XPathContext support)
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
    boolean foundit = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
    int i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
    Node node = nodelist.item(testIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
    for (i = end; i >= start; i--)
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
      Node child = (Node) elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
      if (child == node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
        i = -2;  // Duplicate, suppress insert
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
      if (!DOM2Helper.isNodeAfter(node, child))
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
        insertElementAt(node, i + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
        testIndex--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
        if (testIndex > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
          boolean foundPrev = addNodesInDocOrder(0, i, testIndex, nodelist,
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
                                                 support);
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
          if (!foundPrev)
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
            addNodesInDocOrder(i, size() - 1, testIndex, nodelist, support);
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
    if (i == -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
      insertElementAt(node, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
    return foundit;
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
   * Add the node into a vector of nodes where it should occur in
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
   * document order.
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
   * @param node The node to be added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
   * @param test true if we should test for doc order
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
   * @param support The XPath runtime context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
   * @return insertIndex.
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
  public int addNodeInDocOrder(Node node, boolean test, XPathContext support)
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
    int insertIndex = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
    if (test)
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
      // This needs to do a binary search, but a binary search
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
      // is somewhat tough because the sequence test involves
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
      // two nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
      int size = size(), i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
      for (i = size - 1; i >= 0; i--)
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
        Node child = (Node) elementAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
        if (child == node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
          i = -2;  // Duplicate, suppress insert
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
        if (!DOM2Helper.isNodeAfter(node, child))
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
      if (i != -2)
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
        insertIndex = i + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
        insertElementAt(node, insertIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
      insertIndex = this.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
      boolean foundit = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
      for (int i = 0; i < insertIndex; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
        if (this.item(i).equals(node))
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
          foundit = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
      if (!foundit)
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
        addElement(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
    // checkDups();
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
    return insertIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
  }  // end addNodeInDocOrder(Vector v, Object obj)
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
   * Add the node into a vector of nodes where it should occur in
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
   * document order.
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
   * @param node The node to be added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
   * @param support The XPath runtime context.
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
   * @return The index where it was inserted.
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
   * a mutable type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
  public int addNodeInDocOrder(Node node, XPathContext support)
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
    return addNodeInDocOrder(node, true, support);
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
  }  // end addNodeInDocOrder(Vector v, Object obj)
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
  /** If this node is being used as an iterator, the next index that nextNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
   *  will return.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
  transient protected int m_next = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
   * Get the current position, which is one less than
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
   * the next nextNode() call will retrieve.  i.e. if
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
   * you call getCurrentPos() and the return is 0, the next
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
   * fetch will take place at index 1.
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
   * @return The the current position index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
  public int getCurrentPos()
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
    return m_next;
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
   * Set the current position in the node set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
   * @param i Must be a valid index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
   * a cached type, and thus doesn't permit indexed access.
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
  public void setCurrentPos(int i)
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
    if (!m_cacheNodes)
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
      throw new RuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
    m_next = i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
   * Return the last fetched node.  Needed to support the UnionPathIterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
   * @return the last fetched node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
   * @throws RuntimeException thrown if this NodeSet is not of
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
   * a cached type, and thus doesn't permit indexed access.
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
  public Node getCurrentNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
    if (!m_cacheNodes)
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
      throw new RuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
    int saved = m_next;
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
    Node n = (m_next < m_firstFree) ? elementAt(m_next) : null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
    m_next = saved; // HACK: I think this is a bit of a hack.  -sb
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
    return n;
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
  /** True if this list can be mutated.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
  transient protected boolean m_mutable = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
  /** True if this list is cached.
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
   *  @serial  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
  transient protected boolean m_cacheNodes = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
   * Get whether or not this is a cached node set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
   * @return True if this list is cached.
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
  public boolean getShouldCacheNodes()
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
    return m_cacheNodes;
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
   * If setShouldCacheNodes(true) is called, then nodes will
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
   * be cached.  They are not cached by default. This switch must
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
   * be set before the first call to nextNode is made, to ensure
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
   * that all nodes are cached.
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
   * @param b true if this node set should be cached.
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
   * @throws RuntimeException thrown if an attempt is made to
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
   * request caching after we've already begun stepping through the
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
   * nodes in this set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
  public void setShouldCacheNodes(boolean b)
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
    if (!isFresh())
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
      throw new RuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_CALL_SETSHOULDCACHENODE, null)); //"Can not call setShouldCacheNodes after nextNode has been called!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
    m_cacheNodes = b;
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
    m_mutable = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
  transient private int m_last = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
  public int getLast()
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
    return m_last;
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
  public void setLast(int last)
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
    m_last = last;
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
  /** Size of blocks to allocate.
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
   *  @serial          */
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
  private int m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
  /** Array of nodes this points to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
   *  @serial          */
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
  Node m_map[];
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
  /** Number of nodes in this NodeVector.
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
   *  @serial          */
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
  protected int m_firstFree = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
  /** Size of the array this points to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
   *  @serial           */
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
  private int m_mapSize;  // lazy initialization
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
   * Get a cloned LocPathIterator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
   * @return A clone of this
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
   * @throws CloneNotSupportedException
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
  public Object clone() throws CloneNotSupportedException
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
    NodeSet clone = (NodeSet) super.clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
    if ((null != this.m_map) && (this.m_map == clone.m_map))
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
      clone.m_map = new Node[this.m_map.length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
      System.arraycopy(this.m_map, 0, clone.m_map, 0, this.m_map.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
    return clone;
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
   * Get the length of the list.
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
   * @return Number of nodes in this NodeVector
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
  public int size()
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
    return m_firstFree;
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
   * Append a Node onto the vector.
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
   * @param value Node to add to the vector
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
  public void addElement(Node value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
    if ((m_firstFree + 1) >= m_mapSize)
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
      if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
        m_map = new Node[m_blocksize];
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
        m_mapSize = m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
        m_mapSize += m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
        Node newMap[] = new Node[m_mapSize];
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
        System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
        m_map = newMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
    m_map[m_firstFree] = value;
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
    m_firstFree++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
   * Append a Node onto the vector.
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
   * @param value Node to add to the vector
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
  public final void push(Node value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
    int ff = m_firstFree;
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
    if ((ff + 1) >= m_mapSize)
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
      if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
        m_map = new Node[m_blocksize];
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
        m_mapSize = m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
        m_mapSize += m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
        Node newMap[] = new Node[m_mapSize];
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
        System.arraycopy(m_map, 0, newMap, 0, ff + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
        m_map = newMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
    m_map[ff] = value;
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
    ff++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
    m_firstFree = ff;
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
   * Pop a node from the tail of the vector and return the result.
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
   * @return the node at the tail of the vector
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
  public final Node pop()
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
    m_firstFree--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
    Node n = m_map[m_firstFree];
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
    m_map[m_firstFree] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
    return n;
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
   * Pop a node from the tail of the vector and return the
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
   * top of the stack after the pop.
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
   * @return The top of the stack after it's been popped
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
  public final Node popAndTop()
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
    m_firstFree--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
    m_map[m_firstFree] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
    return (m_firstFree == 0) ? null : m_map[m_firstFree - 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
   * Pop a node from the tail of the vector.
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
  public final void popQuick()
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
    m_firstFree--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
    m_map[m_firstFree] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
   * Return the node at the top of the stack without popping the stack.
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
   * Special purpose method for TransformerImpl, pushElemTemplateElement.
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
   * Performance critical.
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
   * @return Node at the top of the stack or null if stack is empty.
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
  public final Node peepOrNull()
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
    return ((null != m_map) && (m_firstFree > 0))
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
           ? m_map[m_firstFree - 1] : null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
   * Push a pair of nodes into the stack.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
   * Special purpose method for TransformerImpl, pushElemTemplateElement.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
   * Performance critical.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
   * @param v1 First node to add to vector
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
   * @param v2 Second node to add to vector
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
  public final void pushPair(Node v1, Node v2)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
      m_map = new Node[m_blocksize];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
      m_mapSize = m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
      if ((m_firstFree + 2) >= m_mapSize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
        m_mapSize += m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
        Node newMap[] = new Node[m_mapSize];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
        System.arraycopy(m_map, 0, newMap, 0, m_firstFree);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
        m_map = newMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
    m_map[m_firstFree] = v1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
    m_map[m_firstFree + 1] = v2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
    m_firstFree += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
   * Pop a pair of nodes from the tail of the stack.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
   * Special purpose method for TransformerImpl, pushElemTemplateElement.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
   * Performance critical.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
  public final void popPair()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
    m_firstFree -= 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
    m_map[m_firstFree] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
    m_map[m_firstFree + 1] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
   * Set the tail of the stack to the given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
   * Special purpose method for TransformerImpl, pushElemTemplateElement.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
   * Performance critical.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
   * @param n Node to set at the tail of vector
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
  public final void setTail(Node n)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
    m_map[m_firstFree - 1] = n;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
   * Set the given node one position from the tail.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
   * Special purpose method for TransformerImpl, pushElemTemplateElement.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
   * Performance critical.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
   * @param n Node to set
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
  public final void setTailSub1(Node n)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
    m_map[m_firstFree - 2] = n;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
   * Return the node at the tail of the vector without popping
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
   * Special purpose method for TransformerImpl, pushElemTemplateElement.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
   * Performance critical.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
   * @return Node at the tail of the vector
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
  public final Node peepTail()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
    return m_map[m_firstFree - 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
   * Return the node one position from the tail without popping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
   * Special purpose method for TransformerImpl, pushElemTemplateElement.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
   * Performance critical.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
   * @return Node one away from the tail
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
  public final Node peepTailSub1()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
    return m_map[m_firstFree - 2];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
   * Inserts the specified node in this vector at the specified index.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
   * Each component in this vector with an index greater or equal to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
   * the specified index is shifted upward to have an index one greater
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
   * than the value it had previously.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
   * @param value Node to insert
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
   * @param at Position where to insert
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
  public void insertElementAt(Node value, int at)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
      m_map = new Node[m_blocksize];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
      m_mapSize = m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
    else if ((m_firstFree + 1) >= m_mapSize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
      m_mapSize += m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
      Node newMap[] = new Node[m_mapSize];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
      m_map = newMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
    if (at <= (m_firstFree - 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
      System.arraycopy(m_map, at, m_map, at + 1, m_firstFree - at);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
    m_map[at] = value;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
    m_firstFree++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
   * Append the nodes to the list.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
   * @param nodes NodeVector to append to this list
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
  public void appendNodes(NodeSet nodes)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
    int nNodes = nodes.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
      m_mapSize = nNodes + m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
      m_map = new Node[m_mapSize];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
    else if ((m_firstFree + nNodes) >= m_mapSize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
      m_mapSize += (nNodes + m_blocksize);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
      Node newMap[] = new Node[m_mapSize];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + nNodes);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
      m_map = newMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
    System.arraycopy(nodes.m_map, 0, m_map, m_firstFree, nNodes);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
    m_firstFree += nNodes;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
   * Inserts the specified node in this vector at the specified index.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
   * Each component in this vector with an index greater or equal to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
   * the specified index is shifted upward to have an index one greater
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
   * than the value it had previously.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
  public void removeAllElements()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
      return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
    for (int i = 0; i < m_firstFree; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
      m_map[i] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
    m_firstFree = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
   * Removes the first occurrence of the argument from this vector.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
   * If the object is found in this vector, each component in the vector
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
   * with an index greater or equal to the object's index is shifted
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
   * downward to have an index one smaller than the value it had
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
   * previously.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
   * @param s Node to remove from the list
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
   * @return True if the node was successfully removed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
  public boolean removeElement(Node s)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
      return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
    for (int i = 0; i < m_firstFree; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
      Node node = m_map[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
      if ((null != node) && node.equals(s))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
        if (i < m_firstFree - 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
          System.arraycopy(m_map, i + 1, m_map, i, m_firstFree - i - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
        m_firstFree--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
        m_map[m_firstFree] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
   * Deletes the component at the specified index. Each component in
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
   * this vector with an index greater or equal to the specified
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
   * index is shifted downward to have an index one smaller than
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
   * the value it had previously.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
   * @param i Index of node to remove
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
  public void removeElementAt(int i)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
      return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
    if (i >= m_firstFree)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
      throw new ArrayIndexOutOfBoundsException(i + " >= " + m_firstFree);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
    else if (i < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
      throw new ArrayIndexOutOfBoundsException(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
    if (i < m_firstFree - 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
      System.arraycopy(m_map, i + 1, m_map, i, m_firstFree - i - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
    m_firstFree--;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
    m_map[m_firstFree] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
   * Sets the component at the specified index of this vector to be the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
   * specified object. The previous component at that position is discarded.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
   * The index must be a value greater than or equal to 0 and less
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
   * than the current size of the vector.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
   * @param node Node to set
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
   * @param index Index of where to set the node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
  public void setElementAt(Node node, int index)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
    if (!m_mutable)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
      m_map = new Node[m_blocksize];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
      m_mapSize = m_blocksize;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
    m_map[index] = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
   * Get the nth element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
   * @param i Index of node to get
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
   * @return Node at specified index
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
  public Node elementAt(int i)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1283
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1285
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
    return m_map[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
   * Tell if the table contains the given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
   * @param s Node to look for
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
   * @return True if the given node was found.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
  public boolean contains(Node s)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
    runTo(-1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
      return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
    for (int i = 0; i < m_firstFree; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
      Node node = m_map[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
      if ((null != node) && node.equals(s))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
   * Searches for the first occurence of the given argument,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
   * beginning the search at index, and testing for equality
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
   * using the equals method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
   * @param elem Node to look for
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
   * @param index Index of where to start the search
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
   * @return the index of the first occurrence of the object
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
   * argument in this vector at position index or later in the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
   * vector; returns -1 if the object is not found.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
  public int indexOf(Node elem, int index)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
    runTo(-1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1331
      return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
    for (int i = index; i < m_firstFree; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
      Node node = m_map[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
      if ((null != node) && node.equals(elem))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
        return i;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1339
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
    return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
   * Searches for the first occurence of the given argument,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1346
   * beginning the search at index, and testing for equality
7f561c08de6b Initial load
duke
parents:
diff changeset
  1347
   * using the equals method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1348
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1349
   * @param elem Node to look for
7f561c08de6b Initial load
duke
parents:
diff changeset
  1350
   * @return the index of the first occurrence of the object
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
   * argument in this vector at position index or later in the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
   * vector; returns -1 if the object is not found.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
  public int indexOf(Node elem)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
    runTo(-1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1357
7f561c08de6b Initial load
duke
parents:
diff changeset
  1358
    if (null == m_map)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
      return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
    for (int i = 0; i < m_firstFree; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
      Node node = m_map[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
      if ((null != node) && node.equals(elem))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
        return i;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1367
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
7f561c08de6b Initial load
duke
parents:
diff changeset
  1369
    return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
}