From 51619759724aab26417757bcb9102812c490e2cf Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 24 Jul 2022 13:53:21 +0200 Subject: [PATCH] Fix Sonar issues. --- .../importer/ImporterNetworkNodeTest.java | 42 +++++++++++++++++++ .../AbstractBaseContainerMenu.java | 9 ++-- .../containermenu/property/PropertyTypes.java | 2 +- .../AbstractStorageBlockContainerMenu.java | 7 ++-- .../diskdrive/DiskDriveContainerMenu.java | 3 +- .../FilteredResourceFilterContainer.java | 7 ++++ .../widget/ExactModeSideButtonWidget.java | 4 +- 7 files changed, 63 insertions(+), 11 deletions(-) diff --git a/refinedstorage2-network-api/src/test/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterNetworkNodeTest.java b/refinedstorage2-network-api/src/test/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterNetworkNodeTest.java index c21069e02..b792e9449 100644 --- a/refinedstorage2-network-api/src/test/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterNetworkNodeTest.java +++ b/refinedstorage2-network-api/src/test/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterNetworkNodeTest.java @@ -310,6 +310,48 @@ void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel storageChannel + ) { + // Arrange + sut.setFilterMode(FilterMode.ALLOW); + sut.setFilterTemplates(Set.of("A")); + sut.setNormalizer(value -> value instanceof String str && str.startsWith("A") ? "A" : value); + + storageChannel.addSource(new InMemoryStorageImpl<>()); + + final FakeImporterSource source = new FakeImporterSource("B", "A1", "A2") + .add("B", 10) + .add("A1", 1) + .add("A2", 1); + + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl<>( + source, + NetworkTestFixtures.STORAGE_CHANNEL_TYPE, + 10 + ); + sut.setTransferStrategy(strategy); + + // Act + sut.update(); + // cooldown + sut.update(); + sut.update(); + sut.update(); + // Act 2 + sut.update(); + + // Assert + assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount<>("A1", 1), + new ResourceAmount<>("A2", 1) + ); + assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount<>("B", 10) + ); + } + @Test void shouldRespectAllowlistWithoutAlternative( @InjectNetworkStorageChannel final StorageChannel storageChannel diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java index 33bd310d1..44e7d9a20 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java @@ -29,10 +29,13 @@ public ClientProperty getProperty(final PropertyType type) { } public void receivePropertyChangeFromClient(final ResourceLocation id, final int newValue) { - for (final PropertyType type : propertyMap.keySet()) { - if (type.id().equals(id)) { - ((ServerProperty) propertyMap.get(type)).set(newValue); + for (final Map.Entry, Property> entry : propertyMap.entrySet()) { + final PropertyType type = entry.getKey(); + if (!type.id().equals(id)) { + continue; } + final Property property = entry.getValue(); + ((ServerProperty) property).set(newValue); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/property/PropertyTypes.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/property/PropertyTypes.java index bc2116548..a95ed102b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/property/PropertyTypes.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/property/PropertyTypes.java @@ -36,7 +36,7 @@ public final class PropertyTypes { public static final PropertyType EXACT_MODE = new PropertyType<>( createIdentifier("exact_mode"), - value -> value ? 1 : 0, + value -> Boolean.TRUE.equals(value) ? 1 : 0, value -> value == 1 ); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/AbstractStorageBlockContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/AbstractStorageBlockContainerMenu.java index 0cd708c8f..ca49b9787 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/AbstractStorageBlockContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/AbstractStorageBlockContainerMenu.java @@ -33,9 +33,10 @@ protected AbstractStorageBlockContainerMenu(final MenuType type, this.stored = buf.readLong(); this.capacity = buf.readLong(); - addSlots(player, new FilteredResourceFilterContainer( - PlatformApi.INSTANCE.getResourceTypeRegistry(), 9, () -> { - }, resourceType)); + addSlots( + player, + new FilteredResourceFilterContainer(PlatformApi.INSTANCE.getResourceTypeRegistry(), 9, resourceType) + ); initializeResourceFilterSlots(buf); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java index f155f2397..6eb8461c9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java @@ -45,8 +45,7 @@ public DiskDriveContainerMenu(final int syncId, final Inventory playerInventory, addSlots( playerInventory.player, new SimpleContainer(DiskDriveNetworkNode.DISK_COUNT), - new ResourceFilterContainer(PlatformApi.INSTANCE.getResourceTypeRegistry(), 9, () -> { - }) + new ResourceFilterContainer(PlatformApi.INSTANCE.getResourceTypeRegistry(), 9) ); initializeResourceFilterSlots(buf); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/FilteredResourceFilterContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/FilteredResourceFilterContainer.java index de1f6a392..765738741 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/FilteredResourceFilterContainer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/FilteredResourceFilterContainer.java @@ -9,6 +9,13 @@ public class FilteredResourceFilterContainer extends ResourceFilterContainer { private final ResourceType allowedType; + public FilteredResourceFilterContainer(final OrderedRegistry resourceTypeRegistry, + final int size, + final ResourceType allowedType) { + this(resourceTypeRegistry, size, () -> { + }, allowedType); + } + public FilteredResourceFilterContainer(final OrderedRegistry resourceTypeRegistry, final int size, final Runnable listener, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/ExactModeSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/ExactModeSideButtonWidget.java index 41e60012e..c4032c19c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/ExactModeSideButtonWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/ExactModeSideButtonWidget.java @@ -40,7 +40,7 @@ private List calculateTooltip(final boolean exactMode) { @Override protected int getXTexture() { - return property.getValue() ? 0 : 16; + return Boolean.TRUE.equals(property.getValue()) ? 0 : 16; } @Override @@ -52,7 +52,7 @@ protected int getYTexture() { public void onTooltip(final Button button, final PoseStack poseStack, final int mouseX, final int mouseY) { tooltipRenderer.render( poseStack, - property.getValue() ? tooltipWhenOn : tooltipWhenOff, + Boolean.TRUE.equals(property.getValue()) ? tooltipWhenOn : tooltipWhenOff, mouseX, mouseY );