ICollection.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package cz.davza.studentadventure.interfaces;
  2. import cz.davza.studentadventure.objects.ItemStack;
  3. /**
  4. * Contract for a fixed-size, slot-based item collection.
  5. *
  6. * <p>Implementations manage a collection of {@link ItemStack} entries, keyed by item code.
  7. * Items are stacked automatically up to their {@link IItem#getBulk()} limit,
  8. * and any items that cannot fit are returned as a leftover count from {@link #Add}.</p>
  9. *
  10. * <p>Used by both {@link cz.davza.studentadventure.objects.PlayerInventory} and
  11. * {@link cz.davza.studentadventure.objects.RoomItems}.</p>
  12. *
  13. * @param <T> the type of item this collection holds, must extend {@link IItem}
  14. *
  15. * @see cz.davza.studentadventure.base.ItemCollectionBase
  16. * @see ItemStack
  17. */
  18. public interface ICollection<T> {
  19. /**
  20. * Adds the specified quantity of an item to the collection.
  21. *
  22. * <p>The method first attempts to top up any existing stacks of the same item
  23. * code, then fills empty slots with new stacks. Items that cannot fit due to
  24. * capacity limits are returned as a remainder.</p>
  25. *
  26. * @param item the item to add
  27. * @param count the number of items to add
  28. * @return the number of items that could not be added (0 if all were added)
  29. */
  30. int Add(T item, int count);
  31. /**
  32. * Removes a specified number of items from the slot at the given index.
  33. *
  34. * <p>If {@code count} is greater than or equal to the stack size, the slot
  35. * is cleared entirely. If the index is out of bounds or the slot is empty,
  36. * the call is silently ignored.</p>
  37. *
  38. * @param code the items code
  39. * @param count the number of items to remove
  40. */
  41. void Remove(String code, int count);
  42. /**
  43. * Returns the overall capacity the collection can hold
  44. *
  45. * @return Collections bulk capacity
  46. */
  47. int GetCapacity();
  48. /**
  49. * Empties collection of all items and resets used capacity
  50. */
  51. void Empty();
  52. /**
  53. * Returns the remaining capacity of the collection
  54. *
  55. * @return Collections remaining bulk capacity (how much can still be added)
  56. */
  57. int GetRemainingCapacity();
  58. }