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:
Dave Borowitz
2016-08-24 11:53:32 -04:00
parent afe569ab25
commit 7b6ac472fb
2 changed files with 66 additions and 62 deletions

View File

@@ -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() {