Skip to content

Commit

Permalink
Style/codacity style fixes (#2078)
Browse files Browse the repository at this point in the history
* Fixes one exception
Code cleanup
  • Loading branch information
Raycoms authored Jan 23, 2018
1 parent 3f544ff commit 3b66f10
Show file tree
Hide file tree
Showing 102 changed files with 463 additions and 463 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public <INPUT, OUTPUT> IFactory<INPUT, OUTPUT> getFactoryForIO(@NotNull final Ty
}

Log.getLogger().debug("Found matching Factory for Primary input type.");
for (IFactory factory : factories)
for (final IFactory factory : factories)
{
final Set<TypeToken> secondaryOutputSet = ReflectionUtils.getSuperClasses(factory.getFactoryOutputType());
if (secondaryOutputSet.contains(output))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public interface IFactoryController
{
return getFactoryForInput((TypeToken<? extends Input>) TypeToken.of(Class.forName(className)));
}
catch (IllegalArgumentException ex)
catch (final IllegalArgumentException ex)
{
throw ex;
}
catch (Exception ex)
catch (final Exception ex)
{
throw new IllegalArgumentException("The given input name is unknown", ex);
}
Expand Down Expand Up @@ -82,11 +82,11 @@ default <Output> IFactory<?, Output> getFactoryForOutput(@NotNull final String c
{
return getFactoryForOutput((TypeToken<? extends Output>) TypeToken.of(Class.forName(className)));
}
catch (IllegalArgumentException ex)
catch (final IllegalArgumentException ex)
{
throw ex;
}
catch (Exception ex)
catch (final Exception ex)
{
throw new IllegalArgumentException("The given output name is unknown", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ default R getNewInstance(@NotNull final IFactoryController factoryController, @N

if (context.length == NUMBER_OF_PROPERTIES)
{
IRequester requester = (IRequester) context[1];
IToken token = (IToken) context[0];
final IRequester requester = (IRequester) context[1];
final IToken token = (IToken) context[0];

return this.getNewInstance(t, requester, token);
}
Expand All @@ -61,9 +61,9 @@ default R getNewInstance(@NotNull final IFactoryController factoryController, @N
throw new IllegalArgumentException("Unsupported context - Third context object is not a request state");
}

IRequester requester = (IRequester) context[1];
IToken token = (IToken) context[0];
RequestState state = (RequestState) context[2];
final IRequester requester = (IRequester) context[1];
final IToken token = (IToken) context[0];
final RequestState state = (RequestState) context[2];

return this.getNewInstance(t, requester, token, state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public Burnable(final int count, @NotNull final ItemStack result)
this.result = result;
}

public static NBTTagCompound serialize(IFactoryController controller, Burnable food)
public static NBTTagCompound serialize(final IFactoryController controller, final Burnable food)
{
NBTTagCompound compound = new NBTTagCompound();
final NBTTagCompound compound = new NBTTagCompound();
compound.setInteger(NBT_COUNT, food.count);

if (!ItemStackUtils.isEmpty(food.result))
Expand All @@ -44,10 +44,10 @@ public static NBTTagCompound serialize(IFactoryController controller, Burnable f
return compound;
}

public static Burnable deserialize(IFactoryController controller, NBTTagCompound compound)
public static Burnable deserialize(final IFactoryController controller, final NBTTagCompound compound)
{
int count = compound.getInteger(NBT_COUNT);
ItemStack result = compound.hasKey(NBT_RESULT) ? ItemStackUtils.deserializeFromNBT(compound.getCompoundTag(NBT_RESULT)) : ItemStackUtils.EMPTY;
final int count = compound.getInteger(NBT_COUNT);
final ItemStack result = compound.hasKey(NBT_RESULT) ? ItemStackUtils.deserializeFromNBT(compound.getCompoundTag(NBT_RESULT)) : ItemStackUtils.EMPTY;

return new Burnable(count, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public Food(final int count, final ItemStack result)
this.result = result;
}

public static NBTTagCompound serialize(IFactoryController controller, Food food)
public static NBTTagCompound serialize(final IFactoryController controller, final Food food)
{
NBTTagCompound compound = new NBTTagCompound();
final NBTTagCompound compound = new NBTTagCompound();
compound.setInteger(NBT_COUNT, food.count);

if (!ItemStackUtils.isEmpty(food.result))
Expand All @@ -44,10 +44,10 @@ public static NBTTagCompound serialize(IFactoryController controller, Food food)
return compound;
}

public static Food deserialize(IFactoryController controller, NBTTagCompound compound)
public static Food deserialize(final IFactoryController controller, final NBTTagCompound compound)
{
int count = compound.getInteger(NBT_COUNT);
ItemStack result = compound.hasKey(NBT_RESULT) ? ItemStackUtils.deserializeFromNBT(compound.getCompoundTag(NBT_RESULT)) : ItemStackUtils.EMPTY;
final int count = compound.getInteger(NBT_COUNT);
final ItemStack result = compound.hasKey(NBT_RESULT) ? ItemStackUtils.deserializeFromNBT(compound.getCompoundTag(NBT_RESULT)) : ItemStackUtils.EMPTY;

return new Food(count, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Stack implements IDeliverable
////// --------------------------- NBTConstants --------------------------- \\\\\\

@NotNull
private final ItemStack stack;
private final ItemStack theStack;

@NotNull
private boolean matchMeta = false;
Expand All @@ -35,17 +35,43 @@ public class Stack implements IDeliverable
@NotNull
private ItemStack result = ItemStackUtils.EMPTY;

/**
* Create a Stack deliverable.
* @param stack the required stack.
*/
public Stack(@NotNull final ItemStack stack)
{
this.theStack = stack.copy();

if (ItemStackUtils.isEmpty(stack))
{
throw new IllegalArgumentException("Cannot deliver Empty Stack.");
}

setMatchMeta(true).setMatchNBT(true);
this.theStack.setCount(Math.min(this.theStack.getCount(), this.theStack.getMaxStackSize()));
}

this.stack = stack.copy();
this.stack.setCount(Math.min(this.stack.getCount(), this.stack.getMaxStackSize()));
/**
* Create a Stack deliverable.
* @param stack the required stack.
* @param matchMeta if meta has to be matched.
* @param matchNBT if NBT has to be matched.
* @param matchOreDic if the oredict has to be matched.
* @param result the result stack.
*/
public Stack(
@NotNull final ItemStack stack,
@NotNull final boolean matchMeta,
@NotNull final boolean matchNBT,
@NotNull final boolean matchOreDic,
@NotNull final ItemStack result)
{
this.theStack = stack;
this.matchMeta = matchMeta;
this.matchNBT = matchNBT;
this.matchOreDic = matchOreDic;
this.result = result;
}

public Stack setMatchNBT(final boolean match)
Expand All @@ -60,24 +86,16 @@ public Stack setMatchMeta(final boolean match)
return this;
}

public Stack(
@NotNull final ItemStack stack,
@NotNull final boolean matchMeta,
@NotNull final boolean matchNBT,
@NotNull final boolean matchOreDic,
@NotNull final ItemStack result)
{
this.stack = stack;
this.matchMeta = matchMeta;
this.matchNBT = matchNBT;
this.matchOreDic = matchOreDic;
this.result = result;
}

public static NBTTagCompound serialize(IFactoryController controller, Stack input)
/**
* Serialize the deliverable.
* @param controller the controller.
* @param input the input.
* @return the compound.
*/
public static NBTTagCompound serialize(final IFactoryController controller, final Stack input)
{
NBTTagCompound compound = new NBTTagCompound();
compound.setTag(NBT_STACK, input.stack.serializeNBT());
final NBTTagCompound compound = new NBTTagCompound();
compound.setTag(NBT_STACK, input.theStack.serializeNBT());
compound.setBoolean(NBT_MATCHMETA, input.matchMeta);
compound.setBoolean(NBT_MATCHNBT, input.matchNBT);
compound.setBoolean(NBT_MATCHOREDIC, input.matchOreDic);
Expand All @@ -90,13 +108,19 @@ public static NBTTagCompound serialize(IFactoryController controller, Stack inpu
return compound;
}

public static Stack deserialize(IFactoryController controller, NBTTagCompound compound)
/**
* Deserialize the deliverable.
* @param controller the controller.
* @param compound the compound.
* @return the deliverable.
*/
public static Stack deserialize(final IFactoryController controller, final NBTTagCompound compound)
{
ItemStack stack = ItemStackUtils.deserializeFromNBT(compound.getCompoundTag(NBT_STACK));
boolean matchMeta = compound.getBoolean(NBT_MATCHMETA);
boolean matchNBT = compound.getBoolean(NBT_MATCHNBT);
boolean matchOreDic = compound.getBoolean(NBT_MATCHOREDIC);
ItemStack result = compound.hasKey(NBT_RESULT) ? ItemStackUtils.deserializeFromNBT(compound.getCompoundTag(NBT_RESULT)) : ItemStackUtils.EMPTY;
final ItemStack stack = ItemStackUtils.deserializeFromNBT(compound.getCompoundTag(NBT_STACK));
final boolean matchMeta = compound.getBoolean(NBT_MATCHMETA);
final boolean matchNBT = compound.getBoolean(NBT_MATCHNBT);
final boolean matchOreDic = compound.getBoolean(NBT_MATCHOREDIC);
final ItemStack result = compound.hasKey(NBT_RESULT) ? ItemStackUtils.deserializeFromNBT(compound.getCompoundTag(NBT_RESULT)) : ItemStackUtils.EMPTY;

return new Stack(stack, matchMeta, matchNBT, matchOreDic, result);
}
Expand All @@ -115,13 +139,13 @@ public boolean matches(@NotNull final ItemStack stack)
@Override
public int getCount()
{
return stack.getCount();
return theStack.getCount();
}

@NotNull
public ItemStack getStack()
{
return stack;
return theStack;
} @Override
public void setResult(@NotNull final ItemStack result)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public Tool(@NotNull final IToolType toolClass, @NotNull final Integer minLevel,
* @return The NBTTagCompound containing the tool data.
*/
@NotNull
public static NBTTagCompound serialize(IFactoryController controller, Tool tool)
public static NBTTagCompound serialize(final IFactoryController controller, final Tool tool)
{
NBTTagCompound compound = new NBTTagCompound();
final NBTTagCompound compound = new NBTTagCompound();

compound.setString(NBT_TYPE, tool.getToolClass().getName());
compound.setInteger(NBT_MIN_LEVEL, tool.getMinLevel());
Expand Down Expand Up @@ -119,13 +119,13 @@ public ItemStack getResult()
* @return An instance of Tool with the data contained in the given NBT.
*/
@NotNull
public static Tool deserialize(IFactoryController controller, NBTTagCompound nbt)
public static Tool deserialize(final IFactoryController controller, final NBTTagCompound nbt)
{
//API:Map the given strings a proper way.
IToolType type = ToolType.getToolType(nbt.getString(NBT_TYPE));
Integer minLevel = nbt.getInteger(NBT_MIN_LEVEL);
Integer maxLevel = nbt.getInteger(NBT_MAX_LEVEL);
ItemStack result = new ItemStack(nbt.getCompoundTag(NBT_RESULT));
final IToolType type = ToolType.getToolType(nbt.getString(NBT_TYPE));
final Integer minLevel = nbt.getInteger(NBT_MIN_LEVEL);
final Integer maxLevel = nbt.getInteger(NBT_MAX_LEVEL);
final ItemStack result = new ItemStack(nbt.getCompoundTag(NBT_RESULT));

return new Tool(type, minLevel, maxLevel, result);
}
Expand All @@ -134,7 +134,7 @@ public static Tool deserialize(IFactoryController controller, NBTTagCompound nbt
public boolean matches(@NotNull final ItemStack stack)
{
//API:Map the given strings a proper way.
boolean toolTypeResult = !ItemStackUtils.isEmpty(stack)
final boolean toolTypeResult = !ItemStackUtils.isEmpty(stack)
&& stack.getCount() >= 1
&& getToolClasses(stack).stream()
.filter(s -> getToolClass().getName().equalsIgnoreCase(s))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private void discoverSaplings()
{
if (saps.getHasSubtypes())
{
for(CreativeTabs tabs: CreativeTabs.CREATIVE_TAB_ARRAY)
for(final CreativeTabs tabs: CreativeTabs.CREATIVE_TAB_ARRAY)
{
final NonNullList<ItemStack> list = NonNullList.create();
saps.getItem().getSubItems(tabs, list);
Expand Down
12 changes: 6 additions & 6 deletions src/api/java/com/minecolonies/api/crafting/ItemStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ItemStorage
/**
* Set this to ignore the damage value in comparisons.
*/
private final boolean ignoreDamageValue;
private final boolean shouldIgnoreDamageValue;

/**
* Amount of the storage.
Expand All @@ -38,7 +38,7 @@ public class ItemStorage
public ItemStorage(@NotNull final ItemStack stack, final int amount, final boolean ignoreDamageValue)
{
this.stack = stack;
this.ignoreDamageValue = ignoreDamageValue;
this.shouldIgnoreDamageValue = ignoreDamageValue;
this.amount = amount;
}

Expand All @@ -51,7 +51,7 @@ public ItemStorage(@NotNull final ItemStack stack, final int amount, final boole
public ItemStorage(@NotNull final ItemStack stack, final boolean ignoreDamageValue)
{
this.stack = stack;
this.ignoreDamageValue = ignoreDamageValue;
this.shouldIgnoreDamageValue = ignoreDamageValue;
this.amount = ItemStackUtils.getSize(stack);
}

Expand All @@ -63,7 +63,7 @@ public ItemStorage(@NotNull final ItemStack stack, final boolean ignoreDamageVal
public ItemStorage(@NotNull final ItemStack stack)
{
this.stack = stack;
this.ignoreDamageValue = false;
this.shouldIgnoreDamageValue = false;
this.amount = ItemStackUtils.getSize(stack);
}

Expand Down Expand Up @@ -123,7 +123,7 @@ public void setAmount(final int amount)
*/
public boolean ignoreDamageValue()
{
return ignoreDamageValue;
return shouldIgnoreDamageValue;
}

@Override
Expand All @@ -147,7 +147,7 @@ public boolean equals(final Object o)
final ItemStorage that = (ItemStorage) o;


return getItem().equals(that.getItem()) && (this.ignoreDamageValue || that.getDamageValue() == this.getDamageValue());
return getItem().equals(that.getItem()) && (this.shouldIgnoreDamageValue || that.getDamageValue() == this.getDamageValue());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/api/java/com/minecolonies/api/util/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ public static int transferXOfFirstSlotInProviderWithIntoNextFreeSlotInProviderWi
{
int currentAmount = amount;

for(IItemHandler handler : getItemHandlersFromProvider(targetProvider))
for(final IItemHandler handler : getItemHandlersFromProvider(targetProvider))
{
currentAmount = transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandlerWithResult(sourceProvider, itemStackSelectionPredicate, amount, handler);

Expand All @@ -1419,7 +1419,7 @@ public static int transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandle
@NotNull final int amount, @NotNull final IItemHandler targetHandler)
{
int currentAmount = amount;
for (IItemHandler handler : getItemHandlersFromProvider(sourceProvider))
for (final IItemHandler handler : getItemHandlersFromProvider(sourceProvider))
{
currentAmount = transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandlerWithResult(handler, itemStackSelectionPredicate, currentAmount, targetHandler);

Expand Down
6 changes: 1 addition & 5 deletions src/api/java/com/minecolonies/api/util/ItemStackUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ else if (entity instanceof EntityArmorStand)
entity.getArmorInventoryList().forEach(request::add);
entity.getHeldEquipment().forEach(request::add);
}
else if (entity instanceof EntityMob)
{
//Don't try to request the monster.
}
else
else if (!(entity instanceof EntityMob))
{
request.add(entity.getPickedResult(new RayTraceResult(placer)));
}
Expand Down
Loading

0 comments on commit 3b66f10

Please sign in to comment.