package cactusServer.entities; public class Item { private String name; private int amount; public Item(String name, int amount) { this.name = name; this.amount = amount; } public String getName() { return name; } public int getAmount() { return amount; } public boolean isEmpty() { return (amount == 0); } 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; } }