~ubuntu-branches/ubuntu/saucy/libxalan2-java/saucy-security

« back to all changes in this revision

Viewing changes to src/org/apache/xml/utils/ObjectVector.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2008-04-27 10:20:03 UTC
  • mfrom: (1.1.3 upstream) (3.1.11 hardy)
  • Revision ID: james.westby@ubuntu.com-20080427102003-qy06c2if0qayzwlg
Tags: 2.7.1-2
* Build-Depends on default-jdk-builddep. Closes: #477893
* Clarified debian/copyright.
* Don't use '-1' in Build-Depends.
* Updated watch file to match upstream correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2002-2004 The Apache Software Foundation.
3
 
 *
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 *
8
 
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
/*
17
 
 * $Id$
18
 
 */
19
 
package org.apache.xml.utils;
20
 
 
21
 
/**
22
 
 * A very simple table that stores a list of objects.
23
 
 *
24
 
 * This version is based on a "realloc" strategy -- a simle array is
25
 
 * used, and when more storage is needed, a larger array is obtained
26
 
 * and all existing data is recopied into it. As a result, read/write
27
 
 * access to existing nodes is O(1) fast but appending may be O(N**2)
28
 
 * slow. 
29
 
 * @xsl.usage internal
30
 
 */
31
 
public class ObjectVector implements Cloneable
32
 
