/** * @since 2.7 */ public static String formatStringInt(Map<String, Integer> map) { return format(map, newStringConverter(), newIntegerConverter()); }
/** * @since 2.7 */ public static Map<Integer, String> parseIntString(@Nullable String data) { return parse(data, newIntegerConverter(), newStringConverter()); }
/** * Merge the two line coverage data measures. For lines hits use the sum, and for conditions * keep max value in case they both contains a value for the same line. */ static String mergeCoverageLineMetric(Metric<?> metric, String value1, String value2) { Map<Integer, Integer> data1 = KeyValueFormat.parseIntInt(value1); Map<Integer, Integer> data2 = KeyValueFormat.parseIntInt(value2); if (metric.key().equals(COVERAGE_LINE_HITS_DATA_KEY)) { return KeyValueFormat.format(Stream.of(data1, data2) .map(Map::entrySet) .flatMap(Collection::stream) .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, Integer::sum, TreeMap::new))); } else { return KeyValueFormat.format(Stream.of(data1, data2) .map(Map::entrySet) .flatMap(Collection::stream) .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, Integer::max, TreeMap::new))); } }
/** * @since 2.7 */ public static String formatIntDate(Map<Integer, Date> map) { return format(map, newIntegerConverter(), newDateConverter()); }
/** * @since 2.7 */ public static String formatIntDouble(Map<Integer, Double> map) { return format(map, newIntegerConverter(), newDoubleConverter()); }
/** * @since 2.7 */ public static Map<Integer, Integer> parseIntInt(@Nullable String data) { return parse(data, newIntegerConverter(), newIntegerConverter()); }
public QProfileChangeDto setData(@Nullable Map m) { if (m == null || m.isEmpty()) { this.data = null; } else { this.data = KeyValueFormat.format(m); } return this; }
private static boolean handle(Select.Row row, SqlStatement update, Map<String, Integer> ruleKeysById) throws SQLException { String key = row.getString(1); String data = row.getString(2); Map<String, String> map = KeyValueFormat.parse(data); String ruleKey = map.get(RULE_KEY_DATA_FIELD); if (ruleKey == null) { return false; } Integer ruleId = ruleKeysById.get(ruleKey); if (ruleId != null) { map.put(RULE_ID_DATA_FIELD, String.valueOf(ruleId)); } map.remove(RULE_KEY_DATA_FIELD); update.setString(1, KeyValueFormat.format(map)); update.setString(2, key); return true; }
/** * @since 2.7 */ public static Map<Integer, Date> parseIntDate(@Nullable String data) { return parse(data, newIntegerConverter(), newDateConverter()); }
/** * @since 2.7 */ public static String formatIntDateTime(Map<Integer, Date> map) { return format(map, newIntegerConverter(), newDateTimeConverter()); }
/** * @since 2.7 */ public static Map<String, Double> parseStringDouble(@Nullable String data) { return parse(data, newStringConverter(), newDoubleConverter()); }
public Map<String, String> getDataAsMap() { if (data == null) { return Collections.emptyMap(); } return KeyValueFormat.parse(data); }
public static Map<String, String> parse(@Nullable String data) { return parse(data, newStringConverter(), newStringConverter()); }
/** * @since 2.7 */ public static Map<Integer, Date> parseIntDateTime(@Nullable String data) { return parse(data, newIntegerConverter(), newDateTimeConverter()); }
/** * @since 2.7 */ public static Map<Integer, Double> parseIntDouble(@Nullable String data) { return parse(data, newIntegerConverter(), newDoubleConverter()); }
private static Measure createNoNclocDataMeasure(int lineCount) { ImmutableMap.Builder<Integer, Integer> builder = ImmutableMap.builder(); for (int i = 1; i <= lineCount; i++) { builder.put(i, 0); } return newMeasureBuilder().create(KeyValueFormat.format(builder.build(), KeyValueFormat.newIntegerConverter(), KeyValueFormat.newIntegerConverter())); }
private void processMeasure(FileLinesContext context, File measureFile, int lineNumber, String line) { try { String metricKey = StringUtils.substringBefore(line, ":"); String value = line.substring(metricKey.length() + 1); saveMeasure(context, metricKey, KeyValueFormat.parseIntInt(value)); } catch (Exception e) { LOG.error("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e); throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e); } }
/** * @since 2.7 */ public static String format(Map map) { return format(map, newToStringConverter(), newToStringConverter()); }
/** * Adds an existing Distribution to the current one. * It will create the entries if they don't exist. * Can be used to add the values of children resources for example * <br> * The returned distribution will be invalidated in case the given value does not use the same bottom limits * * @param data the data to add to the current one */ public RangeDistributionBuilder add(String data) { Map<Double, Double> map = KeyValueFormat.parse(data, KeyValueFormat.newDoubleConverter(), KeyValueFormat.newDoubleConverter()); if (bottomLimits == null) { Number[] limits = map.keySet().toArray(new Number[map.size()]); init(limits); } else if (!areSameLimits(bottomLimits, map.keySet())) { isValid = false; } if (isValid) { for (Map.Entry<Double, Double> entry : map.entrySet()) { addLimitCount(entry.getKey(), entry.getValue().intValue()); } } return this; }
@Test public void helper_parse_methods() { assertThat(KeyValueFormat.parseIntDate("1=2014-01-15")).hasSize(1); assertThat(KeyValueFormat.parseIntDateTime("1=2014-01-15T15:50:45+0100")).hasSize(1); assertThat(KeyValueFormat.parseIntDouble("1=3.14")).hasSize(1); assertThat(KeyValueFormat.parseIntInt("1=10")).containsOnly(entry(1, 10)); assertThat(KeyValueFormat.parseIntString("1=one")).containsOnly(entry(1, "one")); assertThat(KeyValueFormat.parseIntString("1=\"escaped\"")).containsOnly(entry(1, "escaped")); assertThat(KeyValueFormat.parseStringInt("one=1")).containsOnly(entry("one", 1)); assertThat(KeyValueFormat.parseStringDouble("pi=3.14")).containsOnly(entry("pi", 3.14)); }