Skip to content

Commit

Permalink
Use isEmpty.
Browse files Browse the repository at this point in the history
Using Collection.size() to test for emptiness works, but using
Collection.isEmpty() makes the code more readable and can be more
performant. The time complexity of any isEmpty() method implementation
should be O(1) whereas some implementations of size() can be O(n).

In this case, it's not a big deal, just a code smell.
  • Loading branch information
tastybento committed Dec 7, 2021
1 parent 68eac90 commit f70cf11
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/world/bentobox/border/Border.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class Border extends Addon {

private @NonNull List<GameModeAddon> gameModes = new ArrayList<>();

private final Set<BorderType> availableBorderTypes = EnumSet.of(BorderType.Barrier);
private final Set<BorderType> availableBorderTypes = EnumSet.of(BorderType.BARRIER);

@Override
public void onLoad() {
Expand All @@ -49,7 +49,7 @@ public void onEnable() {
this.setState(State.DISABLED);
return;
}
availableBorderTypes.add(BorderType.Vanilla);
availableBorderTypes.add(BorderType.VANILLA);
}
gameModes.clear();
// Register commands
Expand All @@ -64,7 +64,7 @@ public void onEnable() {
}
});

if (gameModes.size() > 0) {
if (!gameModes.isEmpty()) {
borderShower = createBorder();
registerListener(new PlayerListener(this));
}
Expand All @@ -79,7 +79,7 @@ private BorderShower createBorder() {
BorderShower customBorder = new ShowBarrier(this);
BorderShower wbapiBorder = getSettings().isUseWbapi()
? new ShowWorldBorder(this)
: null;
: null;
return new PerPlayerBorderProxy(this, customBorder, wbapiBorder);
}

Expand Down

0 comments on commit f70cf11

Please sign in to comment.