KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xpath > internal > compiler > OpMapVector


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
20 package com.sun.org.apache.xpath.internal.compiler;
21
22 /**
23  *
24  * Like IntVector, but used only for the OpMap array. Length of array
25  * is kept in the m_lengthPos position of the array. Only the required methods
26  * are in included here.
27  * @xsl.usage internal
28  */

29 public class OpMapVector {
30     
31  /** Size of blocks to allocate */
32   protected int m_blocksize;
33
34   /** Array of ints */
35   protected int m_map[]; // IntStack is trying to see this directly
36

37   /** Position where size of array is kept */
38   protected int m_lengthPos = 0;
39
40   /** Size of array */
41   protected int m_mapSize;
42   
43     /**
44    * Construct a OpMapVector, using the given block size.
45    *
46    * @param blocksize Size of block to allocate
47    */

48   public OpMapVector(int blocksize, int increaseSize, int lengthPos)
49   {
50
51     m_blocksize = increaseSize;
52     m_mapSize = blocksize;
53     m_lengthPos = lengthPos;
54     m_map = new int[blocksize];
55   }
56   
57   /**
58    * Get the nth element.
59    *
60    * @param i index of object to get
61    *
62    * @return object at given index
63    */

64   public final int elementAt(int i)
65   {
66     return m_map[i];
67   }
68    
69     /**
70    * Sets the component at the specified index of this vector to be the
71    * specified object. The previous component at that position is discarded.
72    *
73    * The index must be a value greater than or equal to 0 and less
74    * than the current size of the vector.
75    *
76    * @param node object to set
77    * @param index Index of where to set the object
78    */

79   public final void setElementAt(int value, int index)
80   {
81     if (index >= m_mapSize)
82     {
83       int oldSize = m_mapSize;
84       
85       m_mapSize += m_blocksize;
86
87       int newMap[] = new int[m_mapSize];
88
89       System.arraycopy(m_map, 0, newMap, 0, oldSize);
90
91       m_map = newMap;
92     }
93
94     m_map[index] = value;
95   }
96   
97   
98   /*
99    * Reset the array to the supplied size. No checking is done.
100    *
101    * @param size The size to trim to.
102    */

103   public final void setToSize(int size) {
104     
105     int newMap[] = new int[size];
106
107     System.arraycopy(m_map, 0, newMap, 0, m_map[m_lengthPos]);
108
109     m_mapSize = size;
110     m_map = newMap;
111     
112   }
113
114 }
115
Popular Tags