(String uncompressedStr, int bitsPerChar, CompressFunctionWrapper getCharFromInt)
| 132 | } |
| 133 | |
| 134 | private static String _compress(String uncompressedStr, int bitsPerChar, CompressFunctionWrapper getCharFromInt) { |
| 135 | if (uncompressedStr == null) return ""; |
| 136 | int i, value; |
| 137 | Map<String, Integer> context_dictionary = new HashMap<String, Integer>(); |
| 138 | Set<String> context_dictionaryToCreate = new HashSet<String>(); |
| 139 | String context_c = ""; |
| 140 | String context_wc = ""; |
| 141 | String context_w = ""; |
| 142 | int context_enlargeIn = 2; // Compensate for the first entry which should not count |
| 143 | int context_dictSize = 3; |
| 144 | int context_numBits = 2; |
| 145 | StringBuilder context_data = new StringBuilder(uncompressedStr.length() / 3); |
| 146 | int context_data_val = 0; |
| 147 | int context_data_position = 0; |
| 148 | int ii; |
| 149 | |
| 150 | for (ii = 0; ii < uncompressedStr.length(); ii += 1) { |
| 151 | context_c = String.valueOf(uncompressedStr.charAt(ii)); |
| 152 | if (!context_dictionary.containsKey(context_c)) { |
| 153 | context_dictionary.put(context_c, context_dictSize++); |
| 154 | context_dictionaryToCreate.add(context_c); |
| 155 | } |
| 156 | |
| 157 | context_wc = context_w + context_c; |
| 158 | if (context_dictionary.containsKey(context_wc)) { |
| 159 | context_w = context_wc; |
| 160 | } else { |
| 161 | if (context_dictionaryToCreate.contains(context_w)) { |
| 162 | if (context_w.charAt(0) < 256) { |
| 163 | for (i = 0; i < context_numBits; i++) { |
| 164 | context_data_val = (context_data_val << 1); |
| 165 | if (context_data_position == bitsPerChar - 1) { |
| 166 | context_data_position = 0; |
| 167 | context_data.append(getCharFromInt.doFunc(context_data_val)); |
| 168 | context_data_val = 0; |
| 169 | } else { |
| 170 | context_data_position++; |
| 171 | } |
| 172 | } |
| 173 | value = context_w.charAt(0); |
| 174 | for (i = 0; i < 8; i++) { |
| 175 | context_data_val = (context_data_val << 1) | (value & 1); |
| 176 | if (context_data_position == bitsPerChar - 1) { |
| 177 | context_data_position = 0; |
| 178 | context_data.append(getCharFromInt.doFunc(context_data_val)); |
| 179 | context_data_val = 0; |
| 180 | } else { |
| 181 | context_data_position++; |
| 182 | } |
| 183 | value = value >> 1; |
| 184 | } |
| 185 | } else { |
| 186 | value = 1; |
| 187 | for (i = 0; i < context_numBits; i++) { |
| 188 | context_data_val = (context_data_val << 1) | value; |
| 189 | if (context_data_position == bitsPerChar - 1) { |
| 190 | context_data_position = 0; |
| 191 | context_data.append(getCharFromInt.doFunc(context_data_val)); |
no test coverage detected