@CheckForNull
String getDescription();
-
+ /**
+ * a Metric is equal to another Metric if it has the same ruleId/characteristicId paar (both being potentially
+ * {@code null} but only one of them can be non {@code null}.
+ */
+ boolean equals(Object o);
}
package org.sonar.server.computation.measure;
import java.util.Locale;
+import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
public String getDescription() {
return description;
}
+
+ @Override
+ public boolean equals(@Nullable Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ MeasureImpl measure = (MeasureImpl) o;
+ return Objects.equals(ruleId, measure.ruleId) &&
+ Objects.equals(characteristicId, measure.characteristicId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(ruleId, characteristicId);
+ }
+
+ @Override
+ public String toString() {
+ return com.google.common.base.Objects.toStringHelper(this)
+ .add("valueType", valueType)
+ .add("ruleId", ruleId)
+ .add("characteristicId", characteristicId)
+ .add("value", value)
+ .add("data", data)
+ .add("dataLevel", dataLevel)
+ .add("qualityGateStatus", qualityGateStatus)
+ .add("variations", variations)
+ .add("description", description)
+ .toString();
+ }
}
package org.sonar.server.computation.measure;
import com.google.common.base.Optional;
-import com.google.common.collect.Multimap;
+import com.google.common.collect.SetMultimap;
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.metric.Metric;
import org.sonar.server.computation.metric.MetricImpl;
/**
* Retrieves the base measure (ie. the one currently existing in DB) for the specified {@link Component} for
* the specified {@link MetricImpl} if it exists.
+ * <p>
+ * This method searches for Measure which are specific to the Component and not associated to a rule or a
+ * characteristic.
+ * </p>
+ * <strong>
+ * It will never return a Measure with a non {@code null} {@link Measure#getRuleId()}
+ * or {@link Measure#getCharacteristicId()}
+ * </strong>
*
* @throws NullPointerException if either argument is {@code null}
*/
/**
* Retrieves the measure created during the current analysis for the specified {@link Component} for the specified
- * {@link MetricImpl} if it exists (ie. one created by the Compute Engine or the Batch).
+ * {@link Metric} if it exists (ie. one created by the Compute Engine or the Batch) and which is <strong>not</strong>
+ * associated to a rule or a characteristic.
*/
Optional<Measure> getRawMeasure(Component component, Metric metric);
/**
- * @return {@link Measure}s for the specified {@link Component} mapped by their metric key.
+ * Returns the {@link Measure}s for the specified {@link Component} mapped by their metric key.
+ * <p>
+ * Their can be multiple measures for the same Metric but only one which has no rule nor characteristic, one with a
+ * specific ruleId and one with specific characteristicId (see {@link Measure#equals(Object)}.
+ * </p>
*/
- Multimap<String, Measure> getRawMeasures(Component component);
+ SetMultimap<String, Measure> getRawMeasures(Component component);
/**
* Adds the specified measure for the specified Component and Metric. There can be no more than one measure for a
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
}
@Override
- public Multimap<String, Measure> getRawMeasures(Component component) {
+ public SetMultimap<String, Measure> getRawMeasures(Component component) {
Map<String, Measure> rawMeasures = measures.get(component.getRef());
ListMultimap<String, BatchReport.Measure> batchMeasures = from(reportReader.readComponentMeasures(component.getRef()))
.index(BatchMeasureToMetricKey.INSTANCE);
if (rawMeasures == null && batchMeasures.isEmpty()) {
- return ImmutableListMultimap.of();
+ return ImmutableSetMultimap.of();
}
ListMultimap<String, Measure> rawMeasuresFromBatch = Multimaps.transformValues(batchMeasures, batchMeasureToMeasureFunction);