Advertisement
xickoh

addItem

Nov 25th, 2020
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. public boolean addItem(IItem item, IPosition position, Color color) throws ContainerException {
  2.         boolean added = false;
  3.         if (item != null && position != null) {
  4.             if (this.closed) {
  5.                 throw new ContainerImplException("The container definition is invalid!");
  6.             } else {
  7.                 if (this.find(item) == -1) {
  8.                     if (this.itemsPackedCounter == this.itemsPacked.length) {
  9.                         ItemPacked[] itemsPacked_temp = new ItemPacked[this.itemsPacked.length * 2];
  10.  
  11.                         for(int i = 0; i < this.itemsPacked.length; ++i) {
  12.                             itemsPacked_temp[i] = this.itemsPacked[i];
  13.                         }
  14.  
  15.                         this.itemsPacked = itemsPacked_temp;
  16.                     }
  17.  
  18.                     this.occupiedVolume += item.getVolume();
  19.                     this.itemsPacked[this.itemsPackedCounter++] = new ItemPacked(item, position, color);
  20.                     added = true;
  21.                 }
  22.  
  23.                 return added;
  24.             }
  25.         } else {
  26.             throw new ContainerImplException("The container definition is invalid!");
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement