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. 4
      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. 34
      airsonic-main/src/main/java/org/airsonic/player/service/PodcastService.java
  7. 18
      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();
List<PodcastEpisode> episodes = podcastService.getNewestEpisodes(10);
List<MediaFile> files = Lists.transform(episodes, new Function<PodcastEpisode, MediaFile>() {
@Override
public MediaFile apply(PodcastEpisode episode) {
return mediaFileService.getMediaFile(episode.getMediaFileId());
}
});
List<MediaFile> files = Lists.transform(episodes, episode -> mediaFileService.getMediaFile(episode.getMediaFileId()));
String username = securityService.getCurrentUsername(request);
boolean queueFollowingSongs = settingsService.getUserSettings(username).isQueueFollowingSongs();

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

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

@ -251,8 +251,7 @@ public class PlayQueue {
makeBackup();
MediaFile currentFile = getCurrentFile();
Comparator<MediaFile> comparator = new Comparator<MediaFile>() {
public int compare(MediaFile a, MediaFile b) {
Comparator<MediaFile> comparator = (a, b) -> {
switch (sortOrder) {
case TRACK:
Integer trackA = a.getTrackNumber();
@ -277,7 +276,6 @@ public class PlayQueue {
default:
return 0;
}
}
};
Collections.sort(files, comparator);

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

@ -96,13 +96,10 @@ public class PodcastService {
private MetaDataParserFactory metaDataParserFactory;
public PodcastService() {
ThreadFactory threadFactory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
ThreadFactory threadFactory = r -> {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
}
};
refreshExecutor = Executors.newFixedThreadPool(5, threadFactory);
downloadExecutor = Executors.newFixedThreadPool(3, threadFactory);
@ -128,13 +125,10 @@ public class PodcastService {
}
public synchronized void schedule() {
Runnable task = new Runnable() {
@Override
public void run() {
Runnable task = () -> {
LOG.info("Starting scheduled Podcast refresh.");
refreshAllChannels(true);
LOG.info("Completed scheduled Podcast refresh.");
}
};
if (scheduledRefresh != null) {
@ -224,16 +218,13 @@ public class PodcastService {
public List<PodcastEpisode> getNewestEpisodes(int count) {
List<PodcastEpisode> episodes = addMediaFileIdToEpisodes(podcastDao.getNewestEpisodes(count));
return Lists.newArrayList(Iterables.filter(episodes, new Predicate<PodcastEpisode>() {
@Override
public boolean apply(PodcastEpisode episode) {
return Lists.newArrayList(Iterables.filter(episodes, episode -> {
Integer mediaFileId = episode.getMediaFileId();
if (mediaFileId == null) {
return false;
}
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) {
for (final PodcastChannel channel : channels) {
Runnable task = new Runnable() {
@Override
public void run() {
doRefreshChannel(channel, downloadEpisodes);
}
};
Runnable task = () -> doRefreshChannel(channel, downloadEpisodes);
refreshExecutor.submit(task);
}
}
@ -417,12 +403,7 @@ public class PodcastService {
}
public void downloadEpisode(final PodcastEpisode episode) {
Runnable task = new Runnable() {
@Override
public void run() {
doDownloadEpisode(episode);
}
};
Runnable task = () -> doDownloadEpisode(episode);
downloadExecutor.submit(task);
}
@ -471,14 +452,11 @@ public class PodcastService {
}
// Sort episode in reverse chronological order (newest first)
Collections.sort(episodes, new Comparator<PodcastEpisode>() {
@Override
public int compare(PodcastEpisode a, PodcastEpisode b) {
Collections.sort(episodes, (a, b) -> {
long timeA = a.getPublishDate() == null ? 0L : a.getPublishDate().getTime();
long timeB = b.getPublishDate() == null ? 0L : b.getPublishDate().getTime();
return Long.compare(timeB, timeA);
}
});
// 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");
final JSlider gainSlider = new JSlider(0, 1000);
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startButton.addActionListener(e -> {
createPlayer();
player.play();
}
});
stopButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
player.pause();
}
});
resetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
stopButton.addActionListener(e -> player.pause());
resetButton.addActionListener(e -> {
player.close();
createPlayer();
}
});
gainSlider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
gainSlider.addChangeListener(e -> {
float gain = gainSlider.getValue() / 1000.0F;
player.setGain(gain);
}
});
frame.setLayout(new FlowLayout());

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

@ -1,8 +1,6 @@
package org.airsonic.player.service.search;
import static org.junit.Assert.assertEquals;
import org.airsonic.player.domain.MusicFolder;
import org.airsonic.player.domain.RandomSearchCriteria;
import org.airsonic.player.domain.SearchCriteria;
@ -25,6 +23,8 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* Test case for QueryFactory.
* 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 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 =
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> MULTI_FOLDERS = Arrays.asList(MUSIC_FOLDER1, MUSIC_FOLDER2);
@ -215,15 +215,15 @@ public class QueryFactoryTestCase {
@Test
public void testGetRandomSongs() throws IOException {
RandomSearchCriteria criteria = new RandomSearchCriteria(50, "Classic Rock",
Integer.valueOf(1900), Integer.valueOf(2000), SINGLE_FOLDERS);
1900, 2000, SINGLE_FOLDERS);
Query query = queryFactory.getRandomSongs(criteria);
assertEquals(ToStringBuilder.reflectionToString(criteria),
"+mediaType:MUSIC +genre:Classic Rock +year:[1900 TO 2000] +(folder:" + PATH1 + ")",
query.toString());
criteria = new RandomSearchCriteria(50, "Classic Rock", Integer.valueOf(1900),
Integer.valueOf(2000), MULTI_FOLDERS);
criteria = new RandomSearchCriteria(50, "Classic Rock", 1900,
2000, MULTI_FOLDERS);
query = queryFactory.getRandomSongs(criteria);
assertEquals(ToStringBuilder.reflectionToString(criteria),
"+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 + ")",
query.toString());
criteria = new RandomSearchCriteria(50, "Classic Rock", Integer.valueOf(1900), null,
criteria = new RandomSearchCriteria(50, "Classic Rock", 1900, null,
MULTI_FOLDERS);
query = queryFactory.getRandomSongs(criteria);
assertEquals(ToStringBuilder.reflectionToString(criteria),
@ -244,7 +244,7 @@ public class QueryFactoryTestCase {
+ ")",
query.toString());
criteria = new RandomSearchCriteria(50, "Classic Rock", null, Integer.valueOf(2000),
criteria = new RandomSearchCriteria(50, "Classic Rock", null, 2000,
MULTI_FOLDERS);
query = queryFactory.getRandomSongs(criteria);
assertEquals(ToStringBuilder.reflectionToString(criteria),

Loading…
Cancel
Save