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); } }
/** * 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); }
/** * 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 static Deserializer<CountersMap, String> deserializer() { return (String value) -> { final Map<String, String> split = Splitter.on("\n").withKeyValueSeparator(SPERATOR).split(value); final Map<String, Long> collect = split .entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> new Long(entry.getValue()))); return Optional.of(new CountersMap(collect)); }; }
@Inject GoGridDefaultLocationSupplier(@Memoized Supplier<Set<? extends Location>> locations, @Named(TEMPLATE) String template) { this.locations = locations; Map<String, String> map = Splitter.on(',').trimResults().withKeyValueSeparator("=").split(template); //TODO: move to real ImplicitLocationSupplier this.defaultDC = checkNotNull(map.get("locationId"), "locationId not in % value: %s", TEMPLATE, template); }
/** * Builds the map from string. * * @param input the input * @param splitOn the split on * @param keyValueSeparator the key value separator * @return the map */ public static Map<String, String> buildMapFromString(String input, String splitOn, String keyValueSeparator) { return Splitter.on(splitOn).omitEmptyStrings().trimResults().withKeyValueSeparator(keyValueSeparator) .split(input); }
/** * */ public AutoFixManager() { targetTypeAlias = new HashMap<>(); String alias = CommonUtils.getPropValue(PacmanSdkConstants.TARGET_TYPE_ALIAS); if(!Strings.isNullOrEmpty(alias)) { targetTypeAlias = Splitter.on(",").withKeyValueSeparator("=").split(alias); } }
@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(); }
public static Map<String, String> getColumnMappingMap(String columnMappings) { if (LOG.isDebugEnabled()) { LOG.debug("Column mappings : " + columnMappings); } if (columnMappings == null || columnMappings.length() == 0) { if (LOG.isInfoEnabled()) { LOG.info("phoenix.column.mapping not set. using field definition"); } return Collections.emptyMap(); } Map<String, String> columnMappingMap = Splitter.on(PhoenixStorageHandlerConstants.COMMA) .trimResults().withKeyValueSeparator(PhoenixStorageHandlerConstants.COLON).split (columnMappings); if (LOG.isDebugEnabled()) { LOG.debug("Column mapping map : " + columnMappingMap); } return columnMappingMap; }
.split(request.get(DEBUG_OPTIONS).asText()); LOGGER.debug("Debug options are set to: {} for request {}: {}", debugOptions, requestId, query); brokerRequest.setDebugOptions(debugOptions);
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_duplicateKeys() { try { COMMA_SPLITTER.withKeyValueSeparator(":").split("a:1,b:2,a:3"); fail(); } catch (IllegalArgumentException expected) { } }
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_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_malformedEntry() { try { COMMA_SPLITTER.withKeyValueSeparator("=").split("a=1,b,c=2"); fail(); } catch (IllegalArgumentException expected) { } }
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_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_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_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_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")); }