Skip to content

Commit 187bfc8

Browse files
committed
remove unnecessary lazy init
1 parent 2996371 commit 187bfc8

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/main/java/de/srendi/advancedperipherals/lib/peripherals/BasePeripheral.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class BasePeripheral<O extends IPeripheralOwner> implements IBas
3535
protected final O owner;
3636
protected final List<BoundMethod> pluggedMethods = new ArrayList<>();
3737
protected boolean initialized = false;
38-
protected List<IPeripheralPlugin> plugins = null;
38+
protected final List<IPeripheralPlugin> plugins = new ArrayList<>();
3939
protected String[] methodNames = new String[0];
4040

4141
protected BasePeripheral(String type, @NotNull O owner) {
@@ -49,11 +49,9 @@ protected void tryBuildPlugins() {
4949
}
5050
this.initialized = true;
5151
this.pluggedMethods.clear();
52-
if (this.plugins != null) {
53-
this.plugins.stream()
54-
.filter(plugin -> plugin.isSuitable(this))
55-
.forEach(plugin -> this.pluggedMethods.addAll(plugin.getMethods()));
56-
}
52+
this.plugins.stream()
53+
.filter(plugin -> plugin.isSuitable(this))
54+
.forEach(plugin -> this.pluggedMethods.addAll(plugin.getMethods()));
5755
owner.getAbilities().forEach(ability -> {
5856
if (ability instanceof IPeripheralPlugin peripheralPlugin) {
5957
this.pluggedMethods.addAll(peripheralPlugin.getMethods());
@@ -63,8 +61,7 @@ protected void tryBuildPlugins() {
6361
}
6462

6563
protected void addPlugin(@NotNull IPeripheralPlugin plugin) {
66-
if (plugins == null) plugins = new ArrayList<>();
67-
plugins.add(plugin);
64+
this.plugins.add(plugin);
6865
IPeripheralOperation<?>[] operations = plugin.getOperations();
6966
if (operations != null) {
7067
OperationAbility operationAbility = owner.getAbility(PeripheralOwnerAbility.OPERATION);

src/main/java/de/srendi/advancedperipherals/lib/peripherals/IntegrationPeripheral.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ public abstract class IntegrationPeripheral implements IDynamicPeripheral {
1919
protected final List<IComputerAccess> connectedComputers = new ArrayList<>();
2020
protected final List<BoundMethod> pluggedMethods = new ArrayList<>();
2121
protected boolean initialized = false;
22-
protected List<IPeripheralPlugin> plugins = null;
22+
protected final List<IPeripheralPlugin> plugins = new ArrayList<>();
2323
protected String[] methodNames = new String[0];
2424

2525
protected void buildPlugins() {
2626
if (!initialized) {
2727
initialized = true;
2828
this.pluggedMethods.clear();
29-
if (plugins != null) plugins.forEach(plugin -> {
30-
if (plugin.isSuitable(this))
29+
this.plugins.forEach(plugin -> {
30+
if (plugin.isSuitable(this)) {
3131
pluggedMethods.addAll(plugin.getMethods());
32+
}
3233
});
3334
this.methodNames = pluggedMethods.stream().map(BoundMethod::getName).toArray(String[]::new);
3435
}
3536
}
3637

3738
protected void addPlugin(@NotNull IPeripheralPlugin plugin) {
38-
if (plugins == null) plugins = new ArrayList<>();
3939
plugins.add(plugin);
4040
IPeripheralOperation<?>[] operations = plugin.getOperations();
4141
if (operations != null) {

0 commit comments

Comments
 (0)