diff options
Diffstat (limited to 'gerrit-common/src/main/java/com/google/gerrit/common/data/LabelType.java')
-rw-r--r-- | gerrit-common/src/main/java/com/google/gerrit/common/data/LabelType.java | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/LabelType.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/LabelType.java index 6d427e737c..7bfd22e0c6 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/LabelType.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/LabelType.java @@ -14,6 +14,7 @@ package com.google.gerrit.common.data; +import com.google.gerrit.common.Nullable; import com.google.gerrit.reviewdb.client.LabelId; import com.google.gerrit.reviewdb.client.PatchSetApproval; import java.util.ArrayList; @@ -22,6 +23,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; public class LabelType { public static final boolean DEF_ALLOW_POST_SUBMIT = true; @@ -97,7 +99,9 @@ public class LabelType { protected String name; + // String rather than LabelFunction for backwards compatibility with GWT JSON interface. protected String functionName; + protected boolean copyMinScore; protected boolean copyMaxScore; protected boolean copyAllScoresOnMergeFirstParentUpdate; @@ -124,7 +128,7 @@ public class LabelType { values = sortValues(valueList); defaultValue = 0; - functionName = "MaxWithBlock"; + functionName = LabelFunction.MAX_WITH_BLOCK.getFunctionName(); maxNegative = Short.MIN_VALUE; maxPositive = Short.MAX_VALUE; @@ -154,12 +158,19 @@ public class LabelType { return psa.getLabelId().get().equalsIgnoreCase(name); } - public String getFunctionName() { - return functionName; + public LabelFunction getFunction() { + if (functionName == null) { + return null; + } + Optional<LabelFunction> f = LabelFunction.parse(functionName); + if (!f.isPresent()) { + throw new IllegalStateException("Unsupported functionName: " + functionName); + } + return f.get(); } - public void setFunctionName(String functionName) { - this.functionName = functionName; + public void setFunction(@Nullable LabelFunction function) { + this.functionName = function != null ? function.getFunctionName() : null; } public boolean canOverride() { @@ -274,7 +285,7 @@ public class LabelType { return byValue.get(value); } - public LabelValue getValue(final PatchSetApproval ca) { + public LabelValue getValue(PatchSetApproval ca) { initByValue(); return byValue.get(ca.getValue()); } @@ -282,7 +293,7 @@ public class LabelType { private void initByValue() { if (byValue == null) { byValue = new HashMap<>(); - for (final LabelValue v : values) { + for (LabelValue v : values) { byValue.put(v.getValue(), v); } } |