Get back a Map of String String from its String representation. Unescape backslashed separator characters. @param string String to convert to a Map @return a Map @see #toString(java.util.Map)
(String string)
| 288 | * @see #toString(java.util.Map) |
| 289 | */ |
| 290 | public static Map<String, String> toMap(String string) { |
| 291 | Map<String, String> map = new HashMap<String, String>(); |
| 292 | if (string == null |
| 293 | || string.length() < 3) { |
| 294 | return map; |
| 295 | } |
| 296 | Set<String> firstList = toSet(string, ", "); |
| 297 | for (String element : firstList) { |
| 298 | LinkedHashSet<String> secondList = toSet("[" + element + "]", "="); |
| 299 | if (secondList.size() == 2) { |
| 300 | Iterator<String> iterator = secondList.iterator(); |
| 301 | map.put(iterator.next(), iterator.next()); |
| 302 | } else { |
| 303 | Err.prln("Ignoring element: [" + element + "]"); |
| 304 | Err.prln("Expecting: [key=value]"); |
| 305 | } |
| 306 | } |
| 307 | return map; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Crop the text in the middle if too long. |