package cactusServer.entities; import net.arnx.jsonic.JSONHint; public class Item extends Entity{ private String name; private int amount; @JSONHint(ignore = true) public static final int UNIQUE_ID_LENGTH = 12; private Item() { // JSONDecode時の呼び出し用 } public Item(String name, int amount) { setName(name); setAmount(amount); } public String getName() { return name; } public int getAmount() { return amount; } public boolean isEmpty() { return (amount == 0); } public void setName(String name) { this.name = name; } public void setAmount(int amount) { this.amount = amount; } public Item changeAmount(int amountOfChange) { amount = Math.max(amount + amountOfChange, 0); return this; } @Override public int hashCode() { int result = 17; result = result * 31 + name.hashCode(); return result; } @Override public boolean equals(java.lang.Object obj) { if (this == obj) { return true; } if (obj instanceof Item) { Item item = (Item)obj; if (this.name.equals(item.name)) { return true; // 同名のアイテムは等価 } } return false; } }