Splits {@code sequence} into substrings, splits each substring into an entry, and returns an unmodifiable map with each of the entries. For example, {@code Splitter.on(';').trimResults().withKeyValueSeparator("=>").split("a=>b ; c=>b")} will return a mapping from {@code "a"} to {@code "b"} and {@cod
(CharSequence sequence)
| 494 | * entries, or if there are duplicate keys |
| 495 | */ |
| 496 | public Map<String, String> split(CharSequence sequence) { |
| 497 | Map<String, String> map = new LinkedHashMap<>(); |
| 498 | for (String entry : outerSplitter.split(sequence)) { |
| 499 | Iterator<String> entryFields = entrySplitter.splittingIterator(entry); |
| 500 | |
| 501 | checkArgument(entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); |
| 502 | String key = entryFields.next(); |
| 503 | checkArgument(!map.containsKey(key), "Duplicate key [%s] found.", key); |
| 504 | |
| 505 | checkArgument(entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); |
| 506 | String value = entryFields.next(); |
| 507 | map.put(key, value); |
| 508 | |
| 509 | checkArgument(!entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); |
| 510 | } |
| 511 | return Collections.unmodifiableMap(map); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | private interface Strategy { |