{
33
 
 
34
 
  /** Size of blocks to allocate          */
35
 
  protected int m_blocksize;
36
 
 
37
 
  /** Array of objects          */
38
 
  protected Object m_map[]; 
39
 
 
40
 
  /** Number of ints in array          */
41
 
  protected int m_firstFree = 0;
42
 
 
43
 
  /** Size of array          */
44
 
  protected int m_mapSize;
45
 
 
46
 
  /**
47
 
   * Default constructor.  Note that the default
48
 
   * block size is very small, for small lists.
49
 
   */
50
 
  public ObjectVector()
51
 
  {
52
 
 
53
 
    m_blocksize = 32;
54
 
    m_mapSize = m_blocksize;
55
 
    m_map = new Object[m_blocksize];
56
 
  }
57
 
 
58
 
  /**
59
 
   * Construct a IntVector, using the given block size.
60
 
   *
61
 
   * @param blocksize Size of block to allocate
62
 
   */
63
 
  public ObjectVector(int blocksize)
64
 
  {
65
 
 
66
 
    m_blocksize = blocksize;
67
 
    m_mapSize = blocksize;
68
 
    m_map = new Object[blocksize];
69
 
  }
70
 
  
71
 
  /**
72
 
   * Construct a IntVector, using the given block size.
73
 
   *
74
 
   * @param blocksize Size of block to allocate
75
 
   */
76
 
  public ObjectVector(int blocksize, int increaseSize)
77
 
  {
78
 
 
79
 
    m_blocksize = increaseSize;
80
 
    m_mapSize = blocksize;
81
 
    m_map = new Object[blocksize];
82
 
  }
83
 
 
84
 
  /**
85
 
   * Copy constructor for ObjectVector
86
 
   * 
87
 
   * @param v Existing ObjectVector to copy
88
 
   */
89
 
  public ObjectVector(ObjectVector v)
90
 
  {
91
 
        m_map = new Object[v.m_mapSize];
92
 
    m_mapSize = v.m_mapSize;
93
 
    m_firstFree = v.m_firstFree;
94
 
        m_blocksize = v.m_blocksize;
95
 
        System.arraycopy(v.m_map, 0, m_map, 0, m_firstFree);
96
 
  }
97
 
 
98
 
  /**
99
 
   * Get the length of the list.
100
 
   *
101
 
   * @return length of the list
102
 
   */
103
 
  public final int size()
104
 
  {
105
 
    return m_firstFree;
106
 
  }
107
 
  
108
 
  /**
109
 
   * Get the length of the list.
110
 
   *
111
 
   * @return length of the list
112
 
   */
113
 
  public final void setSize(int sz)
114
 
  {
115
 
    m_firstFree = sz;
116
 
  }
117
 
 
118
 
 
119
 
  /**
120
 
   * Append an object onto the vector.
121
 
   *
122
 
   * @param value Object to add to the list 
123
 
   */
124
 
  public final void addElement(Object value)
125
 
  {
126
 
 
127
 
    if ((m_firstFree + 1) >= m_mapSize)
128
 
    {
129
 
      m_mapSize += m_blocksize;
130
 
 
131
 
      Object newMap[] = new Object[m_mapSize];
132
 
 
133
 
      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
134
 
 
135
 
      m_map = newMap;
136
 
    }
137
 
 
138
 
    m_map[m_firstFree] = value;
139
 
 
140
 
    m_firstFree++;
141
 
  }
142
 
  
143
 
  /**
144
 
   * Append several Object values onto the vector.
145
 
   *
146
 
   * @param value Object to add to the list 
147
 
   */
148
 
  public final void addElements(Object value, int numberOfElements)
149
 
  {
150
 
 
151
 
    if ((m_firstFree + numberOfElements) >= m_mapSize)
152
 
    {
153
 
      m_mapSize += (m_blocksize+numberOfElements);
154
 
 
155
 
      Object newMap[] = new Object[m_mapSize];
156
 
 
157
 
      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
158
 
 
159
 
      m_map = newMap;
160
 
    }
161
 
 
162
 
    for (int i = 0; i < numberOfElements; i++) 
163
 
    {
164
 
      m_map[m_firstFree] = value;
165
 
      m_firstFree++;
166
 
    }
167
 
  }
168
 
  
169
 
  /**
170
 
   * Append several slots onto the vector, but do not set the values.
171
 
   *
172
 
   * @param numberOfElements number of slots to append
173
 
   */
174
 
  public final void addElements(int numberOfElements)
175
 
  {
176
 
 
177
 
    if ((m_firstFree + numberOfElements) >= m_mapSize)
178
 
    {
179
 
      m_mapSize += (m_blocksize+numberOfElements);
180
 
 
181
 
      Object newMap[] = new Object[m_mapSize];
182
 
 
183
 
      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
184
 
 
185
 
      m_map = newMap;
186
 
    }
187
 
    
188
 
    m_firstFree += numberOfElements;
189
 
  }
190
 
  
191
 
 
192
 
  /**
193
 
   * Inserts the specified object in this vector at the specified index.
194
 
   * Each component in this vector with an index greater or equal to
195
 
   * the specified index is shifted upward to have an index one greater
196
 
   * than the value it had previously.
197
 
   *
198
 
   * @param value Object to insert
199
 
   * @param at Index of where to insert 
200
 
   */
201
 
  public final void insertElementAt(Object value, int at)
202
 
  {
203
 
 
204
 
    if ((m_firstFree + 1) >= m_mapSize)
205
 
    {
206
 
      m_mapSize += m_blocksize;
207
 
 
208
 
      Object newMap[] = new Object[m_mapSize];
209
 
 
210
 
      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
211
 
 
212
 
      m_map = newMap;
213
 
    }
214
 
 
215
 
    if (at <= (m_firstFree - 1))
216
 
    {
217
 
      System.arraycopy(m_map, at, m_map, at + 1, m_firstFree - at);
218
 
    }
219
 
 
220
 
    m_map[at] = value;
221
 
 
222
 
    m_firstFree++;
223
 
  }
224
 
 
225
 
  /**
226
 
   * Remove all elements objects from the list. 
227
 
   */
228
 
  public final void removeAllElements()
229
 
  {
230
 
 
231
 
    for (int i = 0; i < m_firstFree; i++)
232
 
    {
233
 
      m_map[i] = null;
234
 
    }
235
 
 
236
 
    m_firstFree = 0;
237
 
  }
238
 
 
239
 
  /**
240
 
   * Removes the first occurrence of the argument from this vector.
241
 
   * If the object is found in this vector, each component in the vector
242
 
   * with an index greater or equal to the object's index is shifted
243
 
   * downward to have an index one smaller than the value it had
244
 
   * previously.
245
 
   *
246
 
   * @param s Object to remove from array
247
 
   *
248
 
   * @return True if the object was removed, false if it was not found
249
 
   */
250
 
  public final boolean removeElement(Object s)
251
 
  {
252
 
 
253
 
    for (int i = 0; i < m_firstFree; i++)
254
 
    {
255
 
      if (m_map[i] == s)
256
 
      {
257
 
        if ((i + 1) < m_firstFree)
258
 
          System.arraycopy(m_map, i + 1, m_map, i - 1, m_firstFree - i);
259
 
        else
260
 
          m_map[i] = null;
261
 
 
262
 
        m_firstFree--;
263
 
 
264
 
        return true;
265
 
      }
266
 
    }
267
 
 
268
 
    return false;
269
 
  }
270
 
 
271
 
  /**
272
 
   * Deletes the component at the specified index. Each component in
273
 
   * this vector with an index greater or equal to the specified
274
 
   * index is shifted downward to have an index one smaller than
275
 
   * the value it had previously.
276
 
   *
277
 
   * @param i index of where to remove an object
278
 
   */
279
 
  public final void removeElementAt(int i)
280
 
  {
281
 
 
282
 
    if (i > m_firstFree)
283
 
      System.arraycopy(m_map, i + 1, m_map, i, m_firstFree);
284
 
    else
285
 
      m_map[i] = null;
286
 
 
287
 
    m_firstFree--;
288
 
  }
289
 
 
290
 
  /**
291
 
   * Sets the component at the specified index of this vector to be the
292
 
   * specified object. The previous component at that position is discarded.
293
 
   *
294
 
   * The index must be a value greater than or equal to 0 and less
295
 
   * than the current size of the vector.
296
 
   *
297
 
   * @param value object to set
298
 
   * @param index Index of where to set the object
299
 
   */
300
 
  public final void setElementAt(Object value, int index)
301
 
  {
302
 
    m_map[index] = value;
303
 
  }
304
 
 
305
 
  /**
306
 
   * Get the nth element.
307
 
   *
308
 
   * @param i index of object to get
309
 
   *
310
 
   * @return object at given index
311
 
   */
312
 
  public final Object elementAt(int i)
313
 
  {
314
 
    return m_map[i];
315
 
  }
316
 
 
317
 
  /**
318
 
   * Tell if the table contains the given Object.
319
 
   *
320
 
   * @param s object to look for
321
 
   *
322
 
   * @return true if the object is in the list
323
 
   */
324
 
  public final boolean contains(Object s)
325
 
  {
326
 
 
327
 
    for (int i = 0; i < m_firstFree; i++)
328
 
    {
329
 
      if (m_map[i] == s)
330
 
        return true;
331
 
    }
332
 
 
333
 
    return false;
334
 
  }
335
 
 
336
 
  /**
337
 
   * Searches for the first occurence of the given argument,
338
 
   * beginning the search at index, and testing for equality
339
 
   * using the equals method.
340
 
   *
341
 
   * @param elem object to look for
342
 
   * @param index Index of where to begin search
343
 
   * @return the index of the first occurrence of the object
344
 
   * argument in this vector at position index or later in the
345
 
   * vector; returns -1 if the object is not found.
346
 
   */
347
 
  public final int indexOf(Object elem, int index)
348
 
  {
349
 
 
350
 
    for (int i = index; i < m_firstFree; i++)
351
 
    {
352
 
      if (m_map[i] == elem)
353
 
        return i;
354
 
    }
355
 
 
356
 
    return java.lang.Integer.MIN_VALUE;
357
 
  }
358
 
 
359
 
  /**
360
 
   * Searches for the first occurence of the given argument,
361
 
   * beginning the search at index, and testing for equality
362
 
   * using the equals method.
363
 
   *
364
 
   * @param elem object to look for
365
 
   * @return the index of the first occurrence of the object
366
 
   * argument in this vector at position index or later in the
367
 
   * vector; returns -1 if the object is not found.
368
 
   */
369
 
  public final int indexOf(Object elem)
370
 
  {
371
 
 
372
 
    for (int i = 0; i < m_firstFree; i++)
373
 
    {
374
 
      if (m_map[i] == elem)
375
 
        return i;
376
 
    }
377
 
 
378
 
    return java.lang.Integer.MIN_VALUE;
379
 
  }
380
 
 
381
 
  /**
382
 
   * Searches for the first occurence of the given argument,
383
 
   * beginning the search at index, and testing for equality
384
 
   * using the equals method.
385
 
   *
386
 
   * @param elem Object to look for
387
 
   * @return the index of the first occurrence of the object
388
 
   * argument in this vector at position index or later in the
389
 
   * vector; returns -1 if the object is not found.
390
 
   */
391
 
  public final int lastIndexOf(Object elem)
392
 
  {
393
 
 
394
 
    for (int i = (m_firstFree - 1); i >= 0; i--)
395
 
    {
396
 
      if (m_map[i] == elem)
397
 
        return i;
398
 
    }
399
 
 
400
 
    return java.lang.Integer.MIN_VALUE;
401
 
  }
402
 
  
403
 
  /*
404
 
   * Reset the array to the supplied size.  
405
 
   * 
406
 
   * @param size 
407
 
   */
408
 
  public final void setToSize(int size) {
409
 
    
410
 
    Object newMap[] = new Object[size];
411
 
    
412
 
    System.arraycopy(m_map, 0, newMap, 0, m_firstFree);
413
 
    m_mapSize = size;
414
 
 
415
 
    m_map = newMap;
416
 
    
417
 
  }  
418
 
  
419
 
  /**
420
 
   * Returns clone of current ObjectVector
421
 
   * 
422
 
   * @return clone of current ObjectVector
423
 
   */
424
 
  public Object clone()
425
 
    throws CloneNotSupportedException
426
 
  {
427
 
        return new ObjectVector(this);
428
 
  }
429
 
}
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one
 
