Advertisement
nikeza

Untitled

Dec 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. @Override
  2.     public String craftPresent(String presentName) {
  3.  
  4.         String message = "";
  5.         int count = 0;
  6.         Present present = this.presents.findByName(presentName);
  7.  
  8.         if (present != null) {
  9.             List<Dwarf> dwarfList = this.dwarfs.getModels().stream()
  10.                     .filter(f -> f.getEnergy() > 50)
  11.                     .collect(Collectors.toList());
  12.  
  13.             if (dwarfList.isEmpty()) {
  14.                 throw new IllegalArgumentException(ExceptionMessages.NO_DWARF_READY);
  15.             }
  16.             for (Dwarf dwarf : dwarfList) {
  17.                 Workshop workshop = new WorkshopImpl();
  18.                 workshop.craft(present, dwarf);
  19.  
  20.                 long count1 = dwarf.getInstruments().stream()
  21.                         .filter(Instrument::isBroken).count();
  22.  
  23.                 if (present.isDone()) {
  24.                     message = String.format("Present %s is done. %d instrument/s have been broken while working on it!", presentName, count1);
  25.                     countCrafted++;
  26.                    
  27.                 } else {
  28.                     message = String.format("Present %s is not done. %d instrument/s have been broken while working on it!", presentName, count1);
  29.                 }
  30.             }
  31.         }
  32.  
  33.         return message;
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement