Use lambdas instead of ghetto nested types

This change was done in an automated fashion
via IntelliJ IDEA

Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
master
jvoisin 5 years ago committed by Andrew DeMaria
parent 9cbcc94b58
commit af05b0f45b
No known key found for this signature in database
GPG Key ID: 0A3F5E91F8364EDF
  1. 7
      airsonic-main/src/main/java/org/airsonic/player/ajax/PlayQueueService.java
  2. 7
      airsonic-main/src/main/java/org/airsonic/player/domain/MediaFile.java
  3. 14
      airsonic-main/src/main/java/org/airsonic/player/domain/MusicFolder.java
  4. 50
      airsonic-main/src/main/java/org/airsonic/player/domain/PlayQueue.java
  5. 9
      airsonic-main/src/main/java/org/airsonic/player/service/LastFmCache.java
  6. 62
      airsonic-main/src/main/java/org/airsonic/player/service/PodcastService.java
  7. 30
      airsonic-main/src/main/java/org/airsonic/player/service/jukebox/PlayerTest.java
  8. 7
      airsonic-main/src/main/java/org/airsonic/player/service/sonos/SonosHelper.java
  9. 18
      airsonic-main/src/test/java/org/airsonic/player/service/search/QueryFactoryTestCase.java

@ -351,12 +351,7 @@ public class PlayQueueService {
HttpServletResponse response = WebContextFactory.get().getHttpServletResponse(); HttpServletResponse response = WebContextFactory.get().getHttpServletResponse();
List<PodcastEpisode> episodes = podcastService.getNewestEpisodes(10); List<PodcastEpisode> episodes = podcastService.getNewestEpisodes(10);
List<MediaFile> files = Lists.transform(episodes, new Function<PodcastEpisode, MediaFile>() { List<MediaFile> files = Lists.transform(episodes, episode -> mediaFileService.getMediaFile(episode.getMediaFileId()));
@Override
public MediaFile apply(PodcastEpisode episode) {
return mediaFileService.getMediaFile(episode.getMediaFileId());
}
});
String username = securityService.getCurrentUsername(request); String username = securityService.getCurrentUsername(request);
boolean queueFollowingSongs = settingsService.getUserSettings(username).isQueueFollowingSongs(); boolean queueFollowingSongs = settingsService.getUserSettings(username).isQueueFollowingSongs();

@ -463,12 +463,7 @@ public class MediaFile {
} }
public static Function<MediaFile, Integer> toId() { public static Function<MediaFile, Integer> toId() {
return new Function<MediaFile, Integer>() { return from -> from.getId();
@Override
public Integer apply(MediaFile from) {
return from.getId();
}
};
} }
public static enum MediaType { public static enum MediaType {

@ -178,20 +178,10 @@ public class MusicFolder implements Serializable {
} }
public static Function<MusicFolder, Integer> toId() { public static Function<MusicFolder, Integer> toId() {
return new Function<MusicFolder, Integer>() { return from -> from.getId();
@Override
public Integer apply(MusicFolder from) {
return from.getId();
}
};
} }
public static Function<MusicFolder, String> toPath() { public static Function<MusicFolder, String> toPath() {
return new Function<MusicFolder, String>() { return from -> from.getPath().getPath();
@Override
public String apply(MusicFolder from) {
return from.getPath().getPath();
}
};
} }
} }