3
 * or more contributor license agreements. See the NOTICE file
 
4
 * distributed with this work for additional information
 
5
 * regarding copyright ownership. The ASF licenses this file
 
6
 * to you under the Apache License, Version 2.0 (the  "License");
 
7
 * you may not use this file except in compliance with the License.
 
8
 * You may obtain a copy of the License at
 
9
 *
 
10
 *     http://www.apache.org/licenses/LICENSE-2.0
 
11
 *
 
12
 * Unless required by applicable law or agreed to in writing, software
 
13
 * distributed under the License is distributed on an "AS IS" BASIS,
 
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
15
 * See the License for the specific language governing permissions and
 
16
 * limitations under the License.
 
17
 */
 
18
/*
 
19
 * $Id$
 
20
 */
 
21
package org.apache.xml.utils;
 
22
 
 
23
/**
 
24
 * A very simple table that stores a list of objects.
 
25
 *
 
26
 * This version is based on a "realloc" strategy -- a simle array is
 
27
 * used, and when more storage is needed, a larger array is obtained
 
28
 * and all existing data is recopied into it. As a result, read/write
 
29
 * access to existing nodes is O(1) fast but appending may be O(N**2)
 
30
 * slow. 
 
31
 * @xsl.usage internal
 
32
 */
 
33
public class ObjectVector implements Cloneable
 
