Added a few null pointer checks and performed minor touchups (tried improving a few equals, clone and hashCode methods).

By: VictorD <victor.danell@gmail.com>
This commit is contained in:
Bukkit/Spigot
2011-03-05 12:27:51 +01:00
parent 5673661da0
commit bb755bb9a2
9 changed files with 51 additions and 16 deletions

View File

@@ -182,11 +182,19 @@ public class ItemStack {
}
@Override
public boolean equals(Object object) {
return false;
}
public boolean equals(ItemStack item) {
public boolean equals(Object obj) {
if (!(obj instanceof ItemStack))
return false;
ItemStack item = (ItemStack)obj;
return item.getAmount() == getAmount() && item.getTypeId() == getTypeId();
}
@Override
public int hashCode() {
int hash = 11;
hash = hash * 19 + 7 * getTypeId(); // Overriding hashCode since equals is overridden, it's just
hash = hash * 7 + 23 * getAmount(); // too bad these are mutable values... Q_Q
return hash;
}
}