Facebook
From Big Macaw, 9 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 616
  1. public Map<String, Double> getCeny(){
  2.         ceny = new HashMap<>();
  3.         for(Spolka s : menager.getSpolki()){
  4.             Double wartosc = ceny.get(s.getSektor());
  5.             if(wartosc== null){
  6.                 wartosc = 0.0;
  7.             }
  8.             ceny.put(s.getSektor(), wartosc + s.getOstatnie().getCena());
  9.         }      
  10.         return ceny;
  11. }
  12.  
  13. into:
  14. public Map<String, Double> getCeny(){
  15.         return menager.getSpolki().stream().collect(Collectors.
  16.                 toMap(s -> s.getSektor(),
  17.                         s -> Optional.ofNullable(ceny.get(s.getSektor())).orElse(0.0) +  s.getOstatnie().getCena()));
  18. }