34
{
 
35
 
 
36
  /** Size of blocks to allocate          */
 
37
  protected int m_blocksize;
 
38
 
 
39
  /** Array of objects          */
 
40
  protected Object m_map[]; 
 
41
 
 
42
  /** Number of ints in array          */
 
43
  protected int m_firstFree = 0;
 
44
 
 
45
  /** Size of array          */
 
46
  protected int m_mapSize;
 
47
 
 
48
  /**
 
49
   * Default constructor.  Note that the default
 
50
   * block size is very small, for small lists.
 
51
   */
 
52
  public ObjectVector()
 
53
  {
 
54
 
 
55
    m_blocksize = 32;
 
56
    m_mapSize = m_blocksize;
 
57
    m_map = new Object[m_blocksize];
 
58
  }
 
59
 
 
60
  /**
 
61
   * Construct a IntVector, using the given block size.
 
62
   *
 
63
   * @param blocksize Size of block to allocate
 
64
   */
 
65
  public ObjectVector(int blocksize)
 
66
  {
 
67
 
 
68
    m_blocksize = blocksize;
 
69
    m_mapSize = blocksize;
 
70
    m_map = new Object[blocksize];
 
71
  }
 
72
  
 
73
  /**
 
74
   * Construct a IntVector, using the given block size.
 
75
   *
 
76
   * @param blocksize Size of block to allocate
 
77
   */
 
78
  public ObjectVector(int blocksize, int increaseSize)
 
79
  {
 
80
 
 
81
    m_blocksize = increaseSize;
 
82
    m_mapSize = blocksize;
 
83
    m_map = new Object[blocksize];
 
84
  }
 
85
 
 
86
  /**
 
87
   * Copy constructor for ObjectVector
 
88
   * 
 
89
   * @param v Existing ObjectVector to copy
 
90
   */
 
91
  public ObjectVector(ObjectVector v)
 
92
  {
 
93
        m_map = new Object[v.m_mapSize];
 
94
    m_mapSize = v.m_mapSize;
 
95
    m_firstFree = v.m_firstFree;
 
96
        m_blocksize = v.m_blocksize;
 
97
        System.arraycopy(v.m_map, 0, m_map, 0, m_firstFree);
 
98
  }
 
99
 
 
100
  /**
 
101
   * Get the length of the list.
 
102
   *
 
103
   * @return length of the list
 
104
   */
 
105
  public final int size()
 
106
  {
 
107
    return m_firstFree;
 
108
  }
 
109
  
 
110
  /**
 
111
   * Get the length of the list.
 
112
   *
 
113
   * @return length of the list
 
114
   */
 
115
  public final void setSize(int sz)
 
116
  {
 
117
    m_firstFree = sz;
 
118
  }
 
119
 
 
120
 
 
121
  /**
 
122
   * Append an object onto the vector.
 
123
   *
 
124
   * @param value Object to add to the list 
 
125
   */
 
126
  public final void addElement(Object value)
 
127
  {
 
128
 
 
129
    if ((m_firstFree + 1) >= m_mapSize)
 
130
    {
 
131
      m_mapSize += m_blocksize;
 
132
 
 
133
      Object newMap[] = new Object[m_mapSize];
 
134
 
 
135
      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
 
136
 
 
137
      m_map = newMap;
 
138
    }
 
139
 
 
140
    m_map[m_firstFree] = value;
 
141
 
 
142
    m_firstFree++;
 
143
  }
 
144
  
 
145
  /**
 
146
   * Append several Object values onto the vector.
 
147
   *
 
148
   * @param value Object to add to the list 
 
149
   */
 
150
  public final void addElements(Object value, int numberOfElements)
 
151
  {
 
152
 
 
153
    if ((m_firstFree + numberOfElements) >= m_mapSize)
 
154
    {
 
155
      m_mapSize += (m_blocksize+numberOfElements);
 
156
 
 
157
      Object newMap[] = new Object[m_mapSize];
 
158
 
 
159
      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
 
160
 
 
161
      m_map = newMap;
 
162
    }
 
163
 
 
164
    for (int i = 0; i < numberOfElements; i++) 
 
165
    {
 
166
      m_map[m_firstFree] = value;
 
167
      m_firstFree++;
 
168
    }
 
169
  }
 
170
  
 
171
  /**
 
172
   * Append several slots onto the vector, but do not set the values.
 
173
   *
 
174
   * @param numberOfElements number of slots to append
 
175
   */
 
176
  public final void addElements(int numberOfElements)
 
177
  {
 
178
 
 
179
    if ((m_firstFree + numberOfElements) >= m_mapSize)
 
180
    {
 
181
      m_mapSize += (m_blocksize+numberOfElements);
 
182
 
 
183
      Object newMap[] = new Object[m_mapSize];
 
184
 
 
185
      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
 
186
 
 
187
      m_map = newMap;
 
188
    }
 
189
    
 
190
    m_firstFree += numberOfElements;
 
191
  }
 
192
  
 
193
 
 
194
  /**
 
195
   * Inserts the specified object in this vector at the specified index.
 
196
   * Each component in this vector with an index greater or equal to
 
197
   * the specified index is shifted upward to have an index one greater
 
198
   * than the value it had previously.
 
199
   *
 
200
   * @param value Object to insert
 
201
   * @param at Index of where to insert 
 
202
   */
 
203
  public final void insertElementAt(Object value, int at)
 
204
  {
 
205
 
 
206
    if ((m_firstFree + 1) >= m_mapSize)
 
207
    {
 
208
      m_mapSize += m_blocksize;
 
209
 
 
210
      Object newMap[] = new Object[m_mapSize];
 
211
 
 
212
      System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
 
213
 
 
214
      m_map = newMap;
 
215
    }
 
216
 
 
217
    if (at <= (m_firstFree - 1))
 
218
    {
 
219
      System.arraycopy(m_map, at, m_map, at + 1, m_firstFree - at);
 
220
    }
 
221
 
 
222
    m_map[at] = value;
 
223
 
 
224
    m_firstFree++;
 
225
  }
 
226
 
 
227
  /**
 
228
   * Remove all elements objects from the list. 
 
229
   */
 
230
  public final void removeAllElements()
 
231
  {
 
232
 
 
233
    for (int i = 0; i < m_firstFree; i++)
 
234
    {
 
235
      m_map[i] = null;
 
236
    }
 
237
 
 
238
    m_firstFree = 0;
 
239
  }
 
240
 
 
241
  /**
 
242
   * Removes the first occurrence of the argument from this vector.
 
243
   * If the object is found in this vector, each component in the vector
 
244
   * with an index greater or equal to the object's index is shifted
 
245
   * downward to have an index one smaller than the value it had
 
246
   * previously.
 
247
   *
 
248
   * @param s Object to remove from array
 
249
   *
 
250
   * @return True if the object was removed, false if it was not found
 
251
   */
 
252
  public final boolean removeElement(Object s)
 
253
  {
 
254
 
 
255
    for (int i = 0; i < m_firstFree; i++)
 
256
    {
 
257
      if (m_map[i] == s)
 
258
      {
 
259
        if ((i + 1) < m_firstFree)
 
260
          System.arraycopy(m_map, i + 1, m_map, i - 1, m_firstFree - i);
 
261
        else
 
262
          m_map[i] = null;
 
263
 
 
264
        m_firstFree--;
 
265
 
 
266
        return true;
 
267
      }
 
268
    }
 
269
 
 
270
    return false;
 
271
  }
 
272
 
 
273
  /**
 
274
   * Deletes the component at the specified index. Each component in
 
275
   * this vector with an index greater or equal to the specified
 
276
   * index is shifted downward to have an index one smaller than
 
277
   * the value it had previously.
 
278
   *
 
279
   * @param i index of where to remove an object
 
280
   */
 
281
  public final void removeElementAt(int i)
 
282
  {
 
283
 
 
284
    if (i > m_firstFree)
 
285
      System.arraycopy(m_map, i + 1, m_map, i, m_firstFree);
 
286
    else
 
287
      m_map[i] = null;
 
288
 
 
289
    m_firstFree--;
 
290
  }
 
291
 
 
292
  /**
 
293
   * Sets the component at the specified index of this vector to be the
 
294
   * specified object. The previous component at that position is discarded.
 
295
   *
 
296
   * The index must be a value greater than or equal to 0 and less
 
297
   * than the current size of the vector.
 
298
   *
 
299
   * @param value object to set
 
300
   * @param index Index of where to set the object
 
301
   */
 
302
  public final void setElementAt(Object value, int index)
 
303
  {
 
304
    m_map[index] = value;
 
305
  }
 
306
 
 
307
  /**
 
308
   * Get the nth element.
 
309
   *
 
310
   * @param i index of object to get
 
311
   *
 
312
   * @return object at given index
 
313
   */
 
314
  public final Object elementAt(int i)
 
315
  {
 
316
    return m_map[i];
 
317
  }
 
318
 
 
319
  /**
 
320
   * Tell if the table contains the given Object.
 
321
   *
 
322
   * @param s object to look for
 
323
   *
 
324
   * @return true if the object is in the list
 
325
   */
 
326
  public final boolean contains(Object s)
 
327
  {
 
328
 
 
329
    for (int i = 0; i < m_firstFree; i++)
 
330
    {
 
331
      if (m_map[i] == s)
 
332
        return true;
 
333
    }
 
334
 
 
335
    return false;
 
336
  }
 
337
 
 
338
  /**
 
339
   * Searches for the first occurence of the given argument,
 
340
   * beginning the search at index, and testing for equality
 
341
   * using the equals method.
 
342
   *
 
343
   * @param elem object to look for
 
344
   * @param index Index of where to begin search
 
345
   * @return the index of the first occurrence of the object
 
346
   * argument in this vector at position index or later in the
 
347
   * vector; returns -1 if the object is not found.
 
348
   */
 
349
  public final int indexOf(Object elem, int index)
 
350
  {
 
351
 
 
352
    for (int i = index; i < m_firstFree; i++)
 
353
    {
 
354
      if (m_map[i] == elem)
 
355
        return i;
 
356
    }
 
357
 
 
358
    return java.lang.Integer.MIN_VALUE;
 
359
  }
 
360
 
 
361
  /**
 
362
   * Searches for the first occurence of the given argument,
 
363
   * beginning the search at index, and testing for equality
 
364
   * using the equals method.
 
365
   *
 
366
   * @param elem object to look for
 
367
   * @return the index of the first occurrence of the object
 
368
   * argument in this vector at position index or later in the
 
369
   * vector; returns -1 if the object is not found.
 
370
   */
 
371
  public final int indexOf(Object elem)
 
372
  {
 
373
 
 
374
    for (int i = 0; i < m_firstFree; i++)
 
375
    {
 
376
      if (m_map[i] == elem)
 
377
        return i;
 
378
    }
 
379
 
 
380
    return java.lang.Integer.MIN_VALUE;
 
381
  }
 
382
 
 
383
  /**
 
384
   * Searches for the first occurence of the given argument,
 
385
   * beginning the search at index, and testing for equality
 
386
   * using the equals method.
 
387
   *
 
388
   * @param elem Object to look for
 
389
   * @return the index of the first occurrence of the object
 
390
   * argument in this vector at position index or later in the
 
391
   * vector; returns -1 if the object is not found.
 
392
   */
 
393
  public final int lastIndexOf(Object elem)
 
394
  {
 
395
 
 
396
    for (int i = (m_firstFree - 1); i >= 0; i--)
 
397
    {
 
398
      if (m_map[i] == elem)
 
399
        return i;
 
400
    }
 
401
 
 
402
    return java.lang.Integer.MIN_VALUE;
 
403
  }
 
404
  
 
405
  /*
 
406
   * Reset the array to the supplied size.  
 
407
   * 
 
408
   * @param size 
 
409
   */
 
410
  public final void setToSize(int size) {
 
411
    
 
412
    Object newMap[] = new Object[size];
 
413
    
 
414
    System.arraycopy(m_map, 0, newMap, 0, m_firstFree);
 
415
    m_mapSize = size;
 
416
 
 
417
    m_map = newMap;
 
418
    
 
419
  }  
 
420
  
 
421
  /**
 
422
   * Returns clone of current ObjectVector
 
423
   * 
 
424
   * @return clone of current ObjectVector
 
425
   */
 
426
  public Object clone()
 
427
    throws CloneNotSupportedException
 
428
  {
 
429
        return new ObjectVector(this);
 
430
  }
 
431
}