Skip to content

Commit

Permalink
Make almost all of MacroButtonProperties fields non-null
Browse files Browse the repository at this point in the history
Most of the fields were either close to being non-nullable, or had getters that enforced non-nullability for callers. As
a result, most of them were readily made truly non-nullable, which enabled us to avoid the need for `null` checks
outside of setters and `readResolve()`.

`StringBuilder` is now used locally instead of `StringBuffer` in `modifySortString()` as it is lighterweight and there
is no multithreading concerns.
  • Loading branch information
kwvanderlinde committed May 10, 2023
1 parent 24f1551 commit 53679f1
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Object getMacroButtonProps(Token token, int index, String delim) throws P
props.addProperty("playerEditable", mbp.getAllowPlayerEdits());
props.addProperty("command", mbp.getCommand());
props.addProperty("maxWidth", mbp.getMaxWidth());
props.addProperty("tooltip", mbp.getToolTip() == null ? "" : mbp.getToolTip());
props.addProperty("tooltip", mbp.getToolTip());
props.addProperty("applyToSelected", mbp.getApplyToTokens());

JsonArray compare = new JsonArray();
Expand Down Expand Up @@ -223,7 +223,7 @@ public Object getMacroButtonProps(Token token, int index, String delim) throws P
sb.append("minWidth=").append(mbp.getMinWidth()).append(delim);
sb.append("playerEditable=").append(mbp.getAllowPlayerEdits()).append(delim);
sb.append("maxWidth=").append(mbp.getMaxWidth()).append(delim);
sb.append("tooltip=").append(mbp.getToolTip() == null ? "" : mbp.getToolTip()).append(delim);
sb.append("tooltip=").append(mbp.getToolTip()).append(delim);
sb.append("applyToSelected=").append(mbp.getApplyToTokens()).append(delim);
return sb.toString();
}
Expand Down Expand Up @@ -419,8 +419,7 @@ private String getMacroCommand(int index, Token token) throws ParserException {
throw new ParserException(
I18N.getText(KEY_OUT_OF_RANGE, "getMacroCommand", index, token.getName()));
}
String cmd = mbp.getCommand();
return cmd != null ? cmd : "";
return mbp.getCommand();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ protected JMenu createMacroMenu() {
Map<String, JMenu> groups = new TreeMap<String, JMenu>();
for (MacroButtonProperties macro : macroList) {
group = macro.getGroup();
group =
(group == null || group.isEmpty()
? " General"
: group); // leading space makes it come first
group = (group.isEmpty() ? " General" : group); // leading space makes it come first
JMenu submenu = groups.get(group);
if (submenu == null) {
submenu = new JMenu(group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public List<MacroButtonProperties> getPropertiesList() {
}

public void setPropertiesList(List<MacroButtonProperties> propertiesList) {
MacroButtonProperties.fixOldMacroSetCompare(propertiesList);
this.propertiesList = propertiesList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public MacroButton(MacroButtonProperties properties, ButtonGroup buttonGroup, To
}
this.properties.setTokenId(this.tokenId);
this.properties.setSaveLocation(this.panelClass);
this.properties.setButton(this);
// we have to call setColor() and setText() here since properties only hold "dumb" data.
setColor(properties.getColorKey());
setText(getButtonText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void show(MacroButton button) {

if (properties != null) {
oldHashCode = properties.hashCodeForComparison();
Boolean playerCanEdit = !MapTool.getPlayer().isGM() && properties.getAllowPlayerEdits();
boolean playerCanEdit = !MapTool.getPlayer().isGM() && properties.getAllowPlayerEdits();
boolean onGlobalPanel = properties.getSaveLocation().equals("Global");
boolean allowEdits = onGlobalPanel || MapTool.getPlayer().isGM() || playerCanEdit;
boolean isCommonMacro =
Expand Down
Loading

0 comments on commit 53679f1

Please sign in to comment.