Use computeIfAbsent instead of an if
Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
This commit is contained in:
@@ -67,11 +67,7 @@ public class JukeboxJavaService {
|
|||||||
if (StringUtils.isBlank(mixer)) {
|
if (StringUtils.isBlank(mixer)) {
|
||||||
mixer = DEFAULT_MIXER_ENTRY_KEY;
|
mixer = DEFAULT_MIXER_ENTRY_KEY;
|
||||||
}
|
}
|
||||||
List<com.github.biconou.AudioPlayer.api.Player> playersForMixer = activeAudioPlayersPerMixer.get(mixer);
|
List<com.github.biconou.AudioPlayer.api.Player> playersForMixer = activeAudioPlayersPerMixer.computeIfAbsent(mixer, k -> new ArrayList<>());
|
||||||
if (playersForMixer == null) {
|
|
||||||
playersForMixer = new ArrayList<>();
|
|
||||||
activeAudioPlayersPerMixer.put(mixer, playersForMixer);
|
|
||||||
}
|
|
||||||
playersForMixer.add(newPlayer);
|
playersForMixer.add(newPlayer);
|
||||||
foundPlayer = newPlayer;
|
foundPlayer = newPlayer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,11 +98,7 @@ public class MusicIndexService {
|
|||||||
|
|
||||||
for (T artist : artists) {
|
for (T artist : artists) {
|
||||||
MusicIndex index = getIndex(artist, indexes);
|
MusicIndex index = getIndex(artist, indexes);
|
||||||
List<T> artistSet = result.get(index);
|
List<T> artistSet = result.computeIfAbsent(index, k -> new ArrayList<T>());
|
||||||
if (artistSet == null) {
|
|
||||||
artistSet = new ArrayList<T>();
|
|
||||||
result.put(index, artistSet);
|
|
||||||
}
|
|
||||||
artistSet.add(artist);
|
artistSet.add(artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user