public QProfileChangeDto setData(@Nullable Map m) { if (m == null || m.isEmpty()) { this.data = null; } else { this.data = KeyValueFormat.format(m); } return this; }
/** * Used to build a measure from the current object * * @return the built measure */ @CheckForNull public String build() { if (isValid) { return KeyValueFormat.format(toMap()); } return null; }
/** * @since 2.7 */ public static String formatStringInt(Map<String, Integer> map) { return format(map, newStringConverter(), newIntegerConverter()); }
/** * @since 2.7 */ public static String formatIntString(Map<Integer, String> map) { return format(map, newIntegerConverter(), newStringConverter()); }
/** * @since 2.7 */ public static String formatIntDate(Map<Integer, Date> map) { return format(map, newIntegerConverter(), newDateConverter()); }
/** * @since 2.7 */ public static String format(Map map) { return format(map, newToStringConverter(), newToStringConverter()); }
/** * @since 2.7 */ public static String formatIntDouble(Map<Integer, Double> map) { return format(map, newIntegerConverter(), newDoubleConverter()); }
/** * @since 2.7 */ public static String formatIntDateTime(Map<Integer, Date> map) { return format(map, newIntegerConverter(), newDateTimeConverter()); }
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; }
@Test public void keep_order_of_linked_map() { Map<String, String> map = new LinkedHashMap<>(); map.put("lucky", "luke"); map.put("aste", "rix"); String s = KeyValueFormat.format(map); assertThat(s).isEqualTo("lucky=luke;aste=rix"); }
@Test public void escape_strings() { Map<String, String> input = new LinkedHashMap<>(); input.put("foo", "a=b=c"); input.put("bar", "a;b;c"); input.put("baz", "double\"quote"); String csv = KeyValueFormat.format(input); assertThat(csv).isEqualTo("foo=\"a=b=c\";bar=\"a;b;c\";baz=double\"quote"); Map<String, String> output = KeyValueFormat.parse(csv); assertThat(output.get("foo")).isEqualTo("a=b=c"); assertThat(output.get("bar")).isEqualTo("a;b;c"); assertThat(output.get("baz")).isEqualTo("double\"quote"); }
@Override public Optional<Measure> createMeasure(LanguageDistributionCounter counter, CreateMeasureContext context) { if (counter.multiset.isEmpty()) { return Optional.empty(); } return Optional.of(newMeasureBuilder().create(format(asMap(counter.multiset.elementSet(), new LanguageToTotalCount(counter.multiset))))); }
@Override public void save() { for (Map.Entry<String, Map<Integer, Object>> entry : map.entrySet()) { String metricKey = entry.getKey(); Map<Integer, Object> lines = entry.getValue(); if (shouldSave(lines)) { String data = KeyValueFormat.format(optimizeStorage(metricKey, lines)); new DefaultMeasure<String>(sensorStorage) .on(inputFile) .forMetric(metricFinder.findByKey(metricKey)) .withValue(data) .save(); entry.setValue(ImmutableMap.copyOf(lines)); } } }
private static boolean handle(Select.Row row, SqlStatement update) throws SQLException { int id = row.getInt(1); String data = row.getString(2); Map<String, String> fields = KeyValueFormat.parse(data); String profileKey = fields.remove("profileKey"); if (isBlank(profileKey)) { return false; } update.setString(1, profileKey); update.setString(2, KeyValueFormat.format(fields)); update.setInt(3, id); return true; } }
private static Measure createNclocDataMeasure(Integer... nclocLines) { Set<Integer> nclocLinesSet = ImmutableSet.copyOf(nclocLines); int max = Ordering.<Integer>natural().max(nclocLinesSet); ImmutableMap.Builder<Integer, Integer> builder = ImmutableMap.builder(); for (int i = 1; i <= max; i++) { builder.put(i, nclocLinesSet.contains(i) ? 1 : 0); } return newMeasureBuilder().create(KeyValueFormat.format(builder.build(), KeyValueFormat.newIntegerConverter(), KeyValueFormat.newIntegerConverter())); }
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())); }
@Test public void shouldValidateMaxLine() throws Exception { InputFile file = new TestInputFileBuilder("module", "testfile").setModuleBaseDir(temp.newFolder().toPath()).build(); Map<Integer, Integer> map = ImmutableMap.of(11, 3); String data = KeyValueFormat.format(map); thrown.expect(IllegalStateException.class); underTest.validateCoverageMeasure(data, file); }
private void markAsChanged(Component component, QualityProfile baseProfile, QualityProfile profile) { Date from = baseProfile.getRulesUpdatedAt(); String data = KeyValueFormat.format(ImmutableSortedMap.of( "key", profile.getQpKey(), "from", UtcDateUtils.formatDateTime(fixDate(from)), "to", UtcDateUtils.formatDateTime(fixDate(profile.getRulesUpdatedAt())))); eventRepository.add(component, createQProfileEvent(profile, "Changes in %s", data)); }
@Test public void shouldValidateStrictlyPositiveLine() throws Exception { InputFile file = new TestInputFileBuilder("module", "testfile").setModuleBaseDir(temp.newFolder().toPath()).build(); Map<Integer, Integer> map = ImmutableMap.of(0, 3); String data = KeyValueFormat.format(map); thrown.expect(IllegalStateException.class); thrown.expectMessage("must be > 0"); underTest.validateCoverageMeasure(data, file); }
@Override public void store(DefaultCoverage defaultCoverage) { DefaultInputFile inputFile = (DefaultInputFile) defaultCoverage.inputFile(); inputFile.setPublished(true); if (defaultCoverage.linesToCover() > 0) { saveCoverageMetricInternal(inputFile, LINES_TO_COVER, new DefaultMeasure<Integer>().forMetric(LINES_TO_COVER).withValue(defaultCoverage.linesToCover())); saveCoverageMetricInternal(inputFile, UNCOVERED_LINES, new DefaultMeasure<Integer>().forMetric(UNCOVERED_LINES).withValue(defaultCoverage.linesToCover() - defaultCoverage.coveredLines())); saveCoverageMetricInternal(inputFile, COVERAGE_LINE_HITS_DATA, new DefaultMeasure<String>().forMetric(COVERAGE_LINE_HITS_DATA).withValue(KeyValueFormat.format(defaultCoverage.hitsByLine()))); } if (defaultCoverage.conditions() > 0) { saveCoverageMetricInternal(inputFile, CONDITIONS_TO_COVER, new DefaultMeasure<Integer>().forMetric(CONDITIONS_TO_COVER).withValue(defaultCoverage.conditions())); saveCoverageMetricInternal(inputFile, UNCOVERED_CONDITIONS, new DefaultMeasure<Integer>().forMetric(UNCOVERED_CONDITIONS).withValue(defaultCoverage.conditions() - defaultCoverage.coveredConditions())); saveCoverageMetricInternal(inputFile, COVERED_CONDITIONS_BY_LINE, new DefaultMeasure<String>().forMetric(COVERED_CONDITIONS_BY_LINE).withValue(KeyValueFormat.format(defaultCoverage.coveredConditionsByLine()))); saveCoverageMetricInternal(inputFile, CONDITIONS_BY_LINE, new DefaultMeasure<String>().forMetric(CONDITIONS_BY_LINE).withValue(KeyValueFormat.format(defaultCoverage.conditionsByLine()))); } }