From 30fa4d0467f1b147ee6c710e17346512624ab9ac Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 26 Mar 2019 00:00:21 +0100 Subject: [PATCH] Second pass of trivial modernizations - Replace unnecessary getters/setters with inline assignments - Simplify string constructions - Improve containers construction --- .../player/command/UserSettingsCommand.java | 2 +- .../player/domain/TranscodeScheme.java | 2 +- .../airsonic/player/domain/TransferStatus.java | 11 +++++------ .../airsonic/player/service/LastFmService.java | 3 +-- .../player/service/SettingsService.java | 2 +- .../airsonic/player/service/SonosService.java | 2 +- .../player/service/sonos/SonosHelper.java | 4 +--- .../service/PlaylistServiceTestImport.java | 18 +++++++++--------- 8 files changed, 20 insertions(+), 24 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/command/UserSettingsCommand.java b/airsonic-main/src/main/java/org/airsonic/player/command/UserSettingsCommand.java index 07e6a1a9..7b70be6a 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/command/UserSettingsCommand.java +++ b/airsonic-main/src/main/java/org/airsonic/player/command/UserSettingsCommand.java @@ -295,7 +295,7 @@ public class UserSettingsCommand { isSettingsRole = user != null && user.isSettingsRole(); isShareRole = user != null && user.isShareRole(); isLdapAuthenticated = user != null && user.isLdapAuthenticated(); - setNewUser(false); + isNewUser = false; } } \ No newline at end of file diff --git a/airsonic-main/src/main/java/org/airsonic/player/domain/TranscodeScheme.java b/airsonic-main/src/main/java/org/airsonic/player/domain/TranscodeScheme.java index 7ebb85b2..dd50b899 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/domain/TranscodeScheme.java +++ b/airsonic-main/src/main/java/org/airsonic/player/domain/TranscodeScheme.java @@ -85,7 +85,7 @@ public enum TranscodeScheme { if (this == OFF) { return "No limit"; } - return "" + getMaxBitRate() + " Kbps"; + return getMaxBitRate() + " Kbps"; } /** diff --git a/airsonic-main/src/main/java/org/airsonic/player/domain/TransferStatus.java b/airsonic-main/src/main/java/org/airsonic/player/domain/TransferStatus.java index dfce8386..ee58dcae 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/domain/TransferStatus.java +++ b/airsonic-main/src/main/java/org/airsonic/player/domain/TransferStatus.java @@ -234,8 +234,8 @@ public class TransferStatus { this.active = active; if (active) { - setBytesSkipped(0L); - setBytesTotal(0L); + bytesSkipped = 0L; + bytesTotal = 0L; setBytesTransfered(0L); } else { createSample(getBytesTransfered(), true); @@ -281,10 +281,9 @@ public class TransferStatus { @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("TransferStatus-").append(hashCode()).append(" [player: ").append(player.getId()).append(", file: "); - builder.append(file).append(", terminated: ").append(terminated).append(", active: ").append(active).append("]"); - return builder.toString(); + String builder = "TransferStatus-" + hashCode() + " [player: " + player.getId() + ", file: " + + file + ", terminated: " + terminated + ", active: " + active + "]"; + return builder; } /** diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/LastFmService.java b/airsonic-main/src/main/java/org/airsonic/player/service/LastFmService.java index d5efa6de..dbca7636 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/LastFmService.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/LastFmService.java @@ -183,9 +183,8 @@ public class LastFmService { */ public List getSimilarSongs(org.airsonic.player.domain.Artist artist, int count, List musicFolders) throws IOException { - List similarSongs = new ArrayList(); - similarSongs.addAll(mediaFileDao.getSongsByArtist(artist.getName(), 0, 1000)); + List similarSongs = new ArrayList(mediaFileDao.getSongsByArtist(artist.getName(), 0, 1000)); for (org.airsonic.player.domain.Artist similarArtist : getSimilarArtists(artist, 100, false, musicFolders)) { similarSongs.addAll(mediaFileDao.getSongsByArtist(similarArtist.getName(), 0, 1000)); } diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/SettingsService.java b/airsonic-main/src/main/java/org/airsonic/player/service/SettingsService.java index 087220db..027c5e79 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/SettingsService.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/SettingsService.java @@ -606,7 +606,7 @@ public class SettingsService { * @param limit The download bitrate limit in Kbit/s. Zero if unlimited. */ public void setDownloadBitrateLimit(long limit) { - setProperty(KEY_DOWNLOAD_BITRATE_LIMIT, "" + limit); + setProperty(KEY_DOWNLOAD_BITRATE_LIMIT, String.valueOf(limit)); } /** diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/SonosService.java b/airsonic-main/src/main/java/org/airsonic/player/service/SonosService.java index fc804f48..cec40454 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/SonosService.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/SonosService.java @@ -464,7 +464,7 @@ public class SonosService implements SonosSoap { if (StringUtils.isNumeric(part)) { result.add(Integer.parseInt(part)); } else { - int dashIndex = part.indexOf("-"); + int dashIndex = part.indexOf('-'); int from = Integer.parseInt(part.substring(0, dashIndex)); int to = Integer.parseInt(part.substring(dashIndex + 1)); for (int i = from; i <= to; i++) { diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/sonos/SonosHelper.java b/airsonic-main/src/main/java/org/airsonic/player/service/sonos/SonosHelper.java index 72e94859..5a6a6b4f 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/sonos/SonosHelper.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/sonos/SonosHelper.java @@ -118,9 +118,7 @@ public class SonosHelper { List albums = searchService.getRandomAlbums(40, musicFolders); List songs = new ArrayList(); for (MediaFile album : albums) { - for (MediaFile file : filterMusic(mediaFileService.getChildrenOf(album, true, false, false))) { - songs.add(file); - } + songs.addAll(filterMusic(mediaFileService.getChildrenOf(album, true, false, false))); } Collections.shuffle(songs); songs = songs.subList(0, Math.min(count, songs.size())); diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/PlaylistServiceTestImport.java b/airsonic-main/src/test/java/org/airsonic/player/service/PlaylistServiceTestImport.java index c63cd473..39ffee0d 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/PlaylistServiceTestImport.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/PlaylistServiceTestImport.java @@ -88,9 +88,9 @@ public class PlaylistServiceTestImport { FileUtils.touch(mf2); File mf3 = folder.newFile(); FileUtils.touch(mf3); - builder.append(mf1.getAbsolutePath() + "\n"); - builder.append(mf2.getAbsolutePath() + "\n"); - builder.append(mf3.getAbsolutePath() + "\n"); + builder.append(mf1.getAbsolutePath()).append("\n"); + builder.append(mf2.getAbsolutePath()).append("\n"); + builder.append(mf3.getAbsolutePath()).append("\n"); doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8")); @@ -122,9 +122,9 @@ public class PlaylistServiceTestImport { FileUtils.touch(mf2); File mf3 = folder.newFile(); FileUtils.touch(mf3); - builder.append("File1=" + mf1.getAbsolutePath() + "\n"); - builder.append("File2=" + mf2.getAbsolutePath() + "\n"); - builder.append("File3=" + mf3.getAbsolutePath() + "\n"); + builder.append("File1=").append(mf1.getAbsolutePath()).append("\n"); + builder.append("File2=").append(mf2.getAbsolutePath()).append("\n"); + builder.append("File3=").append(mf3.getAbsolutePath()).append("\n"); doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8")); @@ -158,9 +158,9 @@ public class PlaylistServiceTestImport { FileUtils.touch(mf2); File mf3 = folder.newFile(); FileUtils.touch(mf3); - builder.append("file://" + mf1.getAbsolutePath() + "\n"); - builder.append("file://" + mf2.getAbsolutePath() + "\n"); - builder.append("file://" + mf3.getAbsolutePath() + "\n"); + builder.append("file://").append(mf1.getAbsolutePath()).append("\n"); + builder.append("file://").append(mf2.getAbsolutePath()).append("\n"); + builder.append("file://").append(mf3.getAbsolutePath()).append("\n"); builder.append(" \n" + "\n"); doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));