Refine search
/** * 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); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, and splits entries * into keys and values using the specified key-value splitter. * * <p>Note: Any configuration option configured on this splitter, such as {@link #trimResults}, * does not change the behavior of the {@code keyValueSplitter}. * * <p>Example: * * <pre>{@code * String toSplit = " x -> y, z-> a "; * Splitter outerSplitter = Splitter.on(',').trimResults(); * MapSplitter mapSplitter = outerSplitter.withKeyValueSeparator(Splitter.on("->")); * Map<String, String> result = mapSplitter.split(toSplit); * assertThat(result).isEqualTo(ImmutableMap.of("x ", " y", "z", " a")); * }</pre> * * @since 10.0 */ @Beta public MapSplitter withKeyValueSeparator(Splitter keyValueSplitter) { return new MapSplitter(this, keyValueSplitter); }
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_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(); }
@Override public Map<String, String> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (jp.getValueAsString() == null) { return null; } Map<String, String> items = Splitter.on("\n").omitEmptyStrings().withKeyValueSeparator(',').split(jp.getValueAsString()); items = Maps.transformValues(items, new Function<String, String>() { @Override public String apply(String value) { return value.trim(); } }); return items; } }
public void setRequires(String value) throws ParserException { checkMutable(); switch (type) { case POLICY: Map<String,String> pr = Splitter.on(',').trimResults(). withKeyValueSeparator(Splitter.on('=').trimResults()).split(value); IGTFInfo.this.policyRequires = ImmutableMap.copyOf(pr); break; case TRUST_ANCHOR: IGTFInfo.this.trustAnchorRequires = ImmutableList.copyOf(Splitter.on(',').trimResults().split(value)); break; } }
@Bean Map<TopicPartition, Offsets> endOffsets( @Value("${road.topic}") String topic, @Value("${road.offsets}") String offsets) { return Splitter.on(';').withKeyValueSeparator(':').split(offsets).entrySet().stream().map(e -> { int partition = parseInt(e.getKey()); List<Long> o = Splitter.on(',').splitToList(e.getValue()).stream().map(Long::parseLong).collect(toList()); return new Offsets(partition, o.get(0), o.get(1)); }).collect(toMap(o -> new TopicPartition(topic, o.getPartition()), identity())); } }
public static JobDataMap fromDataMapStr(String dataMap) { if (StringUtils.isEmpty(dataMap)) return new JobDataMap(); Splitter.MapSplitter mapSplitter = Splitter.onPattern("[,\\n]") .omitEmptyStrings().trimResults().withKeyValueSeparator('='); return new JobDataMap(mapSplitter.split(dataMap)); }
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 BenchmarkQuery(File file) throws IOException { requireNonNull(file, "file is null"); name = Files.getNameWithoutExtension(file.getName()); // file can have 2 sections separated by a line of equals signs String text = Files.toString(file, StandardCharsets.UTF_8); List<String> sections = SECTION_SPLITTER.splitToList(text); if (sections.size() == 2) { this.tags = ImmutableMap.copyOf(TAGS_SPLITTER.split(sections.get(0))); this.sql = sections.get(1); } else { // no tags this.tags = ImmutableMap.of(); this.sql = sections.get(0); } }
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(); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, and splits entries * into keys and values using the specified key-value splitter. * * @since 10.0 */ @Beta public MapSplitter withKeyValueSeparator(Splitter keyValueSplitter) { return new MapSplitter(this, keyValueSplitter); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, and splits entries * into keys and values using the specified key-value splitter. * * @since 10.0 */ @Beta public MapSplitter withKeyValueSeparator(Splitter keyValueSplitter) { return new MapSplitter(this, keyValueSplitter); }
@Override public String toString() { // "tag" can either be just the tag or have the form "tag;attr1=value1;attr2=value2;[...]". int separatorIdx = tag.indexOf(';'); String actualTag = separatorIdx == -1 ? tag : tag.substring(0, separatorIdx); switch (type) { case OPEN: if (separatorIdx != -1) { StringJoiner attributes = new StringJoiner(" "); ATTRIBUTES_SPLITTER .split(tag.substring(separatorIdx + 1)) .forEach((key, value) -> attributes.add(String.format("%s=\"%s\"", key, value))); return String.format("<%s %s>", actualTag, attributes); } return String.format("<%s>", actualTag); case CLOSE: return String.format("</%s>", actualTag); } throw new IllegalStateException(); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, * and splits entries into keys and values using the specified key-value * splitter. * * @since 10.0 */ @CheckReturnValue @Beta public MapSplitter withKeyValueSeparator(Splitter keyValueSplitter) { return new MapSplitter(this, keyValueSplitter); }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, * and splits entries into keys and values using the specified key-value * splitter. * * @since 10.0 */ @CheckReturnValue @Beta public MapSplitter withKeyValueSeparator(Splitter keyValueSplitter) { return new MapSplitter(this, keyValueSplitter); }
private static void addQuery(URI uri, Map<String, String> storage) { String query = uri.getQuery(); if (query != null) { storage.putAll(QUERY_SPLITTER.split(query)); } } }
private Optional<Map<String, String>> parseParameters(@Nonnull final String parametersString) { try { return Optional.of(PARAMETERS_PARSER.split(parametersString)); } catch (IllegalArgumentException iae) { log.info("invalid syntax for parameters list: '" + parametersString + "'"); return Optional.empty(); } } }
private Optional<Map<String, String>> parseParameters(@Nonnull final String parametersString) { try { return Optional.of(PARAMETERS_PARSER.split(parametersString)); } catch (IllegalArgumentException iae) { log.info("invalid syntax for parameters list: '" + parametersString + "'"); return Optional.empty(); } } }
/** * Returns a {@code MapSplitter} which splits entries based on this splitter, * and splits entries into keys and values using the specified key-value * splitter. * * @since 10.0 */ @CheckReturnValue @Beta public MapSplitter withKeyValueSeparator(Splitter keyValueSplitter) { return new MapSplitter(this, keyValueSplitter); }