diff --git a/src/api/java/mekanism/api/chemical/ChemicalUtils.java b/src/api/java/mekanism/api/chemical/ChemicalUtils.java index 037f1a35317..0993b7b3609 100644 --- a/src/api/java/mekanism/api/chemical/ChemicalUtils.java +++ b/src/api/java/mekanism/api/chemical/ChemicalUtils.java @@ -87,14 +87,15 @@ public static ChemicalStack insert(ChemicalStack stack, @Nullable Direction side * * @since 10.6.0 */ - public static ChemicalStack insert(ChemicalStack stack, Action action, AutomationType automationType, int size, Iterable chemicalTanks) { + public static ChemicalStack insert(ChemicalStack stack, Action action, AutomationType automationType, int size, List chemicalTanks) { if (stack.isEmpty()) { //Short circuit if nothing is actually being inserted return ChemicalStack.EMPTY; } else if (size == 0) { return stack; } else if (size == 1) { - return chemicalTanks.iterator().next().insert(stack, action, automationType); + //noinspection SequencedCollectionMethodCanBeUsed: we know size + return chemicalTanks.get(0).insert(stack, action, automationType); } ChemicalStack toInsert = stack; //Start by trying to insert into the tanks that have the same type @@ -185,11 +186,12 @@ public static ChemicalStack extract(long amount, @Nullable Direction side, Funct * * @since 10.6.0 */ - public static ChemicalStack extract(long amount, Action action, AutomationType automationType, int size, Iterable chemicalTanks) { + public static ChemicalStack extract(long amount, Action action, AutomationType automationType, int size, List chemicalTanks) { if (amount == 0 || size == 0) { return ChemicalStack.EMPTY; } else if (size == 1) { - return chemicalTanks.iterator().next().extract(amount, action, automationType); + //noinspection SequencedCollectionMethodCanBeUsed: we know size + return chemicalTanks.get(0).extract(amount, action, automationType); } ChemicalStack extracted = ChemicalStack.EMPTY; long toDrain = amount; diff --git a/src/api/java/mekanism/api/fluid/ExtendedFluidHandlerUtils.java b/src/api/java/mekanism/api/fluid/ExtendedFluidHandlerUtils.java index c6f9582f6c5..3b64ea3b8e1 100644 --- a/src/api/java/mekanism/api/fluid/ExtendedFluidHandlerUtils.java +++ b/src/api/java/mekanism/api/fluid/ExtendedFluidHandlerUtils.java @@ -83,14 +83,15 @@ public static FluidStack insert(FluidStack stack, @Nullable Direction side, Func * * @since 10.6.0 */ - public static FluidStack insert(FluidStack stack, Action action, AutomationType automationType, int size, Iterable fluidTanks) { + public static FluidStack insert(FluidStack stack, Action action, AutomationType automationType, int size, List fluidTanks) { if (stack.isEmpty()) { //Short circuit if nothing is actually being inserted return FluidStack.EMPTY; } else if (size == 0) { return stack; } else if (size == 1) { - return fluidTanks.iterator().next().insert(stack, action, automationType); + //noinspection SequencedCollectionMethodCanBeUsed: we know size + return fluidTanks.get(0).insert(stack, action, automationType); } FluidStack toInsert = stack; //Start by trying to insert into the tanks that have the same type @@ -181,11 +182,12 @@ public static FluidStack extract(int amount, @Nullable Direction side, Function< * * @since 10.6.0 */ - public static FluidStack extract(int amount, Action action, AutomationType automationType, int size, Iterable fluidTanks) { + public static FluidStack extract(int amount, Action action, AutomationType automationType, int size, List fluidTanks) { if (amount == 0 || size == 0) { return FluidStack.EMPTY; } else if (size == 1) { - return fluidTanks.iterator().next().extract(amount, action, automationType); + //noinspection SequencedCollectionMethodCanBeUsed: we know size + return fluidTanks.get(0).extract(amount, action, automationType); } FluidStack extracted = FluidStack.EMPTY; int toDrain = amount; @@ -277,11 +279,12 @@ public static FluidStack extract(FluidStack stack, @Nullable Direction side, Fun * * @since 10.6.0 */ - public static FluidStack extract(FluidStack stack, Action action, AutomationType automationType, int size, Iterable fluidTanks) { + public static FluidStack extract(FluidStack stack, Action action, AutomationType automationType, int size, List fluidTanks) { if (stack.isEmpty() || size == 0) { return FluidStack.EMPTY; } else if (size == 1) { - IExtendedFluidTank tank = fluidTanks.iterator().next(); + //noinspection SequencedCollectionMethodCanBeUsed: we know size + IExtendedFluidTank tank = fluidTanks.get(0); if (tank.isEmpty() || !tank.isFluidEqual(stack)) { return FluidStack.EMPTY; } diff --git a/src/api/java/mekanism/api/math/LongTransferUtils.java b/src/api/java/mekanism/api/math/LongTransferUtils.java index db6e60d17a7..284c09de976 100644 --- a/src/api/java/mekanism/api/math/LongTransferUtils.java +++ b/src/api/java/mekanism/api/math/LongTransferUtils.java @@ -87,14 +87,15 @@ public static long insert(long stack, @Nullable Direction side, Function<@Nullab * * @since 10.6.0 */ - public static long insert(long stack, Action action, AutomationType automationType, int containerCount, Iterable energyContainers) { + public static long insert(long stack, Action action, AutomationType automationType, int containerCount, List energyContainers) { if (stack <= 0L) { //Short circuit if no energy is trying to be inserted return 0L; } else if (containerCount == 0) { return stack; } else if (containerCount == 1) { - return energyContainers.iterator().next().insert(stack, action, automationType); + //noinspection SequencedCollectionMethodCanBeUsed: we know size + return energyContainers.get(0).insert(stack, action, automationType); } long toInsert = stack; //Start by trying to insert into the containers that are not empty @@ -184,12 +185,13 @@ public static long extract(long amount, @Nullable Direction side, Function<@Null * * @since 10.6.0 */ - public static long extract(long amount, Action action, AutomationType automationType, int containerCount, Iterable energyContainers) { + public static long extract(long amount, Action action, AutomationType automationType, int containerCount, List energyContainers) { if (amount <= 0L || containerCount == 0) { //Short circuit if no energy is trying to be extracted return 0L; } else if (containerCount == 1) { - return energyContainers.iterator().next().extract(amount, action, automationType); + //noinspection SequencedCollectionMethodCanBeUsed: we know size + return energyContainers.get(0).extract(amount, action, automationType); } long extracted = 0; long toExtract = amount; diff --git a/src/main/java/mekanism/common/attachments/containers/ComponentBackedHandler.java b/src/main/java/mekanism/common/attachments/containers/ComponentBackedHandler.java index c9a9ba0d970..bc053ba6c57 100644 --- a/src/main/java/mekanism/common/attachments/containers/ComponentBackedHandler.java +++ b/src/main/java/mekanism/common/attachments/containers/ComponentBackedHandler.java @@ -1,5 +1,6 @@ package mekanism.common.attachments.containers; +import java.util.AbstractList; import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -11,7 +12,7 @@ import org.jetbrains.annotations.Nullable; @NothingNullByDefault -public abstract class ComponentBackedHandler, ATTACHED extends IAttachedContainers> +public abstract class ComponentBackedHandler, ATTACHED extends IAttachedContainers> extends AbstractList implements IContentsListener, Iterable { protected final ItemStack attachedTo; @@ -72,10 +73,15 @@ protected CONTAINER getContainer(int index) { return container == null ? initializeContainer(index) : container; } - protected int size() { + public int size() { return totalContainers; } + @Override + public CONTAINER get(int index) { + return getContainer(index); + } + @Override public void onContentsChanged() { }