Use computeIfAbsent instead of an if

Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
This commit is contained in:
jvoisin
2019-10-05 19:01:53 -06:00
committed by Andrew DeMaria
parent 888204ffe7
commit c6ae5a1df7
2 changed files with 2 additions and 10 deletions
@@ -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);
}