Simplify DeleteVote to only use a single loop
The old logic was a little confusing: - Looked up approvals twice. - Looped over label types. - Created the message in the loop body. Change-Id: Ib59df4cb3032800a305efb6928567e4d67dac07e
This commit is contained in:
@@ -58,6 +58,16 @@ public abstract class LabelVote {
|
||||
Short.parseShort(text.substring(e + 1), text.length()));
|
||||
}
|
||||
|
||||
public static StringBuilder appendTo(StringBuilder sb, String label,
|
||||
short value) {
|
||||
if (value == (short) 0) {
|
||||
return sb.append('-').append(label);
|
||||
} else if (value < 0) {
|
||||
return sb.append(label).append(value);
|
||||
}
|
||||
return sb.append(label).append('+').append(value);
|
||||
}
|
||||
|
||||
public static LabelVote create(String label, short value) {
|
||||
return new AutoValue_LabelVote(LabelType.checkNameInternal(label), value);
|
||||
}
|
||||
@@ -70,13 +80,9 @@ public abstract class LabelVote {
|
||||
public abstract short value();
|
||||
|
||||
public String format() {
|
||||
if (value() == (short) 0) {
|
||||
return '-' + label();
|
||||
} else if (value() < 0) {
|
||||
return label() + value();
|
||||
} else {
|
||||
return label() + '+' + value();
|
||||
}
|
||||
// Max short string length is "-32768".length() == 6.
|
||||
return appendTo(new StringBuilder(label().length() + 6), label(), value())
|
||||
.toString();
|
||||
}
|
||||
|
||||
public String formatWithEquals() {
|
||||
|
Reference in New Issue
Block a user