1 16 19 package org.apache.xalan.lib.sql; 20 21 import java.util.Vector ; 22 23 30 public class ObjectArray 31 { 32 34 private int m_minArraySize = 10; 35 38 private Vector m_Arrays = new Vector (200); 39 40 44 private _ObjectArray m_currentArray; 45 46 47 50 private int m_nextSlot; 51 52 53 55 public ObjectArray( ) 56 { 57 init(10); 61 } 62 63 66 public ObjectArray( final int minArraySize ) 67 { 68 init(minArraySize); 69 } 70 71 75 private void init( int size ) 76 { 77 m_minArraySize = size; 78 m_currentArray = new _ObjectArray(m_minArraySize); 79 } 80 81 85 public Object getAt( final int idx ) 86 { 87 int arrayIndx = idx / m_minArraySize; 88 int arrayOffset = idx - (arrayIndx * m_minArraySize); 89 90 if (arrayIndx < m_Arrays.size()) 94 { 95 _ObjectArray a = (_ObjectArray)m_Arrays.elementAt(arrayIndx); 96 return a.objects[arrayOffset]; 97 } 98 else 99 { 100 102 return m_currentArray.objects[arrayOffset]; 106 } 107 } 108 109 114 public void setAt( final int idx, final Object obj ) 115 { 116 int arrayIndx = idx / m_minArraySize; 117 int arrayOffset = idx - (arrayIndx * m_minArraySize); 118 119 if (arrayIndx < m_Arrays.size()) 123 { 124 _ObjectArray a = (_ObjectArray)m_Arrays.elementAt(arrayIndx); 125 a.objects[arrayOffset] = obj; 126 } 127 else 128 { 129 131 m_currentArray.objects[arrayOffset] = obj; 135 } 136 } 137 138 139 140 144 public int append( Object o ) 145 { 146 if (m_nextSlot >= m_minArraySize) 147 { 148 m_Arrays.addElement(m_currentArray); 149 m_nextSlot = 0; 150 m_currentArray = new _ObjectArray(m_minArraySize); 151 } 152 153 m_currentArray.objects[m_nextSlot] = o; 154 155 int pos = (m_Arrays.size() * m_minArraySize) + m_nextSlot; 156 157 m_nextSlot++; 158 159 return pos; 160 } 161 162 163 165 class _ObjectArray 166 { 167 169 public Object [] objects; 170 173 public _ObjectArray( int size ) 174 { 175 objects = new Object [size]; 176 } 177 } 178 179 183 public static void main( String [] args ) 184 { 185 String [] word={ 186 "Zero","One","Two","Three","Four","Five", 187 "Six","Seven","Eight","Nine","Ten", 188 "Eleven","Twelve","Thirteen","Fourteen","Fifteen", 189 "Sixteen","Seventeen","Eighteen","Nineteen","Twenty", 190 "Twenty-One","Twenty-Two","Twenty-Three","Twenty-Four", 191 "Twenty-Five","Twenty-Six","Twenty-Seven","Twenty-Eight", 192 "Twenty-Nine","Thirty","Thirty-One","Thirty-Two", 193 "Thirty-Three","Thirty-Four","Thirty-Five","Thirty-Six", 194 "Thirty-Seven","Thirty-Eight","Thirty-Nine"}; 195 196 ObjectArray m_ObjectArray = new ObjectArray(); 197 for (int x =0; x< word.length; x++) 199 { 200 System.out.print(" - " + m_ObjectArray.append(word[x])); 201 } 202 203 System.out.println("\n"); 204 for (int x =0; x< word.length; x++) 206 { 207 String s = (String ) m_ObjectArray.getAt(x); 208 System.out.println(s); 209 } 210 211 System.out.println((String ) m_ObjectArray.getAt(5)); 213 System.out.println((String ) m_ObjectArray.getAt(10)); 214 System.out.println((String ) m_ObjectArray.getAt(20)); 215 System.out.println((String ) m_ObjectArray.getAt(2)); 216 System.out.println((String ) m_ObjectArray.getAt(15)); 217 System.out.println((String ) m_ObjectArray.getAt(30)); 218 System.out.println((String ) m_ObjectArray.getAt(6)); 219 System.out.println((String ) m_ObjectArray.getAt(8)); 220 221 System.out.println((String ) m_ObjectArray.getAt(40)); 223 224 } 225 } 226 | Popular Tags |