Added checks for null and equal class to .equals()

Also switched a check for null in OreHelper#sameOre to prevent null ==
null => true
This commit is contained in:
yueh 2014-09-29 12:39:40 +02:00
parent 640d888d13
commit fd7c1ff5f8
8 changed files with 63 additions and 27 deletions

View file

@ -53,8 +53,12 @@ public class GuiImgButton extends GuiButton implements ITooltip
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
EnumPair d = (EnumPair) obj; if ( obj == null )
return d.setting.equals( setting ) && d.value.equals( value ); return false;
if ( getClass() != obj.getClass() )
return false;
EnumPair other = (EnumPair) obj;
return other.setting.equals( setting ) && other.value.equals( value );
} }
} }

View file

@ -48,11 +48,13 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
final int ref; final int ref;
final int hash; final int hash;
public TestLookup(int slot, ItemStack i) { public TestLookup(int slot, ItemStack i)
{
this( slot, i.getItem(), i.getItemDamage() ); 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; this.slot = slot;
ref = (dmg << Platform.DEF_OFFSET) | (Item.getIdFromItem( item ) & 0xffff); ref = (dmg << Platform.DEF_OFFSET) | (Item.getIdFromItem( item ) & 0xffff);
int offset = 3 * slot; int offset = 3 * slot;
@ -110,7 +112,8 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
return TestStatus.TEST; return TestStatus.TEST;
} }
public PatternHelper(ItemStack is, World w) { public PatternHelper(ItemStack is, World w)
{
NBTTagCompound encodedValue = is.getTagCompound(); NBTTagCompound encodedValue = is.getTagCompound();
if ( encodedValue == null ) if ( encodedValue == null )
@ -338,7 +341,14 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
@Override @Override
public boolean equals(Object obj) 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 @Override
@ -348,7 +358,8 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
} }
@Override @Override
public int getPriority() { public int getPriority()
{
return priority; return priority;
} }
} }

View file

@ -38,8 +38,12 @@ public class CompassManager
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
CompassRequest b = (CompassRequest) obj; if ( obj == null )
return attunement == b.attunement && cx == b.cx && cdy == b.cdy && cz == b.cz; 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;
} }
} }

View file

@ -54,7 +54,12 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
@Override @Override
public boolean equals(Object obj) 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;
} }
} }

View file

@ -22,10 +22,11 @@ public class GridStorageSearch
{ {
if ( obj == null ) if ( obj == null )
return false; return false;
if ( getClass() != obj.getClass() )
return false;
GridStorageSearch b = (GridStorageSearch) obj; GridStorageSearch other = (GridStorageSearch) obj;
if ( id == other.id )
if ( id == b.id )
return true; return true;
return false; return false;

View file

@ -60,8 +60,12 @@ public class AEItemDef
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
AEItemDef def = (AEItemDef) obj; if ( obj == null )
return def.damageValue == damageValue && def.item == item && tagCompound == def.tagCompound; 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) public int getDamageValueHack(ItemStack is)

View file

@ -16,7 +16,8 @@ public class OreHelper
class ItemRef class ItemRef
{ {
ItemRef(ItemStack stack) { ItemRef(ItemStack stack)
{
ref = stack.getItem(); ref = stack.getItem();
if ( stack.getItem().isDamageable() ) if ( stack.getItem().isDamageable() )
@ -32,10 +33,14 @@ public class OreHelper
int hash; int hash;
@Override @Override
public boolean equals(Object o) public boolean equals(Object obj)
{ {
ItemRef obj = (ItemRef) o; if ( obj == null )
return damage == obj.damage && ref == obj.ref; return false;
if ( getClass() != obj.getClass() )
return false;
ItemRef other = (ItemRef) obj;
return damage == other.damage && ref == other.ref;
} }
@Override @Override
@ -103,12 +108,12 @@ public class OreHelper
OreReference a = aeItemStack.def.isOre; OreReference a = aeItemStack.def.isOre;
OreReference b = aeItemStack.def.isOre; OreReference b = aeItemStack.def.isOre;
if ( a == b )
return true;
if ( a == null || b == null ) if ( a == null || b == null )
return false; return false;
if ( a == b )
return true;
Collection<Integer> bOres = b.getOres(); Collection<Integer> bOres = b.getOres();
for (Integer ore : a.getOres()) for (Integer ore : a.getOres())
{ {

View file

@ -23,10 +23,12 @@ public class SharedSearchObject
{ {
if ( obj == null ) if ( obj == null )
return false; return false;
SharedSearchObject b = (SharedSearchObject) obj; if ( getClass() != obj.getClass() )
if ( def == b.def && hash == b.hash ) 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; return false;
} }