1 16 19 package com.sun.org.apache.xml.internal.serializer.utils; 20 21 33 public final class StringToIntTable 34 { 35 36 public static final int INVALID_KEY = -10000; 37 38 39 private int m_blocksize; 40 41 43 private String m_map[]; 44 45 47 private int m_values[]; 48 49 50 private int m_firstFree = 0; 51 52 53 private int m_mapSize; 54 55 59 public StringToIntTable() 60 { 61 62 m_blocksize = 8; 63 m_mapSize = m_blocksize; 64 m_map = new String [m_blocksize]; 65 m_values = new int[m_blocksize]; 66 } 67 68 73 public StringToIntTable(int blocksize) 74 { 75 76 m_blocksize = blocksize; 77 m_mapSize = blocksize; 78 m_map = new String [blocksize]; 79 m_values = new int[m_blocksize]; 80 } 81 82 87 public final int getLength() 88 { 89 return m_firstFree; 90 } 91 92 98 public final void put(String key, int value) 99 { 100 101 if ((m_firstFree + 1) >= m_mapSize) 102 { 103 m_mapSize += m_blocksize; 104 105 String newMap[] = new String [m_mapSize]; 106 107 System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); 108 109 m_map = newMap; 110 111 int newValues[] = new int[m_mapSize]; 112 113 System.arraycopy(m_values, 0, newValues, 0, m_firstFree + 1); 114 115 m_values = newValues; 116 } 117 118 m_map[m_firstFree] = key; 119 m_values[m_firstFree] = value; 120 121 m_firstFree++; 122 } 123 124 132 public final int get(String key) 133 { 134 135 for (int i = 0; i < m_firstFree; i++) 136 { 137 if (m_map[i].equals(key)) 138 return m_values[i]; 139 } 140 141 return INVALID_KEY; 142 } 143 144 151 public final int getIgnoreCase(String key) 152 { 153 154 if (null == key) 155 return INVALID_KEY; 156 157 for (int i = 0; i < m_firstFree; i++) 158 { 159 if (m_map[i].equalsIgnoreCase(key)) 160 return m_values[i]; 161 } 162 163 return INVALID_KEY; 164 } 165 166 173 public final boolean contains(String key) 174 { 175 176 for (int i = 0; i < m_firstFree; i++) 177 { 178 if (m_map[i].equals(key)) 179 return true; 180 } 181 182 return false; 183 } 184 185 190 public final String [] keys() 191 { 192 String [] keysArr = new String [m_firstFree]; 193 194 for (int i = 0; i < m_firstFree; i++) 195 { 196 keysArr[i] = m_map[i]; 197 } 198 199 return keysArr; 200 } 201 } 202 | Popular Tags |