Code cleanup (#133)

* gradle updateBuildScript

* fix comments and commented-out code

Code deletion, converting comments into javadocs, and refactoring code to not
need comments.

* remove redundant suppressions

* replace C-style array declaration with Java-style

* make private field final

* remove unnecessary semicolon

* extract a common part from an if

* simplify boolean expression

* simplify ternary if

* remove unused imports

* convert escaped characters for clarity

* replace while with for

* replace explicit types with diamond operators

* replace anonymous type with lambda

* enable modern Java syntax

* migrate to enhanced switch

* migrate to pattern variables for instanceof

* remove empty javadoc

* add Nonnull annotation to overrides of Nonnull methods

* replace wailaStack with null

When wailaStack is not null, the flow breaks out of the loop,
so there's no need to confuse the reader with putting wailaStack
both as the result and the parameter of the call - there's no
recursion.

* int cannot be bigger than its max value

* suppress dataflow warning

* remove redundant initializer

The default value of int is 0.

* null check is covered by instanceof

* simplify some calls of addVertexWithUV

* fix typos and add TODOs

* make flipState more understandable
This commit is contained in:
chill authored and GitHub committed 2023-06-18 23:29:57 +02:00
1 parent f87b76347e
commit d5b8ef6ea9
89 files changed
+421 -633

No files matched your search

@@ -83,6 +83,8 @@ public class Ae2Reflect {
for (String name : names) {
try {
f = owner.getDeclaredField(name);
// IntelliJ misses that the exception is ignored and thus "f" can indeed be null.
// noinspection ConstantValue
if (f != null) break;
} catch (NoSuchFieldException ignore) {}
}
@@ -69,8 +69,7 @@ public class BlockPos {
@Override
public boolean equals(Object obj) {
if (obj instanceof BlockPos) {
BlockPos pos = (BlockPos) obj;
if (obj instanceof BlockPos pos) {
return pos.x == x && pos.y == y && pos.z == z && Objects.equals(pos.w, w);
}
return false;
@@ -301,7 +301,7 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable
toStore.setStackSize(-toStore.getStackSize());
FluidStack canExtract = this.tanks.drain(slot, toStore.getFluidStack(), false);
if (canExtract != null && (long) canExtract.amount == toStore.getStackSize()) {
IAEFluidStack notStored = dest.injectItems(toStore, Actionable.MODULATE, this.mySource);;
IAEFluidStack notStored = dest.injectItems(toStore, Actionable.MODULATE, this.mySource);
toStore.setStackSize(toStore.getStackSize() - (notStored == null ? 0L : notStored.getStackSize()));
if (toStore.getStackSize() > 0L) {
changed = true;
@@ -141,7 +141,7 @@ public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<
@Override
public boolean equals(Object obj) {
// ae2 null-checks the pattern stack here for some reason, but doesn't null-check in hashCode()
// this is inconsistent, so i've just decided to assert non-null in the constructor, which is to say that
// this is inconsistent, so I've just decided to assert non-null in the constructor, which is to say that
// the pattern stack can never be null here
return obj instanceof FluidPatternDetails && patternStackAe.equals(((FluidPatternDetails) obj).patternStackAe);
}
@@ -16,7 +16,7 @@ import appeng.util.Platform;
public class FluidSorters {
private static SortDir Direction = SortDir.ASCENDING;
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_MOD = new Comparator<IAEItemStack>() {
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_MOD = new Comparator<>() {
@Override
public int compare(final IAEItemStack o1, final IAEItemStack o2) {
@@ -44,18 +44,14 @@ public class FluidSorters {
}
return Platform.getItemDisplayName(o2).compareToIgnoreCase(Platform.getItemDisplayName(o1));
};
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_SIZE = new Comparator<IAEItemStack>() {
@Override
public int compare(final IAEItemStack o1, final IAEItemStack o2) {
if (getDirection() == SortDir.ASCENDING) {
return compareLong(o2.getStackSize(), o1.getStackSize());
}
return compareLong(o1.getStackSize(), o2.getStackSize());
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_SIZE = (o1, o2) -> {
if (getDirection() == SortDir.ASCENDING) {
return compareLong(o2.getStackSize(), o1.getStackSize());
}
return compareLong(o1.getStackSize(), o2.getStackSize());
};
private static IInvTweaks api;
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_INV_TWEAKS = new Comparator<IAEItemStack>() {
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_INV_TWEAKS = new Comparator<>() {
@Override
public int compare(final IAEItemStack o1, final IAEItemStack o2) {
@@ -23,9 +23,8 @@ public class ObjectArrayIterator<E> implements /* Resettable */ Iterator<E> {
/** The end index to loop to */
final int endIndex;
/** The current iterator index */
int index = 0;
int index;
// -------------------------------------------------------------------------
/**
* Constructs an ObjectArrayIterator that will iterate over the values in the specified array.
*
@@ -46,7 +45,7 @@ public class ObjectArrayIterator<E> implements /* Resettable */ Iterator<E> {
* @throws NullPointerException if <code>array</code> is <code>null</code>
* @throws IndexOutOfBoundsException if the start index is out of bounds
*/
public ObjectArrayIterator(final E array[], final int start) {
public ObjectArrayIterator(final E[] array, final int start) {
this(array, start, array.length);
}
@@ -60,7 +59,7 @@ public class ObjectArrayIterator<E> implements /* Resettable */ Iterator<E> {
* @throws IllegalArgumentException if end index is before the start
* @throws NullPointerException if <code>array</code> is <code>null</code>
*/
public ObjectArrayIterator(final E array[], final int start, final int end) {
public ObjectArrayIterator(final E[] array, final int start, final int end) {
super();
if (start < 0) {
throw new ArrayIndexOutOfBoundsException("Start index must not be less than zero");
@@ -80,8 +79,7 @@ public class ObjectArrayIterator<E> implements /* Resettable */ Iterator<E> {
this.index = start;
}
// Iterator interface
// -------------------------------------------------------------------------
// region Iterator interface
/**
* Returns true if there are more elements to return from the array.
@@ -101,7 +99,7 @@ public class ObjectArrayIterator<E> implements /* Resettable */ Iterator<E> {
*/
@Override
public E next() {
if (hasNext() == false) {
if (!hasNext()) {
throw new NoSuchElementException();
}
return this.array[this.index++];
@@ -116,9 +114,9 @@ public class ObjectArrayIterator<E> implements /* Resettable */ Iterator<E> {
public void remove() {
throw new UnsupportedOperationException("remove() method is not supported for an ObjectArrayIterator");
}
// endregion
// Properties
// -------------------------------------------------------------------------
// region Properties
/**
* Gets the array that this iterator is iterating over.
@@ -147,6 +145,8 @@ public class ObjectArrayIterator<E> implements /* Resettable */ Iterator<E> {
return this.endIndex;
}
// endregion
/**
* Resets the iterator back to the start index.
*/
@@ -300,7 +300,6 @@ public final class Util {
}
public static IAEFluidStack loadFluidStackFromNBT(final NBTTagCompound i) {
// Fuck ae2
final FluidStack t = FluidRegistry.getFluidStack(i.getString("FluidName"), 1);
if (t == null) return null;
final AEFluidStack fluid = AEFluidStack.create(t);
@@ -503,8 +502,7 @@ public final class Util {
public static int getCapacity(ItemStack itemStack, Fluid fluid) {
if (itemStack == null) return 0;
Item item = itemStack.getItem();
if (item instanceof IFluidContainerItem) {
IFluidContainerItem fluidContainerItem = (IFluidContainerItem) item;
if (item instanceof IFluidContainerItem fluidContainerItem) {
int capacity = fluidContainerItem.getCapacity(itemStack);
FluidStack existing = fluidContainerItem.getFluid(itemStack);
if (existing != null) {