From 4f07fd09fdb692f7fea33ed161a39e3b885fc2a9 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 8 May 2020 19:12:09 +0200 Subject: [PATCH] Fixes code style of utility classes --- .../ffmpegconverter/utility/FFMpegHelper.java | 44 ++++++++++++------- .../ffmpegconverter/utility/FileUtil.java | 19 +++++--- .../ffmpegconverter/utility/ListUtil.java | 13 +++--- .../ffmpegconverter/utility/OutputUtil.java | 8 +++- .../ffmpegconverter/{ => utility}/Parser.java | 36 ++++++++++----- .../ffmpegconverter/utility/StringUtil.java | 5 ++- 6 files changed, 84 insertions(+), 41 deletions(-) rename src/main/java/net/knarcraft/ffmpegconverter/{ => utility}/Parser.java (78%) diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java index ffee661..a16db35 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java @@ -18,15 +18,16 @@ import java.util.List; */ public final class FFMpegHelper { + private static final String PROBE_SPLIT_CHARACTER = "øæåÆØå"; + private FFMpegHelper() { } - private static final String PROBE_SPLIT_CHARACTER = "øæåÆØå"; - /** * Gets streams from a file + * * @param ffprobePath

The path/command to ffprobe.

- * @param file

The file to probe.

+ * @param file

The file to probe.

* @return

A list of StreamObjects.

* @throws IOException

If the process can't be readProcess.

*/ @@ -36,8 +37,9 @@ public final class FFMpegHelper { /** * Gets a list of all streams in a file + * * @param ffprobePath

The path/command to ffprobe.

- * @param file

The file to probe.

+ * @param file

The file to probe.

* @return

A list of streams.

* @throws IOException

If something goes wrong while probing.

*/ @@ -69,8 +71,9 @@ public final class FFMpegHelper { /** * Takes a list of all streams and parses each stream into one of three objects + * * @param streams

A list of all streams for the current file.

- * @param file

The file currently being converted.

+ * @param file

The file currently being converted.

* @return

A list of StreamObjects.

*/ private static List parseStreams(String ffprobePath, String[] streams, File file) throws IOException { @@ -95,8 +98,9 @@ public final class FFMpegHelper { /** * Checks whether there exists an external image subtitle with the same filename as the file - * @param ffprobePath

The path/command to ffprobe.

- * @param directory

The directory containing the file.

+ * + * @param ffprobePath

The path/command to ffprobe.

+ * @param directory

The directory containing the file.

* @param convertingFile

The file to be converted.

* @return

The extension of the subtitle or empty if no subtitle was found.

*/ @@ -127,8 +131,9 @@ public final class FFMpegHelper { /** * Starts and prints output of a process + * * @param process

The process to run.

- * @param folder

The folder the process should run in.

+ * @param folder

The folder the process should run in.

* @throws IOException

If the process can't be readProcess.

*/ public static void convertProcess(ProcessBuilder process, File folder) throws IOException { @@ -149,6 +154,7 @@ public final class FFMpegHelper { /** * Reads from a process reader + * * @param reader

The reader of a process.

* @return

The output from the readProcess.

* @throws IOException

On reader failure.

@@ -164,8 +170,9 @@ public final class FFMpegHelper { /** * Creates a list containing all required arguments for converting a video to a web playable video + * * @param executable

The executable to use (ffmpeg/ffprobe).

- * @param fileName

The name of the file to execute on.

+ * @param fileName

The name of the file to execute on.

* @return

A base list of ffmpeg commands for converting a video for web

*/ public static List getFFMpegWebVideoCommand(String executable, String fileName) { @@ -183,8 +190,9 @@ public final class FFMpegHelper { /** * Creates a list containing command line arguments for a general file + * * @param executable

The executable to use (ffmpeg/ffprobe).

- * @param fileName

The name of the file to execute on.

+ * @param fileName

The name of the file to execute on.

* @return

A base list of ffmpeg commands for converting a file.

*/ public static List getFFMpegGeneralFileCommand(String executable, String fileName) { @@ -198,9 +206,10 @@ public final class FFMpegHelper { /** * Adds debugging parameters for only converting parts of a file + * * @param command

The list containing the command to run.

- * @param start

The offset before converting.

- * @param length

The offset for stopping the conversion.

+ * @param start

The offset before converting.

+ * @param length

The offset for stopping the conversion.

*/ public static void addDebugArguments(List command, int start, int length) { command.add("-ss"); @@ -211,7 +220,8 @@ public final class FFMpegHelper { /** * Parses a list of video stream parameters to a video stream object - * @param streamParts

A list of parameters belonging to an video stream.

+ * + * @param streamParts

A list of parameters belonging to an video stream.

* @param relativeIndex

The relative index of the video stream.

* @return

A SubtitleStream object.

* @throws NumberFormatException

If codec index contains a non-numeric value.

@@ -237,7 +247,8 @@ public final class FFMpegHelper { /** * Parses a list of audio stream parameters to an audio stream object - * @param streamParts

A list of parameters belonging to an audio stream.

+ * + * @param streamParts

A list of parameters belonging to an audio stream.

* @param relativeIndex

The relative index of the audio stream.

* @return

A SubtitleStream object.

* @throws NumberFormatException

If codec index contains a non-numeric value.

@@ -266,9 +277,10 @@ public final class FFMpegHelper { /** * Parses a list of subtitle stream parameters to a subtitle stream object - * @param streamParts

A list of parameters belonging to a subtitle stream.

+ * + * @param streamParts

A list of parameters belonging to a subtitle stream.

* @param relativeIndex

The relative index of the subtitle.

- * @param file

The file currently being converted.

+ * @param file

The file currently being converted.

* @return

A SubtitleStream object.

* @throws NumberFormatException

If codec index contains a non-numeric value.

*/ diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/FileUtil.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/FileUtil.java index 281c783..0dfaf1c 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/FileUtil.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/FileUtil.java @@ -16,8 +16,9 @@ public final class FileUtil { /** * Adds parentheses with an integer if the output file already exists + * * @param targetPath

The path the file should ideally be saved at.

- * @param extension

The extension of the target file.

+ * @param extension

The extension of the target file.

* @return

A filename guaranteed not to collide with other files.

*/ public static String getNonCollidingFilename(String targetPath, String extension) { @@ -32,6 +33,7 @@ public final class FileUtil { /** * Gets filename without extension from File object + * * @param file

A file object.

* @return

A filename.

*/ @@ -41,6 +43,7 @@ public final class FileUtil { /** * Removes the extension from a file name + * * @param file

A filename.

* @return

A filename without its extension.

*/ @@ -50,15 +53,20 @@ public final class FileUtil { /** * Recursively lists all files in a folder - * @param folder

The folder to start from.

+ * + * @param folder

The folder to start from.

* @param maxRecursions

Maximum number of recursions

- * @return A list of files + * @return A list of files */ public static File[] listFilesRecursive(File folder, String[] extensions, int maxRecursions) { - if (maxRecursions == 0) { return null; } + if (maxRecursions == 0) { + return null; + } File[] listOfFiles = folder.listFiles((file) -> file.isFile() && ListUtil.listContains(extensions, (item) -> file.getName().endsWith(item))); - if (listOfFiles == null) { return null; } + if (listOfFiles == null) { + return null; + } if (maxRecursions > 1) { File[] listOfFolders = folder.listFiles((dir, name) -> new File(dir, name).isDirectory()); if (listOfFolders != null) { @@ -94,6 +102,7 @@ public final class FileUtil { /** * Gets a resource as an InputStream + * * @param resourceName

The name of the resource you want to read.

* @return

An input stream which can be used to access the resource.

*/ diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/ListUtil.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/ListUtil.java index 8657e3e..638180e 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/ListUtil.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/ListUtil.java @@ -15,9 +15,10 @@ public final class ListUtil { /** * Combines two arrays to one + * * @param listA

The first array.

* @param listB

The second array.

- * @param

The type of the two lists.

+ * @param

The type of the two lists.

* @return

A new array containing all elements from the two arrays.

*/ static T[] concatenate(T[] listA, T[] listB) { @@ -32,9 +33,10 @@ public final class ListUtil { /** * Gets all list items according to the predicate - * @param list

The list to process.

+ * + * @param list

The list to process.

* @param predicate

The predicate to test.

- * @param

The type of the list.

+ * @param

The type of the list.

* @return

A new list containing all matching elements.

*/ static List getMatching(List list, Predicate predicate) { @@ -50,7 +52,7 @@ public final class ListUtil { * @param list The list to test against * @param predicate A predicate to use on every element in the list * @param Anything which can be stored in a list - * @return True if at least one element fulfills the predicate + * @return True if at least one element fulfills the predicate */ static boolean listContains(T[] list, Predicate predicate) { for (T item : list) { @@ -63,7 +65,8 @@ public final class ListUtil { /** * Gets a list from a comma separated string at index in list - * @param list

A list of tokens.

+ * + * @param list

A list of tokens.

* @param index

The index of the token containing comma separated entries.

* @return

A string list.

*/ diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java index efe3413..137d9f6 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java @@ -8,14 +8,15 @@ import java.io.OutputStreamWriter; * A class which helps with outputting information */ public final class OutputUtil { - private static boolean debug; private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); + private static boolean debug; private OutputUtil() { } /** * Sets whether to show debug messages + * * @param debug

The debug message to show.

*/ public static void setDebug(boolean debug) { @@ -24,6 +25,7 @@ public final class OutputUtil { /** * Prints something and a newline to the commandline efficiently + * * @param input

The text to print.

* @throws IOException

If a write is not possible.

*/ @@ -36,6 +38,7 @@ public final class OutputUtil { /** * Prints a string + * * @param input

The string to print.

* @throws IOException

If the writer fails to write.

*/ @@ -47,6 +50,7 @@ public final class OutputUtil { /** * Prints a newline + * * @throws IOException

If a write is not possible.

*/ public static void println() throws IOException { @@ -56,6 +60,7 @@ public final class OutputUtil { /** * Closes the writer + * * @throws IOException

If the writer cannot be closed.

*/ public static void close() throws IOException { @@ -64,6 +69,7 @@ public final class OutputUtil { /** * Prints a message if debug messages should be shown + * * @param message

The debug message to show.

* @throws IOException

If a write is not possible.

*/ diff --git a/src/main/java/net/knarcraft/ffmpegconverter/Parser.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/Parser.java similarity index 78% rename from src/main/java/net/knarcraft/ffmpegconverter/Parser.java rename to src/main/java/net/knarcraft/ffmpegconverter/utility/Parser.java index 0061af3..b561cd5 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/Parser.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/Parser.java @@ -1,32 +1,42 @@ -package net.knarcraft.ffmpegconverter; +package net.knarcraft.ffmpegconverter.utility; + +import net.knarcraft.ffmpegconverter.parser.ConverterArgument; +import net.knarcraft.ffmpegconverter.parser.ConverterArgumentValue; import java.util.ArrayList; import java.util.List; -public class Parser { +/** + * A class to help with command parsing + */ +public final class Parser { + + private Parser() { + } /** * This function parses command inputs into understandable converter instructions + * * @param tokens

A list of tokens containing all arguments

*/ private static void parse(List tokens) { String[] types = {"animeconverter", "audioconverter", "videoconverter"}; - Main.converterArgument[] commonArgs = { - new Main.converterArgument("-recursions", true, Main.converterArgumentValueType.INT) + ConverterArgument[] commonArgs = { + new ConverterArgument("-recursions", true, ConverterArgumentValue.INT) }; - Main.converterArgument[] animeArgs = { + ConverterArgument[] animeArgs = { }; - Main.converterArgument[] audioArgs = { - new Main.converterArgument("-outext", true, - Main.converterArgumentValueType.SINGLE_VALUE) + ConverterArgument[] audioArgs = { + new ConverterArgument("-outext", true, + ConverterArgumentValue.SINGLE_VALUE) }; - Main.converterArgument[] videoArgs = { - new Main.converterArgument("-outext", true, - Main.converterArgumentValueType.SINGLE_VALUE) + ConverterArgument[] videoArgs = { + new ConverterArgument("-outext", true, + ConverterArgumentValue.SINGLE_VALUE) }; String type = tokens.get(0).toLowerCase(); - if (!Main.listContains(types, s -> s.equals(type))) { + if (!ListUtil.listContains(types, s -> s.equals(type))) { throw new IllegalArgumentException("Unknown converter type chosen."); } if (tokens.size() < 2) { @@ -40,6 +50,7 @@ public class Parser { /** * Tokenizes a string + * * @param input

A string.

* @return

A list of tokens.

*/ @@ -89,6 +100,7 @@ public class Parser { /** * Checks whether a string builder is empty + * * @param builder

The string builder to check.

* @return

True if the string builder is non empty.

*/ diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/StringUtil.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/StringUtil.java index da4590b..48e1dd6 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/StringUtil.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/StringUtil.java @@ -10,9 +10,10 @@ final class StringUtil { /** * Finds all substrings between two substrings in a string + * * @param string

The string containing the substrings.

- * @param start

The substring before the wanted substring.

- * @param end

The substring after the wanted substring.

+ * @param start

The substring before the wanted substring.

+ * @param end

The substring after the wanted substring.

* @return

A list of all occurrences of the substring.

*/ static String[] stringBetween(String string, String start, String end) {