@Test public void testCountDuplicateNewInstance() { int amount = 16; ItemStack itemA = new ItemStack(Material.APPLE, amount); ItemStack itemB = new ItemStack(Material.APPLE, amount * 2); Inventory inv = mock(Inventory.class); when(inv.getContents()).thenReturn(new ItemStack[] {itemA, itemB}); assertTrue(itemA.isSimilar(itemB)); Assert.assertEquals(amount * 3, InventoryUtil.count(inv, itemA)); }
public static int count(@NotNull Inventory inv, @NotNull ItemStack item) { int amount = 0; for (ItemStack invItem : inv.getContents()) { if (item.isSimilar(invItem)) { amount += invItem.getAmount(); } } return amount; }
InventoryUtil { public static int count(@NotNull Inventory inv, @NotNull ItemStack item) { int amount = 0; for (ItemStack invItem : inv.getContents()) { if (item.isSimilar(invItem)) { amount += invItem.getAmount(); } } return amount; } }
InventoryUtil { public static int count(@NotNull Inventory inv, @NotNull ItemStack item) { int amount = 0; for (ItemStack invItem : inv.getContents()) { if (item.isSimilar(invItem)) { amount += invItem.getAmount(); } } return amount; }  }
InventoryUtil { public static int count(@NotNull Inventory inv, @NotNull ItemStack item) { int amount = 0; for (ItemStack invItem : inv.getContents()) { if (item.isSimilar(invItem)) { amount += invItem.getAmount(); } } return amount; }  @SuppressWarnings("deprecation") static void removeInvItem(@NotNull final Inventory inv, @NotNull final Material type, final int amount,
                                     final MaterialData data); static void removeInvItem(final Inventory inv, final ItemStack item, final boolean matOnly); static void removeInvItem(@NotNull final Inventory inv, @NotNull final ItemStack item); static void removeInvMat(@NotNull final Inventory inv, @NotNull final Material material, final int amount); static boolean contains(@Nullable final Inventory inv, @Nullable final ItemStack item, int amount); static int getTotalItems(final Inventory inv, final Material type); static int countItems(@NotNull final Player player, final Material material); static int countItems(@NotNull final Player player, final Material material, final short damageValue); static int count(@NotNull Inventory inv, @NotNull ItemStack item); @SuppressWarnings("deprecation") static boolean canHold(@NotNull final Player player, final ItemStack item); static boolean canHold(final Player player, @NotNull final Material material, final byte data,
                                  final int quantity); static int emptySlots(final Inventory inv); @NotNull static ItemStack getPlayerSkull(@NotNull final OfflinePlayer player); static ItemStack[] getPlayerArmor(@Nullable Inventory inv); }
InventoryUtil { public static int count(@NotNull Inventory inv, @NotNull ItemStack item) { int amount = 0; for (ItemStack invItem : inv.getContents()) { if (item.isSimilar(invItem)) { amount += invItem.getAmount(); } } return amount; }  @SuppressWarnings("deprecation") static void removeInvItem(@NotNull final Inventory inv, @NotNull final Material type, final int amount,
                                     final MaterialData data); static void removeInvItem(final Inventory inv, final ItemStack item, final boolean matOnly); static void removeInvItem(@NotNull final Inventory inv, @NotNull final ItemStack item); static void removeInvMat(@NotNull final Inventory inv, @NotNull final Material material, final int amount); static boolean contains(@Nullable final Inventory inv, @Nullable final ItemStack item, int amount); static int getTotalItems(final Inventory inv, final Material type); static int countItems(@NotNull final Player player, final Material material); static int countItems(@NotNull final Player player, final Material material, final short damageValue); static int count(@NotNull Inventory inv, @NotNull ItemStack item); @SuppressWarnings("deprecation") static boolean canHold(@NotNull final Player player, final ItemStack item); static boolean canHold(final Player player, @NotNull final Material material, final byte data,
                                  final int quantity); static int emptySlots(final Inventory inv); @NotNull static ItemStack getPlayerSkull(@NotNull final OfflinePlayer player); static ItemStack[] getPlayerArmor(@Nullable Inventory inv);  }