Skip to content

Commit

Permalink
Merge pull request #486 from refinedmods/chore/GH-482/sonarfixes
Browse files Browse the repository at this point in the history
Sonar fixes
  • Loading branch information
raoulvdberge authored Mar 10, 2024
2 parents 1fd63d1 + 7251c0d commit f07c45c
Show file tree
Hide file tree
Showing 51 changed files with 302 additions and 280 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ this mod that allow the player to setup auto-crafting, allowing the crafting of
- [Roadmap](https://github.com/refinedmods/refinedstorage2/projects)
- [Wiki](https://github.com/refinedmods/refinedstorage2/wiki)
- [Refined Mods on GitHub](https://github.com/refinedmods)
- [Javadoc](https://refinedmods.com/javadoc/refinedstorage2)
- [Discord](https://discordapp.com/invite/VYzsydb)
- [Twitter](https://twitter.com/refinedmods)
- [Mastodon](https://anvil.social/@refinedmods)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public class NetworkTestExtension implements BeforeEachCallback, ParameterResolver {
private final Map<String, Network> networkMap = new HashMap<>();
private final Map<Class<? extends NetworkNode>, NetworkNodeFactory<?>> networkNodeFactories = new HashMap<>();
private final Map<Class<? extends NetworkNode>, NetworkNodeFactory> networkNodeFactories = new HashMap<>();

@Override
public void beforeEach(final ExtensionContext extensionContext) {
Expand All @@ -48,13 +48,13 @@ private void processTestInstance(final Object testInstance) {
private void registerNetworkNodes(final Object testInstance) {
for (final RegisterNetworkNode annotation : getAnnotations(testInstance, RegisterNetworkNode.class)) {
try {
final NetworkNodeFactory<?> factory = annotation.value().getDeclaredConstructor().newInstance();
final NetworkNodeFactory factory = annotation.value().getDeclaredConstructor().newInstance();
networkNodeFactories.put(annotation.clazz(), factory);
} catch (InstantiationException
| IllegalAccessException
| InvocationTargetException
| NoSuchMethodException e) {
throw new RuntimeException(e);
// shouldn't happen
}
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ private void setField(final Object instance, final Field field, final Object val
field.setAccessible(true);
field.set(instance, value);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
// shouldn't happen
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Target(ElementType.TYPE)
@Repeatable(RegisterNetworkNodes.class)
public @interface RegisterNetworkNode {
Class<? extends NetworkNodeFactory<?>> value();
Class<? extends NetworkNodeFactory> value();

Class<? extends NetworkNode> clazz();
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public abstract class AbstractNetworkNodeFactory<T extends AbstractNetworkNode> implements NetworkNodeFactory<T> {
public abstract class AbstractNetworkNodeFactory implements NetworkNodeFactory {
public static final String PROPERTY_ACTIVE = "active";
public static final String PROPERTY_ENERGY_USAGE = "energy_usage";

@Override
public final T create(final AddNetworkNode ctx, final Map<String, Object> properties) {
final T value = innerCreate(ctx, properties);
public final NetworkNode create(final AddNetworkNode ctx, final Map<String, Object> properties) {
final AbstractNetworkNode value = innerCreate(ctx, properties);
final boolean active = (boolean) properties.getOrDefault(PROPERTY_ACTIVE, true);
value.setActive(active);
return value;
Expand All @@ -21,5 +22,5 @@ protected final long getEnergyUsage(final Map<String, Object> properties) {
return (long) properties.getOrDefault(PROPERTY_ENERGY_USAGE, 0L);
}

protected abstract T innerCreate(AddNetworkNode ctx, Map<String, Object> properties);
protected abstract AbstractNetworkNode innerCreate(AddNetworkNode ctx, Map<String, Object> properties);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.controller.ControllerNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class ControllerNetworkNodeFactory extends AbstractNetworkNodeFactory<ControllerNetworkNode> {
public class ControllerNetworkNodeFactory extends AbstractNetworkNodeFactory {
@Override
protected ControllerNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
return new ControllerNetworkNode();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.detector.DetectorNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class DetectorNetworkNodeFactory extends AbstractNetworkNodeFactory<DetectorNetworkNode> {
public class DetectorNetworkNodeFactory extends AbstractNetworkNodeFactory {
@Override
protected DetectorNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
return new DetectorNetworkNode(getEnergyUsage(properties));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.exporter.ExporterNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class ExporterNetworkNodeFactory extends AbstractNetworkNodeFactory<ExporterNetworkNode> {
public class ExporterNetworkNodeFactory extends AbstractNetworkNodeFactory {
@Override
protected ExporterNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
return new ExporterNetworkNode(getEnergyUsage(properties));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExternalStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.storage.tracked.InMemoryTrackedStorageRepository;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class ExternalStorageNetworkNodeFactory extends AbstractNetworkNodeFactory<ExternalStorageNetworkNode> {
public class ExternalStorageNetworkNodeFactory extends AbstractNetworkNodeFactory {
@Override
protected ExternalStorageNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
final ExternalStorageNetworkNode externalStorage = new ExternalStorageNetworkNode(
getEnergyUsage(properties),
() -> 0L
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class GridNetworkNodeFactory extends AbstractNetworkNodeFactory<GridNetworkNode> {
public class GridNetworkNodeFactory extends AbstractNetworkNodeFactory {
@Override
protected GridNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
return new GridNetworkNode(getEnergyUsage(properties));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class ImporterNetworkNodeFactory extends AbstractNetworkNodeFactory<ImporterNetworkNode> {
public class ImporterNetworkNodeFactory extends AbstractNetworkNodeFactory {
@Override
protected ImporterNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
return new ImporterNetworkNode(getEnergyUsage(properties));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class InterfaceNetworkNodeFactory extends AbstractNetworkNodeFactory<InterfaceNetworkNode> {
public class InterfaceNetworkNodeFactory extends AbstractNetworkNodeFactory {
@Override
protected InterfaceNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
return new InterfaceNetworkNode(getEnergyUsage(properties));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class MultiStorageNetworkNodeFactory extends AbstractNetworkNodeFactory<MultiStorageNetworkNode> {
public class MultiStorageNetworkNodeFactory extends AbstractNetworkNodeFactory {
public static final String PROPERTY_ENERGY_USAGE_PER_STORAGE = "energy_usage_per_storage";
public static final String PROPERTY_SIZE = "size";

@Override
protected MultiStorageNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
final long energyUsagePerStorage = (long) properties.getOrDefault(PROPERTY_ENERGY_USAGE_PER_STORAGE, 0L);
final int size = (int) properties.getOrDefault(PROPERTY_SIZE, 9);
return new MultiStorageNetworkNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import java.util.Map;

@FunctionalInterface
public interface NetworkNodeFactory<T extends NetworkNode> {
T create(AddNetworkNode ctx, Map<String, Object> properties);
public interface NetworkNodeFactory {
NetworkNode create(AddNetworkNode ctx, Map<String, Object> properties);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class SimpleNetworkNodeFactory extends AbstractNetworkNodeFactory<SimpleNetworkNode> {
public class SimpleNetworkNodeFactory extends AbstractNetworkNodeFactory {
@Override
protected SimpleNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
return new SimpleNetworkNode(getEnergyUsage(properties));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class StorageNetworkNodeFactory extends AbstractNetworkNodeFactory<StorageNetworkNode> {
public class StorageNetworkNodeFactory extends AbstractNetworkNodeFactory {
@Override
protected StorageNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
return new StorageNetworkNode(getEnergyUsage(properties));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.refinedmods.refinedstorage2.platform.api.support.registry.PlatformRegistry;
import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceFactory;
import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceRendering;
import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType;
import com.refinedmods.refinedstorage2.platform.api.upgrade.BuiltinUpgradeDestinations;
import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeRegistry;
import com.refinedmods.refinedstorage2.platform.api.wirelesstransmitter.WirelessTransmitterRangeModifier;
Expand Down Expand Up @@ -81,7 +82,7 @@ public StorageContainerItemHelper getStorageContainerItemHelper() {
}

@Override
public PlatformRegistry getResourceTypeRegistry() {
public PlatformRegistry<ResourceType> getResourceTypeRegistry() {
return ensureLoaded().getResourceTypeRegistry();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void onScroll(GridScrollMode scrollMode,

int getRegistryId();

List<? extends ClientTooltipComponent> getExtractionHints();
List<ClientTooltipComponent> getExtractionHints();

@Nullable
PlatformResourceKey getUnderlyingResource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode;
import com.refinedmods.refinedstorage2.platform.api.PlatformApi;
import com.refinedmods.refinedstorage2.platform.api.PlatformApiProxy;
import com.refinedmods.refinedstorage2.platform.api.upgrade.AbstractUpgradeItem;
import com.refinedmods.refinedstorage2.platform.common.configurationcard.ConfigurationCardItem;
import com.refinedmods.refinedstorage2.platform.common.constructordestructor.BlockBreakDestructorStrategyFactory;
import com.refinedmods.refinedstorage2.platform.common.constructordestructor.ConstructorBlockEntity;
Expand Down Expand Up @@ -98,7 +99,6 @@
import com.refinedmods.refinedstorage2.platform.common.upgrade.FortuneUpgradeItem;
import com.refinedmods.refinedstorage2.platform.common.upgrade.RangeUpgradeItem;
import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeItem;
import com.refinedmods.refinedstorage2.platform.common.upgrade.SimpleUpgradeItem;
import com.refinedmods.refinedstorage2.platform.common.upgrade.UpgradeDestinations;
import com.refinedmods.refinedstorage2.platform.common.upgrade.UpgradeWithEnchantedBookRecipeSerializer;
Expand Down Expand Up @@ -301,7 +301,7 @@ protected final void registerBlocks(

protected final void registerItems(
final RegistryCallback<Item> callback,
final Supplier<RegulatorUpgradeItem> regulatorUpgradeItemSupplier,
final Supplier<AbstractUpgradeItem> regulatorUpgradeItemSupplier,
final Supplier<WirelessGridItem> wirelessGridItemSupplier,
final Supplier<WirelessGridItem> creativeWirelessGridItemSupplier,
final Supplier<PortableGridBlockItem> portableGridBlockItemSupplier,
Expand Down Expand Up @@ -413,13 +413,13 @@ private void registerFluidStorageItems(final RegistryCallback<Item> callback,

private void registerUpgrades(
final RegistryCallback<Item> callback,
final Supplier<RegulatorUpgradeItem> regulatorUpgradeItemSupplier
final Supplier<AbstractUpgradeItem> regulatorUpgradeItemSupplier
) {
Items.INSTANCE.setUpgrade(callback.register(
ContentIds.UPGRADE,
SimpleItem::new
));
final Supplier<SimpleUpgradeItem> speedUpgrade = callback.register(
final Supplier<AbstractUpgradeItem> speedUpgrade = callback.register(
ContentIds.SPEED_UPGRADE,
() -> new SimpleUpgradeItem(
PlatformApi.INSTANCE.getUpgradeRegistry(),
Expand All @@ -428,7 +428,7 @@ private void registerUpgrades(
)
);
Items.INSTANCE.setSpeedUpgrade(speedUpgrade);
final Supplier<SimpleUpgradeItem> stackUpgrade = callback.register(
final Supplier<AbstractUpgradeItem> stackUpgrade = callback.register(
ContentIds.STACK_UPGRADE,
() -> new SimpleUpgradeItem(
PlatformApi.INSTANCE.getUpgradeRegistry(),
Expand All @@ -437,22 +437,22 @@ private void registerUpgrades(
)
);
Items.INSTANCE.setStackUpgrade(stackUpgrade);
final Supplier<FortuneUpgradeItem> fortune1Upgrade = callback.register(
final Supplier<AbstractUpgradeItem> fortune1Upgrade = callback.register(
ContentIds.FORTUNE_1_UPGRADE,
() -> new FortuneUpgradeItem(PlatformApi.INSTANCE.getUpgradeRegistry(), 1)
);
Items.INSTANCE.setFortune1Upgrade(fortune1Upgrade);
final Supplier<FortuneUpgradeItem> fortune2Upgrade = callback.register(
final Supplier<AbstractUpgradeItem> fortune2Upgrade = callback.register(
ContentIds.FORTUNE_2_UPGRADE,
() -> new FortuneUpgradeItem(PlatformApi.INSTANCE.getUpgradeRegistry(), 2)
);
Items.INSTANCE.setFortune2Upgrade(fortune2Upgrade);
final Supplier<FortuneUpgradeItem> fortune3Upgrade = callback.register(
final Supplier<AbstractUpgradeItem> fortune3Upgrade = callback.register(
ContentIds.FORTUNE_3_UPGRADE,
() -> new FortuneUpgradeItem(PlatformApi.INSTANCE.getUpgradeRegistry(), 3)
);
Items.INSTANCE.setFortune3Upgrade(fortune3Upgrade);
final Supplier<SimpleUpgradeItem> silkTouchUpgrade = callback.register(
final Supplier<AbstractUpgradeItem> silkTouchUpgrade = callback.register(
ContentIds.SILK_TOUCH_UPGRADE,
() -> new SimpleUpgradeItem(
PlatformApi.INSTANCE.getUpgradeRegistry(),
Expand Down Expand Up @@ -505,8 +505,7 @@ protected final void registerUpgradeMappings() {
protected final void registerBlockEntities(
final RegistryCallback<BlockEntityType<?>> callback,
final BlockEntityTypeFactory typeFactory,
final BlockEntityTypeFactory.BlockEntitySupplier<? extends AbstractDiskDriveBlockEntity>
diskDriveBlockEntitySupplier,
final BlockEntityTypeFactory.BlockEntitySupplier<AbstractDiskDriveBlockEntity> diskDriveBlockEntitySupplier,
final BlockEntityTypeFactory.BlockEntitySupplier<? extends AbstractPortableGridBlockEntity>
portableGridBlockEntitySupplier,
final BlockEntityTypeFactory.BlockEntitySupplier<? extends AbstractPortableGridBlockEntity>
Expand Down
Loading

0 comments on commit f07c45c

Please sign in to comment.