Use `computeIfAbsent` instead of an `if`

Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
master
jvoisin 5 years ago committed by Andrew DeMaria
parent 888204ffe7
commit c6ae5a1df7
No known key found for this signature in database
GPG Key ID: 0A3F5E91F8364EDF
  1. 6
      airsonic-main/src/main/java/org/airsonic/player/service/JukeboxJavaService.java
  2. 6
      airsonic-main/src/main/java/org/airsonic/player/service/MusicIndexService.java

@ -67,11 +67,7 @@ public class JukeboxJavaService {
if (StringUtils.isBlank(mixer)) {
mixer = DEFAULT_MIXER_ENTRY_KEY;
}
List<com.github.biconou.AudioPlayer.api.Player> playersForMixer = activeAudioPlayersPerMixer.get(mixer);
if (playersForMixer == null) {
playersForMixer = new ArrayList<>();
activeAudioPlayersPerMixer.put(mixer, playersForMixer);
}
List<com.github.biconou.AudioPlayer.api.Player> playersForMixer = activeAudioPlayersPerMixer.computeIfAbsent(mixer, k -> new ArrayList<>());
playersForMixer.add(newPlayer);
foundPlayer = newPlayer;
}

@ -98,11 +98,7 @@ public class MusicIndexService {
for (T artist : artists) {
MusicIndex index = getIndex(artist, indexes);
List<T> artistSet = result.get(index);
if (artistSet == null) {
artistSet = new ArrayList<T>();
result.put(index, artistSet);
}
List<T> artistSet = result.computeIfAbsent(index, k -> new ArrayList<T>());
artistSet.add(artist);
}

Loading…
Cancel
Save