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)
| 481 | * entries, or if there are duplicate keys |
| 482 | */ |
| 483 | public Map<String, String> split(CharSequence sequence) { |
| 484 | Map<String, String> map = new LinkedHashMap<String, String>(); |
| 485 | for (String entry : outerSplitter.split(sequence)) { |
| 486 | Iterator<String> entryFields = entrySplitter.splittingIterator(entry); |
| 487 | |
| 488 | checkArgument(entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); |
| 489 | String key = entryFields.next(); |
| 490 | checkArgument(!map.containsKey(key), "Duplicate key [%s] found.", key); |
| 491 | |
| 492 | checkArgument(entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); |
| 493 | String value = entryFields.next(); |
| 494 | map.put(key, value); |
| 495 | |
| 496 | checkArgument(!entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); |
| 497 | } |
| 498 | return Collections.unmodifiableMap(map); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | private interface Strategy { |
nothing calls this directly
no test coverage detected