From 23208af902ce01411debfd42c21e123432756054 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 20 Nov 2015 11:54:35 +0100 Subject: [PATCH] SONAR-7027 MeasureRepositoryRule now allow adding measures by developer --- .../measure/MeasureRepositoryRule.java | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryRule.java index d435cc11e38..9f0e09422c4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryRule.java @@ -34,6 +34,7 @@ import javax.annotation.Nullable; import org.junit.rules.ExternalResource; import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.ComponentProvider; +import org.sonar.server.computation.component.Developer; import org.sonar.server.computation.component.NoComponentProvider; import org.sonar.server.computation.component.TreeComponentProvider; import org.sonar.server.computation.component.TreeRootHolder; @@ -281,7 +282,7 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe @Override public void add(Component component, Metric metric, Measure measure) { String ref = getRef(component); - InternalKey internalKey = new InternalKey(ref, metric.getKey(), measure.getRuleId(), measure.getCharacteristicId()); + InternalKey internalKey = new InternalKey(ref, metric.getKey(), measure.getRuleId(), measure.getCharacteristicId(), measure.getDeveloper()); if (rawMeasures.containsKey(internalKey)) { throw new UnsupportedOperationException(format( "A measure can only be set once for Component (ref=%s), Metric (key=%s), ruleId=%s, characteristicId=%s", @@ -293,7 +294,7 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe @Override public void update(Component component, Metric metric, Measure measure) { String componentRef = getRef(component); - InternalKey internalKey = new InternalKey(componentRef, metric.getKey(), measure.getRuleId(), measure.getCharacteristicId()); + InternalKey internalKey = new InternalKey(componentRef, metric.getKey(), measure.getRuleId(), measure.getCharacteristicId(), measure.getDeveloper()); if (!rawMeasures.containsKey(internalKey)) { throw new UnsupportedOperationException(format( "A measure can only be updated if it has been added first for Component (ref=%s), Metric (key=%s), ruleId=%s, characteristicId=%s", @@ -318,24 +319,23 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe private final String metricKey; private final int ruleId; private final int characteristicId; + @Nullable + private final Developer developer; public InternalKey(Component component, Metric metric) { - this(getRef(component), metric.getKey(), null, null); + this(getRef(component), metric.getKey(), null, null, null); } public InternalKey(Component component, Metric metric, @Nullable Integer ruleId, @Nullable Integer characteristicId) { - this(getRef(component), metric.getKey(), ruleId, characteristicId); - } - - public InternalKey(String componentRef, String metricKey) { - this(componentRef, metricKey, null, null); + this(getRef(component), metric.getKey(), ruleId, characteristicId, null); } - public InternalKey(String componentRef, String metricKey, @Nullable Integer ruleId, @Nullable Integer characteristicId) { + public InternalKey(String componentRef, String metricKey, @Nullable Integer ruleId, @Nullable Integer characteristicId, @Nullable Developer developer) { this.componentRef = componentRef; this.metricKey = metricKey; this.ruleId = ruleId == null ? DEFAULT_VALUE : ruleId; this.characteristicId = characteristicId == null ? DEFAULT_VALUE : characteristicId; + this.developer = developer; } public String getComponentRef() { @@ -346,14 +346,6 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe return metricKey; } - public int getRuleId() { - return ruleId; - } - - public int getCharacteristicId() { - return characteristicId; - } - @Override public boolean equals(@Nullable Object o) { if (this == o) { @@ -364,14 +356,15 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe } InternalKey that = (InternalKey) o; return Objects.equals(componentRef, that.componentRef) && + Objects.equals(metricKey, that.metricKey) && Objects.equals(ruleId, that.ruleId) && Objects.equals(characteristicId, that.characteristicId) && - Objects.equals(metricKey, that.metricKey); + Objects.equals(developer, that.developer); } @Override public int hashCode() { - return Objects.hash(componentRef, metricKey, ruleId, characteristicId); + return Objects.hash(componentRef, metricKey, ruleId, characteristicId, developer); } @Override @@ -381,6 +374,7 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe ", metric='" + metricKey + '\'' + ", rule=" + ruleId + ", characteristic=" + characteristicId + + ", developer=" + developer + '}'; } } @@ -453,12 +447,12 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe } } - private enum ToMeasure implements Function, Measure> { + private enum ToMeasure implements Function, Measure> { INSTANCE; @Nullable @Override - public Measure apply(@Nonnull Map.Entry input) { + public Measure apply(@Nonnull Map.Entry input) { return input.getValue(); } } -- 2.39.5