1 16 19 package org.apache.xml.utils; 20 21 26 public class StringVector implements java.io.Serializable 27 { 28 29 30 protected int m_blocksize; 31 32 33 protected String m_map[]; 34 35 36 protected int m_firstFree = 0; 37 38 39 protected int m_mapSize; 40 41 45 public StringVector() 46 { 47 48 m_blocksize = 8; 49 m_mapSize = m_blocksize; 50 m_map = new String [m_blocksize]; 51 } 52 53 58 public StringVector(int blocksize) 59 { 60 61 m_blocksize = blocksize; 62 m_mapSize = blocksize; 63 m_map = new String [blocksize]; 64 } 65 66 71 public int getLength() 72 { 73 return m_firstFree; 74 } 75 76 81 public final int size() 82 { 83 return m_firstFree; 84 } 85 86 91 public final void addElement(String value) 92 { 93 94 if ((m_firstFree + 1) >= m_mapSize) 95 { 96 m_mapSize += m_blocksize; 97 98 String newMap[] = new String [m_mapSize]; 99 100 System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); 101 102 m_map = newMap; 103 } 104 105 m_map[m_firstFree] = value; 106 107 m_firstFree++; 108 } 109 110 117 public final String elementAt(int i) 118 { 119 return m_map[i]; 120 } 121 122 129 public final boolean contains(String s) 130 { 131 132 if (null == s) 133 return false; 134 135 for (int i = 0; i < m_firstFree; i++) 136 { 137 if (m_map[i].equals(s)) 138 return true; 139 } 140 141 return false; 142 } 143 144 151 public final boolean containsIgnoreCase(String s) 152 { 153 154 if (null == s) 155 return false; 156 157 for (int i = 0; i < m_firstFree; i++) 158 { 159 if (m_map[i].equalsIgnoreCase(s)) 160 return true; 161 } 162 163 return false; 164 } 165 166 171 public final void push(String s) 172 { 173 174 if ((m_firstFree + 1) >= m_mapSize) 175 { 176 m_mapSize += m_blocksize; 177 178 String newMap[] = new String [m_mapSize]; 179 180 System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); 181 182 m_map = newMap; 183 } 184 185 m_map[m_firstFree] = s; 186 187 m_firstFree++; 188 } 189 190 196 public final String pop() 197 { 198 199 if (m_firstFree <= 0) 200 return null; 201 202 m_firstFree--; 203 204 String s = m_map[m_firstFree]; 205 206 m_map[m_firstFree] = null; 207 208 return s; 209 } 210 211 216 public final String peek() 217 { 218 return (m_firstFree <= 0) ? null : m_map[m_firstFree - 1]; 219 } 220 } 221 | Popular Tags |