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