Merge pull request #188 from yueh/cleanup-code
Added checks for null and equal class to .equals()
This commit is contained in:
commit
35c00873c1
8 changed files with 63 additions and 27 deletions
|
@ -53,8 +53,12 @@ public class GuiImgButton extends GuiButton implements ITooltip
|
|||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
EnumPair d = (EnumPair) obj;
|
||||
return d.setting.equals( setting ) && d.value.equals( value );
|
||||
if ( obj == null )
|
||||
return false;
|
||||
if ( getClass() != obj.getClass() )
|
||||
return false;
|
||||
EnumPair other = (EnumPair) obj;
|
||||
return other.setting.equals( setting ) && other.value.equals( value );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,11 +48,13 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||
final int ref;
|
||||
final int hash;
|
||||
|
||||
public TestLookup(int slot, ItemStack i) {
|
||||
public TestLookup(int slot, ItemStack i)
|
||||
{
|
||||
this( slot, i.getItem(), i.getItemDamage() );
|
||||
}
|
||||
|
||||
public TestLookup(int slot, Item item, int dmg) {
|
||||
public TestLookup(int slot, Item item, int dmg)
|
||||
{
|
||||
this.slot = slot;
|
||||
ref = (dmg << Platform.DEF_OFFSET) | (Item.getIdFromItem( item ) & 0xffff);
|
||||
int offset = 3 * slot;
|
||||
|
@ -110,7 +112,8 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||
return TestStatus.TEST;
|
||||
}
|
||||
|
||||
public PatternHelper(ItemStack is, World w) {
|
||||
public PatternHelper(ItemStack is, World w)
|
||||
{
|
||||
NBTTagCompound encodedValue = is.getTagCompound();
|
||||
|
||||
if ( encodedValue == null )
|
||||
|
@ -191,10 +194,10 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||
else
|
||||
g.add( io );
|
||||
}
|
||||
|
||||
|
||||
if ( tmpOutputs.isEmpty() || tmpInputs.isEmpty() )
|
||||
throw new RuntimeException( "No pattern here!" );
|
||||
|
||||
|
||||
int offset = 0;
|
||||
condensedInputs = new IAEItemStack[tmpInputs.size()];
|
||||
for (IAEItemStack io : tmpInputs.values())
|
||||
|
@ -338,7 +341,14 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return pattern.equals( ((PatternHelper) obj).pattern );
|
||||
if ( obj == null )
|
||||
return false;
|
||||
if ( getClass() != obj.getClass() )
|
||||
return false;
|
||||
PatternHelper other = (PatternHelper) obj;
|
||||
if ( pattern != null && other.pattern != null )
|
||||
return pattern.equals( other.pattern );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -348,7 +358,8 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
public int getPriority()
|
||||
{
|
||||
return priority;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,12 @@ public class CompassManager
|
|||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
CompassRequest b = (CompassRequest) obj;
|
||||
return attunement == b.attunement && cx == b.cx && cdy == b.cdy && cz == b.cz;
|
||||
if ( obj == null )
|
||||
return false;
|
||||
if ( getClass() != obj.getClass() )
|
||||
return false;
|
||||
CompassRequest other = (CompassRequest) obj;
|
||||
return attunement == other.attunement && cx == other.cx && cdy == other.cdy && cz == other.cz;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,7 +54,12 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
|
|||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return blk == ((Combo) obj).blk && meta == ((Combo) obj).meta;
|
||||
if ( obj == null )
|
||||
return false;
|
||||
if ( getClass() != obj.getClass() )
|
||||
return false;
|
||||
Combo other = (Combo) obj;
|
||||
return blk == other.blk && meta == other.meta;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,10 +22,11 @@ public class GridStorageSearch
|
|||
{
|
||||
if ( obj == null )
|
||||
return false;
|
||||
if ( getClass() != obj.getClass() )
|
||||
return false;
|
||||
|
||||
GridStorageSearch b = (GridStorageSearch) obj;
|
||||
|
||||
if ( id == b.id )
|
||||
GridStorageSearch other = (GridStorageSearch) obj;
|
||||
if ( id == other.id )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
|
@ -60,8 +60,12 @@ public class AEItemDef
|
|||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
AEItemDef def = (AEItemDef) obj;
|
||||
return def.damageValue == damageValue && def.item == item && tagCompound == def.tagCompound;
|
||||
if ( obj == null )
|
||||
return false;
|
||||
if ( getClass() != obj.getClass() )
|
||||
return false;
|
||||
AEItemDef other = (AEItemDef) obj;
|
||||
return other.damageValue == damageValue && other.item == item && tagCompound == other.tagCompound;
|
||||
}
|
||||
|
||||
public int getDamageValueHack(ItemStack is)
|
||||
|
|
|
@ -16,7 +16,8 @@ public class OreHelper
|
|||
class ItemRef
|
||||
{
|
||||
|
||||
ItemRef(ItemStack stack) {
|
||||
ItemRef(ItemStack stack)
|
||||
{
|
||||
ref = stack.getItem();
|
||||
|
||||
if ( stack.getItem().isDamageable() )
|
||||
|
@ -32,10 +33,14 @@ public class OreHelper
|
|||
int hash;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
ItemRef obj = (ItemRef) o;
|
||||
return damage == obj.damage && ref == obj.ref;
|
||||
if ( obj == null )
|
||||
return false;
|
||||
if ( getClass() != obj.getClass() )
|
||||
return false;
|
||||
ItemRef other = (ItemRef) obj;
|
||||
return damage == other.damage && ref == other.ref;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -103,12 +108,12 @@ public class OreHelper
|
|||
OreReference a = aeItemStack.def.isOre;
|
||||
OreReference b = aeItemStack.def.isOre;
|
||||
|
||||
if ( a == b )
|
||||
return true;
|
||||
|
||||
if ( a == null || b == null )
|
||||
return false;
|
||||
|
||||
if ( a == b )
|
||||
return true;
|
||||
|
||||
Collection<Integer> bOres = b.getOres();
|
||||
for (Integer ore : a.getOres())
|
||||
{
|
||||
|
|
|
@ -23,10 +23,12 @@ public class SharedSearchObject
|
|||
{
|
||||
if ( obj == null )
|
||||
return false;
|
||||
SharedSearchObject b = (SharedSearchObject) obj;
|
||||
if ( def == b.def && hash == b.hash )
|
||||
if ( getClass() != obj.getClass() )
|
||||
return false;
|
||||
SharedSearchObject other = (SharedSearchObject) obj;
|
||||
if ( def == other.def && hash == other.hash )
|
||||
{
|
||||
return Platform.NBTEqualityTest( compound, b.compound );
|
||||
return Platform.NBTEqualityTest( compound, other.compound );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue