Second pass of trivial modernizations

- Replace unnecessary getters/setters with inline assignments
- Simplify string constructions
- Improve containers construction
master
jvoisin 6 years ago
parent ca489f8220
commit 30fa4d0467
  1. 2
      airsonic-main/src/main/java/org/airsonic/player/command/UserSettingsCommand.java
  2. 2
      airsonic-main/src/main/java/org/airsonic/player/domain/TranscodeScheme.java
  3. 11
      airsonic-main/src/main/java/org/airsonic/player/domain/TransferStatus.java
  4. 3
      airsonic-main/src/main/java/org/airsonic/player/service/LastFmService.java
  5. 2
      airsonic-main/src/main/java/org/airsonic/player/service/SettingsService.java
  6. 2
      airsonic-main/src/main/java/org/airsonic/player/service/SonosService.java
  7. 4
      airsonic-main/src/main/java/org/airsonic/player/service/sonos/SonosHelper.java
  8. 18
      airsonic-main/src/test/java/org/airsonic/player/service/PlaylistServiceTestImport.java

@ -295,7 +295,7 @@ public class UserSettingsCommand {
isSettingsRole = user != null && user.isSettingsRole(); isSettingsRole = user != null && user.isSettingsRole();
isShareRole = user != null && user.isShareRole(); isShareRole = user != null && user.isShareRole();
isLdapAuthenticated = user != null && user.isLdapAuthenticated(); isLdapAuthenticated = user != null && user.isLdapAuthenticated();
setNewUser(false); isNewUser = false;
} }
} }

@ -85,7 +85,7 @@ public enum TranscodeScheme {
if (this == OFF) { if (this == OFF) {
return "No limit"; return "No limit";
} }
return "" + getMaxBitRate() + " Kbps"; return getMaxBitRate() + " Kbps";
} }
/** /**

@ -234,8 +234,8 @@ public class TransferStatus {
this.active = active; this.active = active;
if (active) { if (active) {
setBytesSkipped(0L); bytesSkipped = 0L;
setBytesTotal(0L); bytesTotal = 0L;
setBytesTransfered(0L); setBytesTransfered(0L);
} else { } else {
createSample(getBytesTransfered(), true); createSample(getBytesTransfered(), true);
@ -281,10 +281,9 @@ public class TransferStatus {
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); String builder = "TransferStatus-" + hashCode() + " [player: " + player.getId() + ", file: " +
builder.append("TransferStatus-").append(hashCode()).append(" [player: ").append(player.getId()).append(", file: "); file + ", terminated: " + terminated + ", active: " + active + "]";
builder.append(file).append(", terminated: ").append(terminated).append(", active: ").append(active).append("]"); return builder;
return builder.toString();
} }
/** /**

@ -183,9 +183,8 @@ public class LastFmService {
*/ */
public List<MediaFile> getSimilarSongs(org.airsonic.player.domain.Artist artist, int count, public List<MediaFile> getSimilarSongs(org.airsonic.player.domain.Artist artist, int count,
List<MusicFolder> musicFolders) throws IOException { List<MusicFolder> musicFolders) throws IOException {
List<MediaFile> similarSongs = new ArrayList<MediaFile>();
similarSongs.addAll(mediaFileDao.getSongsByArtist(artist.getName(), 0, 1000)); List<MediaFile> similarSongs = new ArrayList<MediaFile>(mediaFileDao.getSongsByArtist(artist.getName(), 0, 1000));
for (org.airsonic.player.domain.Artist similarArtist : getSimilarArtists(artist, 100, false, musicFolders)) { for (org.airsonic.player.domain.Artist similarArtist : getSimilarArtists(artist, 100, false, musicFolders)) {
similarSongs.addAll(mediaFileDao.getSongsByArtist(similarArtist.getName(), 0, 1000)); similarSongs.addAll(mediaFileDao.getSongsByArtist(similarArtist.getName(), 0, 1000));
} }

@ -606,7 +606,7 @@ public class SettingsService {
* @param limit The download bitrate limit in Kbit/s. Zero if unlimited. * @param limit The download bitrate limit in Kbit/s. Zero if unlimited.
*/ */
public void setDownloadBitrateLimit(long limit) { public void setDownloadBitrateLimit(long limit) {
setProperty(KEY_DOWNLOAD_BITRATE_LIMIT, "" + limit); setProperty(KEY_DOWNLOAD_BITRATE_LIMIT, String.valueOf(limit));
} }
/** /**

@ -464,7 +464,7 @@ public class SonosService implements SonosSoap {
if (StringUtils.isNumeric(part)) { if (StringUtils.isNumeric(part)) {
result.add(Integer.parseInt(part)); result.add(Integer.parseInt(part));
} else { } else {
int dashIndex = part.indexOf("-"); int dashIndex = part.indexOf('-');
int from = Integer.parseInt(part.substring(0, dashIndex)); int from = Integer.parseInt(part.substring(0, dashIndex));
int to = Integer.parseInt(part.substring(dashIndex + 1)); int to = Integer.parseInt(part.substring(dashIndex + 1));
for (int i = from; i <= to; i++) { for (int i = from; i <= to; i++) {

@ -118,9 +118,7 @@ public class SonosHelper {
List<MediaFile> albums = searchService.getRandomAlbums(40, musicFolders); List<MediaFile> albums = searchService.getRandomAlbums(40, musicFolders);
List<MediaFile> songs = new ArrayList<MediaFile>(); List<MediaFile> songs = new ArrayList<MediaFile>();
for (MediaFile album : albums) { for (MediaFile album : albums) {
for (MediaFile file : filterMusic(mediaFileService.getChildrenOf(album, true, false, false))) { songs.addAll(filterMusic(mediaFileService.getChildrenOf(album, true, false, false)));
songs.add(file);
}
} }
Collections.shuffle(songs); Collections.shuffle(songs);
songs = songs.subList(0, Math.min(count, songs.size())); songs = songs.subList(0, Math.min(count, songs.size()));

@ -88,9 +88,9 @@ public class PlaylistServiceTestImport {
FileUtils.touch(mf2); FileUtils.touch(mf2);
File mf3 = folder.newFile(); File mf3 = folder.newFile();
FileUtils.touch(mf3); FileUtils.touch(mf3);
builder.append(mf1.getAbsolutePath() + "\n"); builder.append(mf1.getAbsolutePath()).append("\n");
builder.append(mf2.getAbsolutePath() + "\n"); builder.append(mf2.getAbsolutePath()).append("\n");
builder.append(mf3.getAbsolutePath() + "\n"); builder.append(mf3.getAbsolutePath()).append("\n");
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8")); InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
@ -122,9 +122,9 @@ public class PlaylistServiceTestImport {
FileUtils.touch(mf2); FileUtils.touch(mf2);
File mf3 = folder.newFile(); File mf3 = folder.newFile();
FileUtils.touch(mf3); FileUtils.touch(mf3);
builder.append("File1=" + mf1.getAbsolutePath() + "\n"); builder.append("File1=").append(mf1.getAbsolutePath()).append("\n");
builder.append("File2=" + mf2.getAbsolutePath() + "\n"); builder.append("File2=").append(mf2.getAbsolutePath()).append("\n");
builder.append("File3=" + mf3.getAbsolutePath() + "\n"); builder.append("File3=").append(mf3.getAbsolutePath()).append("\n");
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8")); InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
@ -158,9 +158,9 @@ public class PlaylistServiceTestImport {
FileUtils.touch(mf2); FileUtils.touch(mf2);
File mf3 = folder.newFile(); File mf3 = folder.newFile();
FileUtils.touch(mf3); FileUtils.touch(mf3);
builder.append("<track><location>file://" + mf1.getAbsolutePath() + "</location></track>\n"); builder.append("<track><location>file://").append(mf1.getAbsolutePath()).append("</location></track>\n");
builder.append("<track><location>file://" + mf2.getAbsolutePath() + "</location></track>\n"); builder.append("<track><location>file://").append(mf2.getAbsolutePath()).append("</location></track>\n");
builder.append("<track><location>file://" + mf3.getAbsolutePath() + "</location></track>\n"); builder.append("<track><location>file://").append(mf3.getAbsolutePath()).append("</location></track>\n");
builder.append(" </trackList>\n" + "</playlist>\n"); builder.append(" </trackList>\n" + "</playlist>\n");
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));

Loading…
Cancel
Save