org.sonar.api.measures.Metric.getKey()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(166)

本文整理了Java中org.sonar.api.measures.Metric.getKey()方法的一些代码示例,展示了Metric.getKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metric.getKey()方法的具体详情如下:
包路径:org.sonar.api.measures.Metric
类名称:Metric
方法名:getKey

Metric.getKey介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

@Override
public boolean equals(Object obj) {
 if (!(obj instanceof Metric)) {
  return false;
 }
 if (this == obj) {
  return true;
 }
 Metric other = (Metric) obj;
 return key.equals(other.getKey());
}

代码示例来源:origin: SonarSource/sonarqube

@CheckForNull
private static String formatMeasure(Map<String, LiveMeasureDto> measuresByMetricKey, Metric metric) {
 LiveMeasureDto measure = measuresByMetricKey.get(metric.getKey());
 return formatMeasure(measure, metric);
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public Optional<Double> getLeakValue(Metric metric) {
 Optional<LiveMeasureDto> measure = matrix.getMeasure(currentComponent, metric.getKey());
 return measure.map(LiveMeasureDto::getVariation);
}

代码示例来源:origin: SonarSource/sonarqube

private Set<String> getKeysOfAllInvolvedMetrics(QualityGate gate) {
 Set<String> metricKeys = new HashSet<>();
 for (Metric metric : formulaFactory.getFormulaMetrics()) {
  metricKeys.add(metric.getKey());
 }
 metricKeys.addAll(qGateComputer.getMetricsRelatedTo(gate));
 return metricKeys;
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public void setValue(double value) {
 String metricKey = currentFormula.getMetric().getKey();
 checkState(!currentFormula.isOnLeak(), "Formula of metric %s accepts only leak values", metricKey);
 matrix.setValue(currentComponent, metricKey, value);
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public void setLeakValue(double value) {
 String metricKey = currentFormula.getMetric().getKey();
 checkState(currentFormula.isOnLeak(), "Formula of metric %s does not accept leak values", metricKey);
 matrix.setLeakValue(currentComponent, metricKey, value);
}

代码示例来源:origin: SonarSource/sonarqube

@Override
 public void setLeakValue(Rating value) {
  String metricKey = currentFormula.getMetric().getKey();
  checkState(currentFormula.isOnLeak(), "Formula of metric %s does not accept leak values", metricKey);
  matrix.setLeakValue(currentComponent, metricKey, value);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public Optional<Double> getValue(Metric metric) {
 if (!dependentMetrics.contains(metric)) {
  throw new IllegalStateException("Metric " + metric.getKey() + " is not declared as a dependency");
 }
 if (values.containsKey(metric)) {
  return Optional.of(values.get(metric));
 }
 return Optional.empty();
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public Optional<Double> getLeakValue(Metric metric) {
 if (!dependentMetrics.contains(metric)) {
  throw new IllegalStateException("Metric " + metric.getKey() + " is not declared as a dependency");
 }
 if (leakValues.containsKey(metric)) {
  return Optional.of(leakValues.get(metric));
 }
 return Optional.empty();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void get_metric_by_key() {
 Metric metric = getMetric("ncloc");
 assertThat(metric.getKey()).isEqualTo("ncloc");
}

代码示例来源:origin: SonarSource/sonarqube

private TestContext run(Metric metric, boolean expectLeakFormula) {
  IssueMetricFormula formula = underTest.getFormulas().stream()
   .filter(f -> f.getMetric().getKey().equals(metric.getKey()))
   .findFirst()
   .get();
  assertThat(formula.isOnLeak()).isEqualTo(expectLeakFormula);
  TestContext context = new TestContext(formula.getDependentMetrics(), values, leakValues);
  formula.compute(context, newIssueCounter(groups));
  return context;
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void shouldCreateMetric() {
 Metric metric = new Metric.Builder("foo", "Foo", Metric.ValueType.INT)
  .setDomain("my domain")
  .create();
 assertThat(metric.getKey()).isEqualTo("foo");
 assertThat(metric.getName()).isEqualTo("Foo");
 assertThat(metric.getDomain()).isEqualTo("my domain");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void measures_on_leak_period_are_persisted() {
 prepareProject();
 measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().setVariation(42.0).createNoValue());
 TestComputationStepContext context = execute();
 MeasureDto persistedMeasure = selectMeasure("project-uuid", INT_METRIC).get();
 assertThat(persistedMeasure.getValue()).isNull();
 assertThat(persistedMeasure.getVariation()).isEqualTo(42.0);
 assertNbOfInserts(context, 1);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void measures_without_value_are_not_persisted() {
 prepareProject();
 measureRepository.addRawMeasure(REF_1, STRING_METRIC.getKey(), newMeasureBuilder().createNoValue());
 measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().createNoValue());
 TestComputationStepContext context = execute();
 assertThatMeasureIsNotPersisted("project-uuid", STRING_METRIC);
 assertThatMeasureIsNotPersisted("project-uuid", INT_METRIC);
 assertNbOfInserts(context, 0);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void measures_on_leak_period_are_persisted() {
 prepareProject();
 measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().setVariation(42.0).createNoValue());
 TestComputationStepContext context = new TestComputationStepContext();
 step().execute(context);
 LiveMeasureDto persistedMeasure = selectMeasure("project-uuid", INT_METRIC).get();
 assertThat(persistedMeasure.getValue()).isNull();
 assertThat(persistedMeasure.getVariation()).isEqualTo(42.0);
 verifyStatistics(context, 1);
}

代码示例来源:origin: SonarSource/sonarqube

private static Metric from(int id, org.sonar.api.measures.Metric<?> coreMetric) {
 return new MetricImpl(
  id, coreMetric.getKey(), coreMetric.getName(),
  convert(coreMetric.getType()),
  coreMetric.getDecimalScale(),
  coreMetric.getBestValue(), coreMetric.isOptimizedBestValue());
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void measures_without_value_are_not_persisted() {
 prepareProject();
 measureRepository.addRawMeasure(REF_1, STRING_METRIC.getKey(), newMeasureBuilder().createNoValue());
 measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().createNoValue());
 TestComputationStepContext context = new TestComputationStepContext();
 step().execute(context);
 assertThatMeasureIsNotPersisted("project-uuid", STRING_METRIC);
 assertThatMeasureIsNotPersisted("project-uuid", INT_METRIC);
 verifyStatistics(context, 0);
}

代码示例来源:origin: SonarSource/sonarqube

@Before
public void setUp() {
 MetricDto stringMetricDto = db.measures().insertMetric(m -> m.setKey(STRING_METRIC.getKey()).setValueType(Metric.ValueType.STRING.name()));
 MetricDto intMetricDto = db.measures().insertMetric(m -> m.setKey(INT_METRIC.getKey()).setValueType(Metric.ValueType.INT.name()));
 MetricDto bestValueMMetricDto = db.measures()
  .insertMetric(m -> m.setKey(METRIC_WITH_BEST_VALUE.getKey()).setValueType(Metric.ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(0.0));
 metricRepository.add(stringMetricDto.getId(), STRING_METRIC);
 metricRepository.add(intMetricDto.getId(), INT_METRIC);
 metricRepository.add(bestValueMMetricDto.getId(), METRIC_WITH_BEST_VALUE);
}

代码示例来源:origin: SonarSource/sonarqube

@Before
public void setUp() {
 analysisMetadataHolder.setUuid(ANALYSIS_UUID);
 MetricDto stringMetricDto = db.measures().insertMetric(m -> m.setKey(STRING_METRIC.getKey()).setValueType(Metric.ValueType.STRING.name()));
 MetricDto intMetricDto = db.measures().insertMetric(m -> m.setKey(INT_METRIC.getKey()).setValueType(Metric.ValueType.INT.name()));
 metricRepository.add(stringMetricDto.getId(), STRING_METRIC);
 metricRepository.add(intMetricDto.getId(), INT_METRIC);
}

代码示例来源:origin: SonarSource/sonarqube

private LiveMeasureDto insertMeasure(String componentUuid, String projectUuid, Metric metric) {
 LiveMeasureDto measure = newLiveMeasure()
  .setComponentUuid(componentUuid)
  .setProjectUuid(projectUuid)
  .setMetricId(metricRepository.getByKey(metric.getKey()).getId());
 dbClient.liveMeasureDao().insertOrUpdate(db.getSession(), measure);
 return measure;
}

相关文章