Skip to content

Commit

Permalink
SONAR-6620 rename Metric.getMetricType to getType
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb committed Jun 11, 2015
1 parent 3867d47 commit ccc92bf
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 20 deletions.
Expand Up @@ -34,7 +34,7 @@ public Optional<Measure> toMeasure(@Nullable BatchReport.Measure batchMeasure, M
} }


String data = batchMeasure.hasStringValue() ? batchMeasure.getStringValue() : null; String data = batchMeasure.hasStringValue() ? batchMeasure.getStringValue() : null;
switch (metric.getMetricType().getValueType()) { switch (metric.getType().getValueType()) {
case INT: case INT:
return toIntegerMeasure(batchMeasure, data); return toIntegerMeasure(batchMeasure, data);
case LONG: case LONG:
Expand All @@ -50,7 +50,7 @@ public Optional<Measure> toMeasure(@Nullable BatchReport.Measure batchMeasure, M
case NO_VALUE: case NO_VALUE:
return toNoValueMeasure(batchMeasure); return toNoValueMeasure(batchMeasure);
default: default:
throw new IllegalArgumentException("Unsupported Measure.ValueType " + metric.getMetricType().getValueType()); throw new IllegalArgumentException("Unsupported Measure.ValueType " + metric.getType().getValueType());
} }
} }


Expand Down
Expand Up @@ -154,8 +154,6 @@ public String toString() {
* <p> * <p>
* If the measure type is {@link Measure.ValueType#STRING}, the value returned by this function is the same as {@link #getStringValue()}. * If the measure type is {@link Measure.ValueType#STRING}, the value returned by this function is the same as {@link #getStringValue()}.
* </p> * </p>
*
* @throws IllegalStateException if the value type of the measure is not {@link Measure.ValueType#BOOLEAN}
*/ */
@CheckForNull @CheckForNull
String getData(); String getData();
Expand Down
Expand Up @@ -37,7 +37,7 @@ public Optional<Measure> toMeasure(@Nullable MeasureDto measureDto, Metric metri


Double value = measureDto.getValue(); Double value = measureDto.getValue();
String data = measureDto.getData(); String data = measureDto.getData();
switch (metric.getMetricType().getValueType()) { switch (metric.getType().getValueType()) {
case INT: case INT:
return toIntegerMeasure(measureDto, value, data); return toIntegerMeasure(measureDto, value, data);
case LONG: case LONG:
Expand All @@ -53,7 +53,7 @@ public Optional<Measure> toMeasure(@Nullable MeasureDto measureDto, Metric metri
case NO_VALUE: case NO_VALUE:
return toNoValueMeasure(measureDto); return toNoValueMeasure(measureDto);
default: default:
throw new IllegalArgumentException("Unsupported Measure.ValueType " + metric.getMetricType().getValueType()); throw new IllegalArgumentException("Unsupported Measure.ValueType " + metric.getType().getValueType());
} }
} }


Expand Down
Expand Up @@ -29,7 +29,7 @@ public interface Metric {


String getName(); String getName();


MetricType getMetricType(); MetricType getType();


enum MetricType { enum MetricType {
INT(Measure.ValueType.INT), INT(Measure.ValueType.INT),
Expand Down
Expand Up @@ -30,12 +30,12 @@ public final class MetricImpl implements Metric {


private final String key; private final String key;
private final String name; private final String name;
private final MetricType metricType; private final MetricType type;


public MetricImpl(String key, String name, MetricType metricType) { public MetricImpl(String key, String name, MetricType type) {
this.key = requireNonNull(key); this.key = requireNonNull(key);
this.name = requireNonNull(name); this.name = requireNonNull(name);
this.metricType = requireNonNull(metricType); this.type = requireNonNull(type);
} }


@Override @Override
Expand All @@ -49,8 +49,8 @@ public String getName() {
} }


@Override @Override
public MetricType getMetricType() { public MetricType getType() {
return metricType; return type;
} }


@Override @Override
Expand All @@ -63,20 +63,20 @@ public boolean equals(@Nullable Object o) {
} }
MetricImpl metric = (MetricImpl) o; MetricImpl metric = (MetricImpl) o;
return Objects.equals(key, metric.key) && return Objects.equals(key, metric.key) &&
Objects.equals(metricType, metric.metricType); Objects.equals(type, metric.type);
} }


@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(key, metricType); return Objects.hash(key, type);
} }


@Override @Override
public String toString() { public String toString() {
return com.google.common.base.Objects.toStringHelper(this) return com.google.common.base.Objects.toStringHelper(this)
.add("key", key) .add("key", key)
.add("name", name) .add("name", name)
.add("metricType", metricType) .add("type", type)
.toString(); .toString();
} }
} }
Expand Up @@ -86,9 +86,9 @@ public class MeasureRepositoryImplTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
when(metric1.getKey()).thenReturn(METRIC_KEY_1); when(metric1.getKey()).thenReturn(METRIC_KEY_1);
when(metric1.getMetricType()).thenReturn(Metric.MetricType.STRING); when(metric1.getType()).thenReturn(Metric.MetricType.STRING);
when(metric2.getKey()).thenReturn(METRIC_KEY_2); when(metric2.getKey()).thenReturn(METRIC_KEY_2);
when(metric2.getMetricType()).thenReturn(Metric.MetricType.STRING); when(metric2.getType()).thenReturn(Metric.MetricType.STRING);


// references to metrics are consistent with DB by design // references to metrics are consistent with DB by design
when(metricRepository.getByKey(METRIC_KEY_1)).thenReturn(metric1); when(metricRepository.getByKey(METRIC_KEY_1)).thenReturn(metric1);
Expand Down
Expand Up @@ -49,7 +49,7 @@ public void verify_getters() {


assertThat(metric.getKey()).isEqualTo(SOME_KEY); assertThat(metric.getKey()).isEqualTo(SOME_KEY);
assertThat(metric.getName()).isEqualTo(SOME_NAME); assertThat(metric.getName()).isEqualTo(SOME_NAME);
assertThat(metric.getMetricType()).isEqualTo(Metric.MetricType.FLOAT); assertThat(metric.getType()).isEqualTo(Metric.MetricType.FLOAT);
} }


@Test @Test
Expand All @@ -76,7 +76,7 @@ public void hashcode_uses_only_key_and_valueType() {
@Test @Test
public void all_fields_are_displayed_in_toString() { public void all_fields_are_displayed_in_toString() {
assertThat(new MetricImpl(SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT).toString()) assertThat(new MetricImpl(SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT).toString())
.isEqualTo("MetricImpl{key=key, name=name, metricType=FLOAT}"); .isEqualTo("MetricImpl{key=key, name=name, type=FLOAT}");


} }
} }
Expand Up @@ -89,7 +89,7 @@ private void verify_mapping_and_valueType_conversion_from_DB_impl(String valueTy


assertThat(metric.getKey()).isEqualTo(metricDto.getKey()); assertThat(metric.getKey()).isEqualTo(metricDto.getKey());
assertThat(metric.getName()).isEqualTo(metricDto.getShortName()); assertThat(metric.getName()).isEqualTo(metricDto.getShortName());
assertThat(metric.getMetricType()).isEqualTo(expected); assertThat(metric.getType()).isEqualTo(expected);
} }


@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
Expand Down

0 comments on commit ccc92bf

Please sign in to comment.