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>
This commit is contained in:
@@ -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,32 +251,30 @@ public class PlayQueue {
|
||||
makeBackup();
|
||||
MediaFile currentFile = getCurrentFile();
|
||||
|
||||
Comparator<MediaFile> comparator = new Comparator<MediaFile>() {
|
||||
public int compare(MediaFile a, MediaFile b) {
|
||||
switch (sortOrder) {
|
||||
case TRACK:
|
||||
Integer trackA = a.getTrackNumber();
|
||||
Integer trackB = b.getTrackNumber();
|
||||
if (trackA == null) {
|
||||
trackA = 0;
|
||||
}
|
||||
if (trackB == null) {
|
||||
trackB = 0;
|
||||
}
|
||||
return trackA.compareTo(trackB);
|
||||
Comparator<MediaFile> comparator = (a, b) -> {
|
||||
switch (sortOrder) {
|
||||
case TRACK:
|
||||
Integer trackA = a.getTrackNumber();
|
||||
Integer trackB = b.getTrackNumber();
|
||||
if (trackA == null) {
|
||||
trackA = 0;
|
||||
}
|
||||
if (trackB == null) {
|
||||
trackB = 0;
|
||||
}
|
||||
return trackA.compareTo(trackB);
|
||||
|
||||
case ARTIST:
|
||||
String artistA = StringUtils.trimToEmpty(a.getArtist());
|
||||
String artistB = StringUtils.trimToEmpty(b.getArtist());
|
||||
return artistA.compareTo(artistB);
|
||||
case ARTIST:
|
||||
String artistA = StringUtils.trimToEmpty(a.getArtist());
|
||||
String artistB = StringUtils.trimToEmpty(b.getArtist());
|
||||
return artistA.compareTo(artistB);
|
||||
|
||||
case ALBUM:
|
||||
String albumA = StringUtils.trimToEmpty(a.getAlbumName());
|
||||
String albumB = StringUtils.trimToEmpty(b.getAlbumName());
|
||||
return albumA.compareTo(albumB);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
case ALBUM:
|
||||
String albumA = StringUtils.trimToEmpty(a.getAlbumName());
|
||||
String albumB = StringUtils.trimToEmpty(b.getAlbumName());
|
||||
return albumA.compareTo(albumB);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
Thread t = Executors.defaultThreadFactory().newThread(r);
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
}
|
||||
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() {
|
||||
LOG.info("Starting scheduled Podcast refresh.");
|
||||
refreshAllChannels(true);
|
||||
LOG.info("Completed scheduled Podcast refresh.");
|
||||
}
|
||||
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) {
|
||||
Integer mediaFileId = episode.getMediaFileId();
|
||||
if (mediaFileId == null) {
|
||||
return false;
|
||||
}
|
||||
MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId);
|
||||
return mediaFile != null && mediaFile.isPresent();
|
||||
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) {
|
||||
long timeA = a.getPublishDate() == null ? 0L : a.getPublishDate().getTime();
|
||||
long timeB = b.getPublishDate() == null ? 0L : b.getPublishDate().getTime();
|
||||
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);
|
||||
}
|
||||
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) {
|
||||
createPlayer();
|
||||
player.play();
|
||||
}
|
||||
startButton.addActionListener(e -> {
|
||||
createPlayer();
|
||||
player.play();
|
||||
});
|
||||
stopButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
player.pause();
|
||||
}
|
||||
stopButton.addActionListener(e -> player.pause());
|
||||
resetButton.addActionListener(e -> {
|
||||
player.close();
|
||||
createPlayer();
|
||||
});
|
||||
resetButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
player.close();
|
||||
createPlayer();
|
||||
}
|
||||
});
|
||||
gainSlider.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
float gain = gainSlider.getValue() / 1000.0F;
|
||||
player.setGain(gain);
|
||||
}
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user