本文整理了Java中org.sonar.api.measures.Metric.getType()
方法的一些代码示例,展示了Metric.getType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metric.getType()
方法的具体详情如下:
包路径:org.sonar.api.measures.Metric
类名称:Metric
方法名:getType
暂无
代码示例来源:origin: SonarSource/sonarqube
@Override
public Class<G> valueType() {
return getType().valueType();
}
}
代码示例来源:origin: SonarSource/sonarqube
public DefaultMetricFinder(MetricsRepository metricsRepository) {
Map<String, Metric<Serializable>> metrics = new LinkedHashMap<>();
for (org.sonar.api.measures.Metric metric : metricsRepository.metrics()) {
metrics.put(metric.key(), new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), metric.getType()).create());
}
metricsByKey = Collections.unmodifiableMap(metrics);
}
代码示例来源: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
@Override
@Nonnull
public MetricDto apply(@Nonnull Metric metric) {
MetricDto dto = new MetricDto();
dto.setId(metric.getId());
dto.setKey(metric.getKey());
dto.setDescription(metric.getDescription());
dto.setShortName(metric.getName());
dto.setBestValue(metric.getBestValue());
dto.setDomain(metric.getDomain());
dto.setEnabled(metric.getEnabled());
dto.setDirection(metric.getDirection());
dto.setHidden(metric.isHidden());
dto.setQualitative(metric.getQualitative());
dto.setValueType(metric.getType().name());
dto.setOptimizedBestValue(metric.isOptimizedBestValue());
dto.setUserManaged(metric.getUserManaged());
dto.setWorstValue(metric.getWorstValue());
dto.setDeleteHistoricalData(metric.getDeleteHistoricalData());
dto.setDecimalScale(metric.getDecimalScale());
return dto;
}
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-plugin-api
@Override
public Class<G> valueType() {
return getType().valueType();
}
}
代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api
@Override
public Class<G> valueType() {
return getType().valueType();
}
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private static boolean isADouble(Metric metric) {
return metric.getType() == Metric.ValueType.FLOAT ||
metric.getType() == Metric.ValueType.PERCENT ||
metric.getType() == Metric.ValueType.RATING;
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private static boolean isAString(Metric metric) {
return metric.getType() == Metric.ValueType.STRING ||
metric.getType() == Metric.ValueType.LEVEL;
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private static boolean isAInteger(Metric metric) {
return metric.getType() == Metric.ValueType.INT ||
metric.getType() == Metric.ValueType.MILLISEC;
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private static boolean isAWorkDuration(Metric metric) {
return metric.getType() == Metric.ValueType.WORK_DUR;
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private static boolean isABoolean(Metric metric) {
return metric.getType() == Metric.ValueType.BOOL;
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private static Comparable getMeasureValueForStringOrBoolean(Metric metric, Measure measure) {
if (isAString(metric)) {
return measure.getData();
}
if (isABoolean(metric)) {
return measure.getValue().intValue();
}
throw new NotImplementedException(metric.getType().toString());
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-scanner-engine
public DefaultMetricFinder(MetricsRepository metricsRepository) {
Map<String, Metric<Serializable>> metrics = new LinkedHashMap<>();
for (org.sonar.api.measures.Metric metric : metricsRepository.metrics()) {
metrics.put(metric.key(), new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), metric.getType()).create());
}
metricsByKey = Collections.unmodifiableMap(metrics);
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch
private void setValueAccordingToMetricType(Measure<?> measure, org.sonar.api.measures.Metric<?> m, org.sonar.api.measures.Measure measureToSave) {
switch (m.getType()) {
case BOOL:
measureToSave.setValue(Boolean.TRUE.equals(measure.value()) ? 1.0 : 0.0);
break;
case INT:
case MILLISEC:
case WORK_DUR:
case FLOAT:
case PERCENT:
case RATING:
measureToSave.setValue(((Number) measure.value()).doubleValue());
break;
case STRING:
case LEVEL:
case DATA:
case DISTRIB:
measureToSave.setData((String) measure.value());
break;
default:
throw new UnsupportedOperationException("Unsupported type :" + m.getType());
}
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private static Comparable getValueForComparison(Metric metric, String value) {
Comparable valueToCompare = null;
try {
if (isADouble(metric)) {
valueToCompare = Double.parseDouble(value);
} else if (isAInteger(metric)) {
valueToCompare = parseInteger(value);
} else if (isAString(metric)) {
valueToCompare = value;
} else if (isABoolean(metric)) {
valueToCompare = Integer.parseInt(value);
} else if (isAWorkDuration(metric)) {
valueToCompare = Long.parseLong(value);
} else {
throw new NotImplementedException(metric.getType().toString());
}
} catch (NumberFormatException badValueFormat) {
throw new IllegalArgumentException(String.format("Quality Gate: Unable to parse value '%s' to compare against %s", value, metric.getName()));
}
return valueToCompare;
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private String alertValue(ResolvedCondition condition, Metric.Level level) {
String value = level.equals(Metric.Level.ERROR) ? condition.errorThreshold() : condition.warningThreshold();
if (condition.metric().getType().equals(Metric.ValueType.WORK_DUR)) {
return formatDuration(value);
} else {
return value;
}
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
private static Comparable getMeasureValue(ResolvedCondition condition, Measure measure) {
Metric metric = condition.metric();
if (isADouble(metric)) {
return getValue(condition, measure);
}
if (isAInteger(metric)) {
return parseInteger(condition, measure);
}
if (isAWorkDuration(metric)) {
return parseLong(condition, measure);
}
if (condition.period() == null) {
return getMeasureValueForStringOrBoolean(metric, measure);
}
throw new NotImplementedException(metric.getType().toString());
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch
private BatchReport.Measure toReportMeasure(BatchReport.Measure.Builder builder, Measure measure) {
builder.clear();
builder.setValueType(getMeasureValueType(measure.getMetric().getType()));
setValueAccordingToType(builder, measure);
// Because some numeric measures also have a data (like Sqale rating)
String data = measure.getData();
if (data != null) {
builder.setStringValue(data);
}
builder.setMetricKey(measure.getMetricKey());
return builder.build();
}
代码示例来源:origin: org.codehaus.sonar/sonar-batch
public FakeGlobalRepositoriesLoader add(Metric metric) {
Boolean optimizedBestValue = metric.isOptimizedBestValue();
ref.metrics().add(new org.sonar.batch.protocol.input.Metric(metricId,
metric.key(),
metric.getType().name(),
metric.getDescription(),
metric.getDirection(),
metric.getName(),
metric.getQualitative(),
metric.getUserManaged(),
metric.getWorstValue(),
metric.getBestValue(),
optimizedBestValue != null ? optimizedBestValue : false));
metricId++;
return this;
}
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-server
@Override
@Nonnull
public MetricDto apply(@Nonnull Metric metric) {
MetricDto dto = new MetricDto();
dto.setId(metric.getId());
dto.setKey(metric.getKey());
dto.setDescription(metric.getDescription());
dto.setShortName(metric.getName());
dto.setBestValue(metric.getBestValue());
dto.setDomain(metric.getDomain());
dto.setEnabled(metric.getEnabled());
dto.setDirection(metric.getDirection());
dto.setHidden(metric.isHidden());
dto.setQualitative(metric.getQualitative());
dto.setValueType(metric.getType().name());
dto.setOptimizedBestValue(metric.isOptimizedBestValue());
dto.setUserManaged(metric.getUserManaged());
dto.setWorstValue(metric.getWorstValue());
dto.setDeleteHistoricalData(metric.getDeleteHistoricalData());
dto.setDecimalScale(metric.getDecimalScale());
return dto;
}
}
内容来源于网络,如有侵权,请联系作者删除!