/** * Returns a {@code MapSplitter} which splits entries based on this splitter, and splits entries * into keys and values using the specified separator. * * @since 10.0 */ @Beta public MapSplitter withKeyValueSeparator(String separator) { return withKeyValueSeparator(on(separator)); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, and splits entries * into keys and values using the specified separator. * * @since 14.0 */ @Beta public MapSplitter withKeyValueSeparator(char separator) { return withKeyValueSeparator(on(separator)); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, and splits entries * into keys and values using the specified separator. * * @since 10.0 */ @Beta public MapSplitter withKeyValueSeparator(String separator) { return withKeyValueSeparator(on(separator)); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, and splits entries * into keys and values using the specified separator. * * @since 14.0 */ @Beta public MapSplitter withKeyValueSeparator(char separator) { return withKeyValueSeparator(on(separator)); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, and splits entries * into keys and values using the specified separator. * * @since 10.0 */ @Beta public MapSplitter withKeyValueSeparator(String separator) { return withKeyValueSeparator(on(separator)); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, and splits entries * into keys and values using the specified separator. * * @since 14.0 */ @Beta public MapSplitter withKeyValueSeparator(char separator) { return withKeyValueSeparator(on(separator)); }
/** * Gets the value with a given key from a static key/value mapping in string format. E.g. with * mapping "id1=user1;id2=user2", it returns "user1" with key "id1". It returns null if the given * key does not exist in the mapping. * * @param mapping the "key=value" mapping in string format separated by ";" * @param key the key to query * @return the mapped value if the key exists, otherwise returns "" */ public static String getValueFromStaticMapping(String mapping, String key) { Map<String, String> m = Splitter.on(";") .omitEmptyStrings() .trimResults() .withKeyValueSeparator("=") .split(mapping); return m.get(key); }
public void testMapSplitter_emptySeparator() { try { COMMA_SPLITTER.withKeyValueSeparator(""); fail(); } catch (IllegalArgumentException expected) { } }
/** * Parses the input string and returns the fingerprint object. * * @param input the string to parse * @return the parsed fingerprint object, or null if parsing failed */ public static Fingerprint parse(String input) { if (input == null) { return null; } if (Constants.INVALID_UFS_FINGERPRINT.equals(input)) { return new Fingerprint(Collections.emptyMap()); } Map<String, String> kv = Splitter.on(TAGDELIMTER).trimResults().omitEmptyStrings() .withKeyValueSeparator(KVDELIMTER).split(input); Map<Tag, String> tagMap = new HashMap<>(); for (Map.Entry<String, String> entry : kv.entrySet()) { tagMap.put(Tag.valueOf(entry.getKey()), entry.getValue()); } // Verify required tags for (Tag tag : REQUIRED_TAGS) { if (!tagMap.containsKey(tag)) { return null; } } return new Fingerprint(tagMap); }
public void testMapSplitter_trimmedBoth() { Map<String, String> m = COMMA_SPLITTER .trimResults() .withKeyValueSeparator(Splitter.on(':').trimResults()) .split("boy : tom , girl: tina , cat : kitty , dog: tommy "); ImmutableMap<String, String> expected = ImmutableMap.of("boy", "tom", "girl", "tina", "cat", "kitty", "dog", "tommy"); assertThat(m).isEqualTo(expected); assertThat(m.entrySet()).containsExactlyElementsIn(expected.entrySet()).inOrder(); }
public void testMapSplitter_trimmedKeyValue() { Map<String, String> m = COMMA_SPLITTER .withKeyValueSeparator(Splitter.on(':').trimResults()) .split("boy : tom , girl: tina , cat : kitty , dog: tommy "); ImmutableMap<String, String> expected = ImmutableMap.of("boy", "tom", "girl", "tina", "cat", "kitty", "dog", "tommy"); assertThat(m).isEqualTo(expected); assertThat(m.entrySet()).containsExactlyElementsIn(expected.entrySet()).inOrder(); }
public void testMapSplitter_varyingTrimLevels() { MapSplitter splitter = COMMA_SPLITTER.trimResults().withKeyValueSeparator(Splitter.on("->")); Map<String, String> split = splitter.split(" x -> y, z-> a "); assertThat(split).containsEntry("x ", " y"); assertThat(split).containsEntry("z", " a"); } }
public void testMapSplitter_CharacterSeparator() { // try different delimiters. Map<String, String> m = Splitter.on(",").withKeyValueSeparator(':').split("boy:tom,girl:tina,cat:kitty,dog:tommy"); ImmutableMap<String, String> expected = ImmutableMap.of("boy", "tom", "girl", "tina", "cat", "kitty", "dog", "tommy"); assertThat(m).isEqualTo(expected); assertThat(m.entrySet()).containsExactlyElementsIn(expected.entrySet()).inOrder(); }
public void testMapSplitter_trimmedEntries() { Map<String, String> m = COMMA_SPLITTER .trimResults() .withKeyValueSeparator(":") .split("boy : tom , girl: tina , cat : kitty , dog: tommy "); ImmutableMap<String, String> expected = ImmutableMap.of("boy ", " tom", "girl", " tina", "cat ", " kitty", "dog", " tommy"); assertThat(m).isEqualTo(expected); assertThat(m.entrySet()).containsExactlyElementsIn(expected.entrySet()).inOrder(); }
public void testMapSplitter_multiCharacterSeparator() { // try different delimiters. Map<String, String> m = Splitter.on(",") .withKeyValueSeparator(":^&") .split("boy:^&tom,girl:^&tina,cat:^&kitty,dog:^&tommy"); ImmutableMap<String, String> expected = ImmutableMap.of("boy", "tom", "girl", "tina", "cat", "kitty", "dog", "tommy"); assertThat(m).isEqualTo(expected); assertThat(m.entrySet()).containsExactlyElementsIn(expected.entrySet()).inOrder(); }
public void testMapSplitter_notTrimmed() { Map<String, String> m = COMMA_SPLITTER .withKeyValueSeparator(":") .split(" boy:tom , girl: tina , cat :kitty , dog: tommy "); ImmutableMap<String, String> expected = ImmutableMap.of(" boy", "tom ", " girl", " tina ", " cat ", "kitty ", " dog", " tommy "); assertThat(m).isEqualTo(expected); assertThat(m.entrySet()).containsExactlyElementsIn(expected.entrySet()).inOrder(); }
public void testMapSplitter_orderedResults() { Map<String, String> m = COMMA_SPLITTER.withKeyValueSeparator(":").split("boy:tom,girl:tina,cat:kitty,dog:tommy"); assertThat(m.keySet()).containsExactly("boy", "girl", "cat", "dog").inOrder(); assertThat(m) .isEqualTo(ImmutableMap.of("boy", "tom", "girl", "tina", "cat", "kitty", "dog", "tommy")); // try in a different order m = COMMA_SPLITTER.withKeyValueSeparator(":").split("girl:tina,boy:tom,dog:tommy,cat:kitty"); assertThat(m.keySet()).containsExactly("girl", "boy", "dog", "cat").inOrder(); assertThat(m) .isEqualTo(ImmutableMap.of("boy", "tom", "girl", "tina", "cat", "kitty", "dog", "tommy")); }
public void testMapSplitter_malformedEntry() { try { COMMA_SPLITTER.withKeyValueSeparator("=").split("a=1,b,c=2"); fail(); } catch (IllegalArgumentException expected) { } }
public void testMapSplitter_duplicateKeys() { try { COMMA_SPLITTER.withKeyValueSeparator(":").split("a:1,b:2,a:3"); fail(); } catch (IllegalArgumentException expected) { } }
Map<String, String> debugOptions = Splitter.on(';').omitEmptyStrings().trimResults().withKeyValueSeparator('=') .split(request.get(DEBUG_OPTIONS).asText()); LOGGER.debug("Debug options are set to: {} for request {}: {}", debugOptions, requestId, query);