Skip to content

Commit

Permalink
Code smell fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Mar 4, 2023
1 parent b56c4e8 commit c1a5869
Show file tree
Hide file tree
Showing 53 changed files with 202 additions and 298 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ dependencies {

// JAXB API only
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'

// https://central.sonatype.com/artifact/com.google.guava/guava/
implementation 'com.google.guava:guava:31.1-jre'

//JAXB RI, Jakarta XML Binding
runtimeOnly 'com.sun.xml.bind:jaxb-impl:2.3.8'

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/christophedelory/content/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ public void setHeight(final int height)
*/
public boolean isValid()
{
return (_connected == null) ? false : _connected.booleanValue();
synchronized (this) {
return _connected != null && _connected.booleanValue();
}
}

/**
Expand All @@ -362,7 +364,6 @@ public boolean isValid()
* @throws IllegalArgumentException if the URL is not absolute.
* @throws MalformedURLException if a protocol handler for the URL could not be found, or if some other error occurred while constructing the URL.
* @throws IOException if any I/O error occurs.
* @throws SocketTimeoutException if the timeout expires before the connection can be established.
* @see #getURL
*/
public void connect() throws IOException
Expand Down Expand Up @@ -444,7 +445,7 @@ public void connect() throws IOException
@Override
public boolean equals(final Object obj)
{
return (obj == null) ? false : _urlString.equals(obj.toString());
return obj != null && _urlString.equals(obj.toString());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/christophedelory/content/type/ContentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public PlayerSupport[] getPlayerSupports()
* @see #setDescription
* @see FileFilter#getDescription
*/
@Override
public String getDescription()
{
return _description;
Expand Down Expand Up @@ -191,7 +192,7 @@ public boolean matchExtension(final String pattern)
@Override
public boolean accept(final File f)
{
return (f.isDirectory()) ? true : matchExtension(f.getName()); // Throws NullPointerException if f is null.
return f.isDirectory() || matchExtension(f.getName()); // Throws NullPointerException if f is null.
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public List<ContentType> getContentTypes()
* @return a description. Shall not be <code>null</code>.
* @see FileFilter#getDescription
*/
@Override
public String getDescription()
{
final StringBuilder sb = new StringBuilder(_title);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/christophedelory/io/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
*/
package christophedelory.io;

import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.StringWriter;

/**
Expand All @@ -51,7 +53,7 @@ public static String toString(final InputStream in, final String encoding) throw

if (encoding == null)
{
reader = new InputStreamReader(in); // Throws NullPointerException if in is null.
reader = new InputStreamReader(in, UTF_8); // Throws NullPointerException if in is null.
}
else
{
Expand All @@ -62,7 +64,7 @@ public static String toString(final InputStream in, final String encoding) throw
final char[] buffer = new char[512];
int nb = 0;

while (-1 != (nb = reader.read(buffer))) // May throw IOException.
while ((nb = reader.read(buffer)) != -1) // May throw IOException.
{
writer.write(buffer, 0, nb);
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/christophedelory/lizzy/AddToPlaylist.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,49 +109,49 @@ public static void main(final String[] args) throws Exception
* The playlist type, if specified.
*/
@Option(name="-t",usage="The output playlist type\nAllowed values: see below",metaVar="type")
private volatile String _type = null;
private String _type = null;

/**
* Specifies if the content metadata shall be fetched, if possible.
*/
@Option(name="-m",usage="Fetch if possible the media content metadata")
private volatile boolean _fetchContentMetadata = false;
private boolean _fetchContentMetadata = false;

/**
* The sub-directories shall be recursively scanned.
*/
@Option(name="-r",usage="Recursively add sub-directories contents")
private volatile boolean _recursive = false;
private boolean _recursive = false;

/**
* The output file or URL.
*/
@Option(name="-o",usage="The output file or URL\nIf missing, a file save dialog is prompted\nIf the output playlist type is not specified (-t), it will be inferred from the output file name extension",metaVar="file/URL")
private volatile String _output = null;
private String _output = null;

/**
* Specifies that the marshalled M3U playlist must use the Extension M3U format.
*/
@Option(name="-m3u:ext",usage="The output M3U playlist must use the Extension M3U format")
private volatile boolean _extM3U = false;
private boolean _extM3U = false;

/**
* Specifies that the output RSS shall make use of the RSS Media extension.
*/
@Option(name="-rss:media",usage="The output RSS playlist must use the RSS Media format")
private volatile boolean _useRSSMedia = false;
private boolean _useRSSMedia = false;

/**
* Specifies the disk identifier of the output PLP playlist.
*/
@Option(name="-plp:disk",usage="The disk identifier of the output PLP playlist\nExamples: HARP, HDD",metaVar="disk")
private volatile String _diskSpecifier = null;
private String _diskSpecifier = null;

/**
* The list of input files or directories.
*/
@Argument(usage="One or more files or directories to add to the output playlist",metaVar="input-files(s)",required=true)
private volatile ArrayList<String> _arguments = new ArrayList<String>(); // NOPMD Avoid using implementation types; use the interface instead
private ArrayList<String> _arguments = new ArrayList<>(); // NOPMD Avoid using implementation types; use the interface instead

/**
* The default no-arg constructor shall not be publicly available.
Expand Down Expand Up @@ -493,7 +493,7 @@ else if (file.isFile()) // May throw SecurityException.
sb.insert(0, '/'); // Shall not throw StringIndexOutOfBoundsException.
final String previousFileName = previousFile.getName();

if (!"/".equals(previousFileName) && !"\\".equals(previousFileName))
if (!previousFileName.equals("/") && !previousFileName.equals("\\"))
{
sb.insert(0, previousFileName); // Shall not throw StringIndexOutOfBoundsException.
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/christophedelory/lizzy/ContentTypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static void main(final String[] args)
sb.append("</tbody></table></body></html>");
}

System.out.println(sb.toString()); // NOPMD System.out.print is used
System.out.println(sb); // NOPMD System.out.print is used
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void setConnect(final boolean connect)
}

@Override
public void beginVisitMedia(final Media target) throws Exception
public void beginVisitMedia(final Media target)
{
if (target.getSource() != null)
{
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/christophedelory/lizzy/PlaylistToString.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ public class PlaylistToString extends BasePlaylistVisitor

/**
* Builds a new playlist visitor.
* @see BasePlaylistVisitor#BasePlaylistVisitor
*/
public PlaylistToString()
{
super();

_sb = new StringBuilder();
_indent = 0;
_debug = false;
Expand All @@ -83,7 +80,7 @@ public String toString()
}

@Override
public void beginVisitParallel(final Parallel target) throws Exception
public void beginVisitParallel(final Parallel target)
{
addIndent();
_sb.append("PARALLEL(x");
Expand All @@ -101,13 +98,13 @@ public void beginVisitParallel(final Parallel target) throws Exception
}

@Override
public void endVisitParallel(final Parallel target) throws Exception
public void endVisitParallel(final Parallel target)
{
_indent -= 2;
}

@Override
public void beginVisitSequence(final Sequence target) throws Exception
public void beginVisitSequence(final Sequence target)
{
addIndent();
_sb.append("SEQUENCE(x");
Expand All @@ -125,13 +122,13 @@ public void beginVisitSequence(final Sequence target) throws Exception
}

@Override
public void endVisitSequence(final Sequence target) throws Exception
public void endVisitSequence(final Sequence target)
{
_indent -= 2;
}

@Override
public void beginVisitMedia(final Media target) throws Exception
public void beginVisitMedia(final Media target)
{
addIndent();
_sb.append("MEDIA(x");
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/christophedelory/lizzy/Transcode.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@
*/
package christophedelory.lizzy;

import static java.nio.charset.StandardCharsets.UTF_8;

import christophedelory.playlist.Playlist;
import christophedelory.playlist.SpecificPlaylist;
import christophedelory.playlist.SpecificPlaylistFactory;
import christophedelory.playlist.SpecificPlaylistProvider;
import christophedelory.playlist.m3u.M3U;
import christophedelory.playlist.plp.PLP;
import christophedelory.playlist.rss.RSSProvider;
import christophedelory.xml.Version;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.util.ArrayList;

import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;

import christophedelory.playlist.Playlist;
import christophedelory.playlist.SpecificPlaylist;
import christophedelory.playlist.SpecificPlaylistFactory;
import christophedelory.playlist.SpecificPlaylistProvider;
import christophedelory.playlist.m3u.M3U;
import christophedelory.playlist.plp.PLP;
import christophedelory.playlist.rss.RSSProvider;
import christophedelory.xml.Version;

/**
* Converts a given playlist file to a specified format.
* @since 0.2.0
Expand All @@ -73,7 +73,7 @@ public static void buildCurrentVersion(final String resourceName) throws Excepti
final URL url = Version.class.getClassLoader().getResource(resourceName); // May throw SecurityException. Throws NullPointerException if resourceName is null.

if (url != null) {
final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); // May throw IOException. Throws NullPointerException if url is null.
final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), UTF_8)); // May throw IOException. Throws NullPointerException if url is null.

final String version = reader.readLine(); // May throw IOException.
Version.CURRENT = Version.valueOf(version); // Throws NullPointerException if version is null. Should not throw IllegalArgumentException, IndexOutOfBoundsException, NumberFormatException.
Expand Down Expand Up @@ -126,55 +126,55 @@ public static void main(final String[] args) throws Exception
* The playlist type, if specified.
*/
@Option(name="-t",usage="The output playlist type\nAllowed values: see below\nIf missing, the input playlist type is used",metaVar="type")
private volatile String _type = null;
private String _type = null;

/**
* Specifies if the intermediate generic playlist shall be displayed or not.
*/
@Option(name="-g",usage="Show the intermediate generic playlist")
private volatile boolean _showGenericPlaylist = false;
private boolean _showGenericPlaylist = false;

/**
* Specifies if the (parsed) input playlist shall be displayed or not.
*/
@Option(name="-i",usage="Show the parsed input playlist")
private volatile boolean _showInputPlaylist = false;
private boolean _showInputPlaylist = false;

/**
* Specifies if the content metadata shall be fetched, if possible.
*/
@Option(name="-m",usage="Fetch if possible the media content metadata")
private volatile boolean _fetchContentMetadata = false;
private boolean _fetchContentMetadata = false;

/**
* The output file or URL.
*/
@Option(name="-o",usage="The output file or URL\nIf missing, stdout is used\nIf the output playlist type is not specified (-t), it will be inferred from the output file name extension",metaVar="file/URL")
private volatile String _output = null;
private String _output = null;

/**
* Specifies that the marshalled M3U playlist must use the Extension M3U format.
*/
@Option(name="-m3u:ext",usage="The output M3U playlist must use the Extension M3U format")
private volatile boolean _extM3U = false;
private boolean _extM3U = false;

/**
* Specifies that the output RSS shall make use of the RSS Media extension.
*/
@Option(name="-rss:media",usage="The output RSS playlist must use the RSS Media format")
private volatile boolean _useRSSMedia = false;
private boolean _useRSSMedia = false;

/**
* Specifies the disk identifier of the output PLP playlist.
*/
@Option(name="-plp:disk",usage="The disk identifier of the output PLP playlist\nExamples: HARP, HDD",metaVar="disk")
private volatile String _diskSpecifier = null;
private String _diskSpecifier = null;

/**
* The input file or URL.
*/
@Argument(usage="The input playlist file or URL",metaVar="input-playlist",required=true)
private volatile ArrayList<String> _arguments = new ArrayList<String>(); // NOPMD Avoid using implementation types; use the interface instead
private ArrayList<String> _arguments = new ArrayList<String>(); // NOPMD Avoid using implementation types; use the interface instead

/**
* The default no-arg constructor shall not be publicly available.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/christophedelory/player/PlayerSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public enum Player
VLC_MEDIA_PLAYER,
WINAMP,
WINDOWS_MEDIA_PLAYER,
};
}

/**
* Returns a string representation of the specified player.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public abstract class AbstractPlaylistProvider implements SpecificPlaylistProvider
{
protected Log logger;
protected final Log logger;

public AbstractPlaylistProvider(Class clazz) {
this.logger = LogFactory.getLog(clazz);
Expand Down
Loading

0 comments on commit c1a5869

Please sign in to comment.