1 16 19 package org.apache.xml.utils; 20 21 26 public class StringToStringTable 27 { 28 29 30 private int m_blocksize; 31 32 33 private String m_map[]; 34 35 36 private int m_firstFree = 0; 37 38 39 private int m_mapSize; 40 41 45 public StringToStringTable() 46 { 47 48 m_blocksize = 16; 49 m_mapSize = m_blocksize; 50 m_map = new String [m_blocksize]; 51 } 52 53 58 public StringToStringTable(int blocksize) 59 { 60 61 m_blocksize = blocksize; 62 m_mapSize = blocksize; 63 m_map = new String [blocksize]; 64 } 65 66 71 public final int getLength() 72 { 73 return m_firstFree; 74 } 75 76 84 public final void put(String key, String value) 85 { 86 87 if ((m_firstFree + 2) >= m_mapSize) 88 { 89 m_mapSize += m_blocksize; 90 91 String newMap[] = new String [m_mapSize]; 92 93 System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); 94 95 m_map = newMap; 96 } 97 98 m_map[m_firstFree] = key; 99 100 m_firstFree++; 101 102 m_map[m_firstFree] = value; 103 104 m_firstFree++; 105 } 106 107 114 public final String get(String key) 115 { 116 117 for (int i = 0; i < m_firstFree; i += 2) 118 { 119 if (m_map[i].equals(key)) 120 return m_map[i + 1]; 121 } 122 123 return null; 124 } 125 126 131 public final void remove(String key) 132 { 133 134 for (int i = 0; i < m_firstFree; i += 2) 135 { 136 if (m_map[i].equals(key)) 137 { 138 if ((i + 2) < m_firstFree) 139 System.arraycopy(m_map, i + 2, m_map, i, m_firstFree - (i + 2)); 140 141 m_firstFree -= 2; 142 m_map[m_firstFree] = null; 143 m_map[m_firstFree + 1] = null; 144 145 break; 146 } 147 } 148 } 149 150 157 public final String getIgnoreCase(String key) 158 { 159 160 if (null == key) 161 return null; 162 163 for (int i = 0; i < m_firstFree; i += 2) 164 { 165 if (m_map[i].equalsIgnoreCase(key)) 166 return m_map[i + 1]; 167 } 168 169 return null; 170 } 171 172 179 public final String getByValue(String val) 180 { 181 182 for (int i = 1; i < m_firstFree; i += 2) 183 { 184 if (m_map[i].equals(val)) 185 return m_map[i - 1]; 186 } 187 188 return null; 189 } 190 191 198 public final String elementAt(int i) 199 { 200 return m_map[i]; 201 } 202 203 210 public final boolean contains(String key) 211 { 212 213 for (int i = 0; i < m_firstFree; i += 2) 214 { 215 if (m_map[i].equals(key)) 216 return true; 217 } 218 219 return false; 220 } 221 222 229 public final boolean containsValue(String val) 230 { 231 232 for (int i = 1; i < m_firstFree; i += 2) 233 { 234 if (m_map[i].equals(val)) 235 return true; 236 } 237 238 return false; 239 } 240 } 241 | Popular Tags |