@ -251,32 +251,30 @@ public class PlayQueue {
makeBackup(); makeBackup();
MediaFile currentFile = getCurrentFile(); MediaFile currentFile = getCurrentFile();
Comparator<MediaFile> comparator = new Comparator<MediaFile>() { Comparator<MediaFile> comparator = (a, b) -> {
public int compare(MediaFile a, MediaFile b) { switch (sortOrder) {
switch (sortOrder) { case TRACK:
case TRACK: Integer trackA = a.getTrackNumber();
Integer trackA = a.getTrackNumber(); Integer trackB = b.getTrackNumber();
Integer trackB = b.getTrackNumber(); if (trackA == null) {
if (trackA == null) { trackA = 0;
trackA = 0; }
} if (trackB == null) {
if (trackB == null) { trackB = 0;
trackB = 0; }
} return trackA.compareTo(trackB);
return trackA.compareTo(trackB);
case ARTIST:
case ARTIST: String artistA = StringUtils.trimToEmpty(a.getArtist());
String artistA = StringUtils.trimToEmpty(a.getArtist()); String artistB = StringUtils.trimToEmpty(b.getArtist());
String artistB = StringUtils.trimToEmpty(b.getArtist()); return artistA.compareTo(artistB);
return artistA.compareTo(artistB);
case ALBUM:
case ALBUM: String albumA = StringUtils.trimToEmpty(a.getAlbumName());
String albumA = StringUtils.trimToEmpty(a.getAlbumName()); String albumB = StringUtils.trimToEmpty(b.getAlbumName());
String albumB = StringUtils.trimToEmpty(b.getAlbumName()); return albumA.compareTo(albumB);
return albumA.compareTo(albumB); default:
default: return 0;
return 0;
}
} }
}; };

@ -20,13 +20,11 @@
package org.airsonic.player.service; package org.airsonic.player.service;
import de.umass.lastfm.cache.Cache; import de.umass.lastfm.cache.Cache;
import de.umass.lastfm.cache.ExpirationPolicy;
import de.umass.lastfm.cache.FileSystemCache; import de.umass.lastfm.cache.FileSystemCache;
import org.airsonic.player.util.FileUtil; import org.airsonic.player.util.FileUtil;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import java.io.*; import java.io.*;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
/** /**
@ -45,12 +43,7 @@ public class LastFmCache extends Cache {
this.cacheDir = cacheDir; this.cacheDir = cacheDir;
this.ttl = ttl; this.ttl = ttl;
setExpirationPolicy(new ExpirationPolicy() { setExpirationPolicy((method, params) -> ttl);
@Override
public long getExpirationTime(String method, Map<String, String> params) {
return ttl;
}
});
} }
@Override @Override

@ -96,13 +96,10 @@ public class PodcastService {
private MetaDataParserFactory metaDataParserFactory; private MetaDataParserFactory metaDataParserFactory;
public PodcastService() { public PodcastService() {
ThreadFactory threadFactory = new ThreadFactory() { ThreadFactory threadFactory = r -> {
@Override Thread t = Executors.defaultThreadFactory().newThread(r);
public Thread newThread(Runnable r) { t.setDaemon(true);
Thread t = Executors.defaultThreadFactory().newThread(r); return t;
t.setDaemon(true);
return t;
}
}; };
refreshExecutor = Executors.newFixedThreadPool(5, threadFactory); refreshExecutor = Executors.newFixedThreadPool(5, threadFactory);
downloadExecutor = Executors.newFixedThreadPool(3, threadFactory); downloadExecutor = Executors.newFixedThreadPool(3, threadFactory);
@ -128,13 +125,10 @@ public class PodcastService {
} }
public synchronized void schedule() { public synchronized void schedule() {
Runnable task = new Runnable() { Runnable task = () -> {
@Override LOG.info("Starting scheduled Podcast refresh.");
public void run() { refreshAllChannels(true);
LOG.info("Starting scheduled Podcast refresh."); LOG.info("Completed scheduled Podcast refresh.");
refreshAllChannels(true);
LOG.info("Completed scheduled Podcast refresh.");
}
}; };
if (scheduledRefresh != null) { if (scheduledRefresh != null) {
@ -224,16 +218,13 @@ public class PodcastService {
public List<PodcastEpisode> getNewestEpisodes(int count) { public List<PodcastEpisode> getNewestEpisodes(int count) {
List<PodcastEpisode> episodes = addMediaFileIdToEpisodes(podcastDao.getNewestEpisodes(count)); List<PodcastEpisode> episodes = addMediaFileIdToEpisodes(podcastDao.getNewestEpisodes(count));
return Lists.newArrayList(Iterables.filter(episodes, new Predicate<PodcastEpisode>() { return Lists.newArrayList(Iterables.filter(episodes, episode -> {
@Override Integer mediaFileId = episode.getMediaFileId();
public boolean apply(PodcastEpisode episode) { if (mediaFileId == null) {
Integer mediaFileId = episode.getMediaFileId(); return false;
if (mediaFileId == null) {
return false;
}
MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId);
return mediaFile != null && mediaFile.isPresent();
} }
MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId);
return mediaFile != null && mediaFile.isPresent();
})); }));
} }
@ -300,12 +291,7 @@ public class PodcastService {
private void refreshChannels(final List<PodcastChannel> channels, final boolean downloadEpisodes) { private void refreshChannels(final List<PodcastChannel> channels, final boolean downloadEpisodes) {
for (final PodcastChannel channel : channels) { for (final PodcastChannel channel : channels) {
Runnable task = new Runnable() { Runnable task = () -> doRefreshChannel(channel, downloadEpisodes);
@Override
public void run() {
doRefreshChannel(channel, downloadEpisodes);
}
};
refreshExecutor.submit(task); refreshExecutor.submit(task);
} }
} }
@ -417,12 +403,7 @@ public class PodcastService {
} }
public void downloadEpisode(final PodcastEpisode episode) { public void downloadEpisode(final PodcastEpisode episode) {
Runnable task = new Runnable() { Runnable task = () -> doDownloadEpisode(episode);
@Override
public void run() {
doDownloadEpisode(episode);
}
};
downloadExecutor.submit(task); downloadExecutor.submit(task);
} }
@ -471,14 +452,11 @@ public class PodcastService {
} }
// Sort episode in reverse chronological order (newest first) // Sort episode in reverse chronological order (newest first)
Collections.sort(episodes, new Comparator<PodcastEpisode>() { Collections.sort(episodes, (a, b) -> {
@Override long timeA = a.getPublishDate() == null ? 0L : a.getPublishDate().getTime();
public int compare(PodcastEpisode a, PodcastEpisode b) { long timeB = b.getPublishDate() == null ? 0L : b.getPublishDate().getTime();
long timeA = a.getPublishDate() == null ? 0L : a.getPublishDate().getTime();
long timeB = b.getPublishDate() == null ? 0L : b.getPublishDate().getTime();
return Long.compare(timeB, timeA); return Long.compare(timeB, timeA);
}
}); });
// Create episodes in database, skipping the proper number of episodes. // Create episodes in database, skipping the proper number of episodes.

@ -29,28 +29,18 @@ public class PlayerTest implements AudioPlayer.Listener {
JButton resetButton = new JButton("Reset"); JButton resetButton = new JButton("Reset");
final JSlider gainSlider = new JSlider(0, 1000); final JSlider gainSlider = new JSlider(0, 1000);
startButton.addActionListener(new ActionListener() { startButton.addActionListener(e -> {
public void actionPerformed(ActionEvent e) { createPlayer();
createPlayer(); player.play();
player.play();
}
}); });
stopButton.addActionListener(new ActionListener() { stopButton.addActionListener(e -> player.pause());
public void actionPerformed(ActionEvent e) { resetButton.addActionListener(e -> {
player.pause(); player.close();
} createPlayer();
}); });
resetButton.addActionListener(new ActionListener() { gainSlider.addChangeListener(e -> {
public void actionPerformed(ActionEvent e) { float gain = gainSlider.getValue() / 1000.0F;
player.close(); player.setGain(gain);
createPlayer();
}
});
gainSlider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
float gain = gainSlider.getValue() / 1000.0F;
player.setGain(gain);
}
}); });
frame.setLayout(new FlowLayout()); frame.setLayout(new FlowLayout());

@ -623,12 +623,7 @@ public class SonosHelper {
} }
private List<MediaFile> filterMusic(List<MediaFile> files) { private List<MediaFile> filterMusic(List<MediaFile> files) {
return Lists.newArrayList(Iterables.filter(files, new Predicate<MediaFile>() { return Lists.newArrayList(Iterables.filter(files, input -> input.getMediaType() == MediaFile.MediaType.MUSIC));
@Override
public boolean apply(MediaFile input) {
return input.getMediaType() == MediaFile.MediaType.MUSIC;
}
}));
} }
public void setPlaylistService(PlaylistService playlistService) { public void setPlaylistService(PlaylistService playlistService) {

@ -1,8 +1,6 @@
package org.airsonic.player.service.search; package org.airsonic.player.service.search;
import static org.junit.Assert.assertEquals;
import org.airsonic.player.domain.MusicFolder; import org.airsonic.player.domain.MusicFolder;
import org.airsonic.player.domain.RandomSearchCriteria; import org.airsonic.player.domain.RandomSearchCriteria;
import org.airsonic.player.domain.SearchCriteria; import org.airsonic.player.domain.SearchCriteria;
@ -25,6 +23,8 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals;
/** /**
* Test case for QueryFactory. * Test case for QueryFactory.
* These cases have the purpose of observing the current situation * These cases have the purpose of observing the current situation
@ -68,9 +68,9 @@ public class QueryFactoryTestCase {
private static final int FID2 = 20; private static final int FID2 = 20;
private static final MusicFolder MUSIC_FOLDER1 = private static final MusicFolder MUSIC_FOLDER1 =
new MusicFolder(Integer.valueOf(FID1), new File(PATH1), "music1", true, new java.util.Date()); new MusicFolder(FID1, new File(PATH1), "music1", true, new java.util.Date());
private static final MusicFolder MUSIC_FOLDER2 = private static final MusicFolder MUSIC_FOLDER2 =
new MusicFolder(Integer.valueOf(FID2), new File(PATH2), "music2", true, new java.util.Date()); new MusicFolder(FID2, new File(PATH2), "music2", true, new java.util.Date());
private static final List<MusicFolder> SINGLE_FOLDERS = Arrays.asList(MUSIC_FOLDER1); private static final List<MusicFolder> SINGLE_FOLDERS = Arrays.asList(MUSIC_FOLDER1);
private static final List<MusicFolder> MULTI_FOLDERS = Arrays.asList(MUSIC_FOLDER1, MUSIC_FOLDER2); private static final List<MusicFolder> MULTI_FOLDERS = Arrays.asList(MUSIC_FOLDER1, MUSIC_FOLDER2);
@ -215,15 +215,15 @@ public class QueryFactoryTestCase {
@Test @Test
public void testGetRandomSongs() throws IOException { public void testGetRandomSongs() throws IOException {
RandomSearchCriteria criteria = new RandomSearchCriteria(50, "Classic Rock", RandomSearchCriteria criteria = new RandomSearchCriteria(50, "Classic Rock",
Integer.valueOf(1900), Integer.valueOf(2000), SINGLE_FOLDERS); 1900, 2000, SINGLE_FOLDERS);
Query query = queryFactory.getRandomSongs(criteria); Query query = queryFactory.getRandomSongs(criteria);
assertEquals(ToStringBuilder.reflectionToString(criteria), assertEquals(ToStringBuilder.reflectionToString(criteria),
"+mediaType:MUSIC +genre:Classic Rock +year:[1900 TO 2000] +(folder:" + PATH1 + ")", "+mediaType:MUSIC +genre:Classic Rock +year:[1900 TO 2000] +(folder:" + PATH1 + ")",
query.toString()); query.toString());
criteria = new RandomSearchCriteria(50, "Classic Rock", Integer.valueOf(1900), criteria = new RandomSearchCriteria(50, "Classic Rock", 1900,
Integer.valueOf(2000), MULTI_FOLDERS); 2000, MULTI_FOLDERS);
query = queryFactory.getRandomSongs(criteria); query = queryFactory.getRandomSongs(criteria);
assertEquals(ToStringBuilder.reflectionToString(criteria), assertEquals(ToStringBuilder.reflectionToString(criteria),
"+mediaType:MUSIC +genre:Classic Rock +year:[1900 TO 2000] +(folder:" + PATH1 + " folder:" + PATH2 "+mediaType:MUSIC +genre:Classic Rock +year:[1900 TO 2000] +(folder:" + PATH1 + " folder:" + PATH2
@ -236,7 +236,7 @@ public class QueryFactoryTestCase {
"+mediaType:MUSIC +genre:Classic Rock +(folder:" + PATH1 + " folder:" + PATH2 + ")", "+mediaType:MUSIC +genre:Classic Rock +(folder:" + PATH1 + " folder:" + PATH2 + ")",
query.toString()); query.toString());
criteria = new RandomSearchCriteria(50, "Classic Rock", Integer.valueOf(1900), null, criteria = new RandomSearchCriteria(50, "Classic Rock", 1900, null,
MULTI_FOLDERS); MULTI_FOLDERS);
query = queryFactory.getRandomSongs(criteria); query = queryFactory.getRandomSongs(criteria);
assertEquals(ToStringBuilder.reflectionToString(criteria), assertEquals(ToStringBuilder.reflectionToString(criteria),
@ -244,7 +244,7 @@ public class QueryFactoryTestCase {
+ ")", + ")",
query.toString()); query.toString());
criteria = new RandomSearchCriteria(50, "Classic Rock", null, Integer.valueOf(2000), criteria = new RandomSearchCriteria(50, "Classic Rock", null, 2000,
MULTI_FOLDERS); MULTI_FOLDERS);
query = queryFactory.getRandomSongs(criteria); query = queryFactory.getRandomSongs(criteria);
assertEquals(ToStringBuilder.reflectionToString(criteria), assertEquals(ToStringBuilder.reflectionToString(criteria),

Loading…
Cancel
Save