@Test public void testGetItemAmount() { final Item item = MockFactory.mockItem(1, 1); final Item item2 = MockFactory.mockItem(1, 1000); inventory.addItem(item); assertEquals(1, inventory.getItemAmount(item)); inventory.addItem(item2); assertEquals(1001, inventory.getItemAmount(item)); }
@Override public int getItemAmount(Item item) { int amount = 0; int id = item.getId(); for (Item i : inventory){ if (i != null && id == i.getId()){ amount += i.getAmount(); } } return amount; }
InventoryImpl implements Inventory { @Override public int getItemAmount(Item item) { int amount = 0; int id = item.getId(); for (Item i : inventory){ if (i != null && id == i.getId()){ amount += i.getAmount(); } } return amount; } }
InventoryImpl implements Inventory { @Override public int getItemAmount(Item item) { int amount = 0; int id = item.getId(); for (Item i : inventory){ if (i != null && id == i.getId()){ amount += i.getAmount(); } } return amount; } InventoryImpl();  InventoryImpl(int slots);  InventoryImpl(Item[] inventory); }
InventoryImpl implements Inventory { @Override public int getItemAmount(Item item) { int amount = 0; int id = item.getId(); for (Item i : inventory){ if (i != null && id == i.getId()){ amount += i.getAmount(); } } return amount; } InventoryImpl();  InventoryImpl(int slots);  InventoryImpl(Item[] inventory); @Override int addItem(final Item item); @Override Item getItem(int slot); @Override boolean hasFreeSlots(); @Override int hasItem(Item item); @Override Item removeItem(int slot); @Override Item removeItem(Item item); @Override Item removeItem(int slot, int amount); @Override int getCapacity(); @Override int getItemAmount(Item item); @Override void cleanup(); @Override void setCapacity(int capacity); @Override Iterator<Item> iterator(); }
InventoryImpl implements Inventory { @Override public int getItemAmount(Item item) { int amount = 0; int id = item.getId(); for (Item i : inventory){ if (i != null && id == i.getId()){ amount += i.getAmount(); } } return amount; } InventoryImpl();  InventoryImpl(int slots);  InventoryImpl(Item[] inventory); @Override int addItem(final Item item); @Override Item getItem(int slot); @Override boolean hasFreeSlots(); @Override int hasItem(Item item); @Override Item removeItem(int slot); @Override Item removeItem(Item item); @Override Item removeItem(int slot, int amount); @Override int getCapacity(); @Override int getItemAmount(Item item); @Override void cleanup(); @Override void setCapacity(int capacity); @Override Iterator<Item> iterator();  }