Advertisement
Azamatik

Untitled

Dec 23rd, 2022
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | Source Code | 0 0
  1. @Override
  2. public Skill update(Skill skill) {
  3.     List<Skill> currentSkills = this.service.getItemsFromFile(Skill.class);
  4.     AtomicBoolean wasUpdated = new AtomicBoolean(false);
  5.  
  6.     currentSkills = currentSkills.stream()
  7.         .map(s -> {
  8.             if (Objects.equals(s.getId(), skill.getId())) {
  9.                 wasUpdated.set(true);
  10.                 return skill;
  11.             }
  12.             return s;
  13.         })
  14.         .collect(Collectors.toList());
  15.  
  16.     this.service.addItemsToFile(currentSkills);
  17.     return wasUpdated.get() ? skill : null;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement