From 13c73cc2dce4dacbcc4a25c2054132829026665c Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 11 Jan 2020 10:59:48 +0100 Subject: [PATCH 1/2] Remove use of raw types Make use of parametrised types where possible, to please the java compiler and to make it easier to find potential issues. --- .../org/airsonic/player/dao/AbstractDao.java | 8 ++++---- .../java/org/airsonic/player/dao/AlbumDao.java | 2 +- .../java/org/airsonic/player/dao/ArtistDao.java | 2 +- .../org/airsonic/player/dao/MediaFileDao.java | 4 ++-- .../org/airsonic/player/dao/PlayQueueDao.java | 3 ++- .../org/airsonic/player/dao/PlaylistDao.java | 2 +- .../org/airsonic/player/dao/PodcastDao.java | 4 ++-- .../player/filter/ParameterDecodingFilter.java | 17 ++++++++--------- .../player/filter/ResponseHeaderFilter.java | 4 ++-- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/AbstractDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/AbstractDao.java index f412a60b..fedfff16 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/AbstractDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/AbstractDao.java @@ -88,14 +88,14 @@ public class AbstractDao { } } - protected List query(String sql, RowMapper rowMapper, Object... args) { + protected List query(String sql, RowMapper rowMapper, Object... args) { long t = System.nanoTime(); List result = getJdbcTemplate().query(sql, args, rowMapper); log(sql, t); return result; } - protected List namedQuery(String sql, RowMapper rowMapper, Map args) { + protected List namedQuery(String sql, RowMapper rowMapper, Map args) { long t = System.nanoTime(); List result = getNamedParameterJdbcTemplate().query(sql, args, rowMapper); log(sql, t); @@ -165,12 +165,12 @@ public class AbstractDao { return result; } - protected T queryOne(String sql, RowMapper rowMapper, Object... args) { + protected T queryOne(String sql, RowMapper rowMapper, Object... args) { List list = query(sql, rowMapper, args); return list.isEmpty() ? null : list.get(0); } - protected T namedQueryOne(String sql, RowMapper rowMapper, Map args) { + protected T namedQueryOne(String sql, RowMapper rowMapper, Map args) { List list = namedQuery(sql, rowMapper, args); return list.isEmpty() ? null : list.get(0); } diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/AlbumDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/AlbumDao.java index e3f00892..f6f31a15 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/AlbumDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/AlbumDao.java @@ -45,7 +45,7 @@ public class AlbumDao extends AbstractDao { private static final String QUERY_COLUMNS = "id, " + INSERT_COLUMNS; - private final RowMapper rowMapper = new AlbumMapper(); + private final RowMapper rowMapper = new AlbumMapper(); public Album getAlbum(int id) { return queryOne("select " + QUERY_COLUMNS + " from album where id=?", rowMapper, id); diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/ArtistDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/ArtistDao.java index a45d0480..810b2977 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/ArtistDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/ArtistDao.java @@ -39,7 +39,7 @@ public class ArtistDao extends AbstractDao { private static final String INSERT_COLUMNS = "name, cover_art_path, album_count, last_scanned, present, folder_id"; private static final String QUERY_COLUMNS = "id, " + INSERT_COLUMNS; - private final RowMapper rowMapper = new ArtistMapper(); + private final RowMapper rowMapper = new ArtistMapper(); /** * Returns the artist with the given name. diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java index 4803a828..ed44f20a 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java @@ -54,8 +54,8 @@ public class MediaFileDao extends AbstractDao { public static final int VERSION = 4; private final RowMapper rowMapper = new MediaFileMapper(); - private final RowMapper musicFileInfoRowMapper = new MusicFileInfoMapper(); - private final RowMapper genreRowMapper = new GenreMapper(); + private final RowMapper musicFileInfoRowMapper = new MusicFileInfoMapper(); + private final RowMapper genreRowMapper = new GenreMapper(); /** * Returns the media file for the given path. diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/PlayQueueDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/PlayQueueDao.java index 9040dc12..4b31dd6e 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/PlayQueueDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/PlayQueueDao.java @@ -18,6 +18,7 @@ */ package org.airsonic.player.dao; +import org.airsonic.player.domain.PlayQueue; import org.airsonic.player.domain.SavedPlayQueue; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Repository; @@ -37,7 +38,7 @@ public class PlayQueueDao extends AbstractDao { private static final String INSERT_COLUMNS = "username, current, position_millis, changed, changed_by"; private static final String QUERY_COLUMNS = "id, " + INSERT_COLUMNS; - private final RowMapper rowMapper = new PlayQueueMapper(); + private final RowMapper rowMapper = new PlayQueueMapper(); @Transactional public SavedPlayQueue getPlayQueue(String username) { diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/PlaylistDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/PlaylistDao.java index 30fe2f60..60378874 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/PlaylistDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/PlaylistDao.java @@ -39,7 +39,7 @@ public class PlaylistDao extends AbstractDao { private static final String INSERT_COLUMNS = "username, is_public, name, comment, file_count, duration_seconds, " + "created, changed, imported_from"; private static final String QUERY_COLUMNS = "id, " + INSERT_COLUMNS; - private final RowMapper rowMapper = new PlaylistMapper(); + private final RowMapper rowMapper = new PlaylistMapper(); public List getReadablePlaylistsForUser(String username) { diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/PodcastDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/PodcastDao.java index 69fbeb71..c7680ede 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/PodcastDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/PodcastDao.java @@ -182,8 +182,8 @@ public class PodcastDao extends AbstractDao { update(sql, id); } - private static class PodcastChannelRowMapper implements RowMapper { - public Object mapRow(ResultSet rs, int rowNum) throws SQLException { + private static class PodcastChannelRowMapper implements RowMapper { + public PodcastChannel mapRow(ResultSet rs, int rowNum) throws SQLException { return new PodcastChannel(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), PodcastStatus.valueOf(rs.getString(6)), rs.getString(7)); } diff --git a/airsonic-main/src/main/java/org/airsonic/player/filter/ParameterDecodingFilter.java b/airsonic-main/src/main/java/org/airsonic/player/filter/ParameterDecodingFilter.java index ca2e87a3..15cdfc36 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/filter/ParameterDecodingFilter.java +++ b/airsonic-main/src/main/java/org/airsonic/player/filter/ParameterDecodingFilter.java @@ -79,14 +79,13 @@ public class ParameterDecodingFilter implements Filter { } @Override - public Map getParameterMap() { - Map map = super.getParameterMap(); + public Map getParameterMap() { + Map map = super.getParameterMap(); Map result = new HashMap(); - for (Object o : map.entrySet()) { - Map.Entry entry = (Map.Entry) o; - String name = (String) entry.getKey(); - String[] values = (String[]) entry.getValue(); + for (Map.Entry entry : map.entrySet()) { + String name = entry.getKey(); + String[] values = entry.getValue(); if (name.endsWith(PARAM_SUFFIX)) { result.put(name.replace(PARAM_SUFFIX, ""), decode(values)); @@ -98,11 +97,11 @@ public class ParameterDecodingFilter implements Filter { } @Override - public Enumeration getParameterNames() { - Enumeration e = super.getParameterNames(); + public Enumeration getParameterNames() { + Enumeration e = super.getParameterNames(); Vector v = new Vector(); while (e.hasMoreElements()) { - String name = (String) e.nextElement(); + String name = e.nextElement(); if (name.endsWith(PARAM_SUFFIX)) { name = name.replace(PARAM_SUFFIX, ""); } diff --git a/airsonic-main/src/main/java/org/airsonic/player/filter/ResponseHeaderFilter.java b/airsonic-main/src/main/java/org/airsonic/player/filter/ResponseHeaderFilter.java index a4a9ab7f..958762ba 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/filter/ResponseHeaderFilter.java +++ b/airsonic-main/src/main/java/org/airsonic/player/filter/ResponseHeaderFilter.java @@ -40,8 +40,8 @@ public class ResponseHeaderFilter implements Filter { HttpServletResponse response = (HttpServletResponse) res; // Sets the provided HTTP response parameters - for (Enumeration e = filterConfig.getInitParameterNames(); e.hasMoreElements();) { - String headerName = (String) e.nextElement(); + for (Enumeration e = filterConfig.getInitParameterNames(); e.hasMoreElements();) { + String headerName = e.nextElement(); response.setHeader(headerName, filterConfig.getInitParameter(headerName)); } From e4d58e434a96d4fa692e0b8c55a23c22908181a0 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 11 Jan 2020 11:14:13 +0100 Subject: [PATCH 2/2] Please checkstyle --- .../src/main/java/org/airsonic/player/dao/PlayQueueDao.java | 1 - 1 file changed, 1 deletion(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/PlayQueueDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/PlayQueueDao.java index 4b31dd6e..0b7d12c0 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/PlayQueueDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/PlayQueueDao.java @@ -18,7 +18,6 @@ */ package org.airsonic.player.dao; -import org.airsonic.player.domain.PlayQueue; import org.airsonic.player.domain.SavedPlayQueue; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Repository;