Fixes code style of utility classes

This commit is contained in:
Kristian Knarvik 2020-05-08 19:12:09 +02:00
parent 857c8f29a4
commit 4f07fd09fd
6 changed files with 84 additions and 41 deletions

View File

@ -18,13 +18,14 @@ import java.util.List;
*/ */
public final class FFMpegHelper { public final class FFMpegHelper {
private static final String PROBE_SPLIT_CHARACTER = "øæåÆØå";
private FFMpegHelper() { private FFMpegHelper() {
} }
private static final String PROBE_SPLIT_CHARACTER = "øæåÆØå";
/** /**
* Gets streams from a file * Gets streams from a file
*
* @param ffprobePath <p>The path/command to ffprobe.</p> * @param ffprobePath <p>The path/command to ffprobe.</p>
* @param file <p>The file to probe.</p> * @param file <p>The file to probe.</p>
* @return <p>A list of StreamObjects.</p> * @return <p>A list of StreamObjects.</p>
@ -36,6 +37,7 @@ public final class FFMpegHelper {
/** /**
* Gets a list of all streams in a file * Gets a list of all streams in a file
*
* @param ffprobePath <p>The path/command to ffprobe.</p> * @param ffprobePath <p>The path/command to ffprobe.</p>
* @param file <p>The file to probe.</p> * @param file <p>The file to probe.</p>
* @return <p>A list of streams.</p> * @return <p>A list of streams.</p>
@ -69,6 +71,7 @@ public final class FFMpegHelper {
/** /**
* Takes a list of all streams and parses each stream into one of three objects * Takes a list of all streams and parses each stream into one of three objects
*
* @param streams <p>A list of all streams for the current file.</p> * @param streams <p>A list of all streams for the current file.</p>
* @param file <p>The file currently being converted.</p> * @param file <p>The file currently being converted.</p>
* @return <p>A list of StreamObjects.</p> * @return <p>A list of StreamObjects.</p>
@ -95,6 +98,7 @@ public final class FFMpegHelper {
/** /**
* Checks whether there exists an external image subtitle with the same filename as the file * Checks whether there exists an external image subtitle with the same filename as the file
*
* @param ffprobePath <p>The path/command to ffprobe.</p> * @param ffprobePath <p>The path/command to ffprobe.</p>
* @param directory <p>The directory containing the file.</p> * @param directory <p>The directory containing the file.</p>
* @param convertingFile <p>The file to be converted.</p> * @param convertingFile <p>The file to be converted.</p>
@ -127,6 +131,7 @@ public final class FFMpegHelper {
/** /**
* Starts and prints output of a process * Starts and prints output of a process
*
* @param process <p>The process to run.</p> * @param process <p>The process to run.</p>
* @param folder <p>The folder the process should run in.</p> * @param folder <p>The folder the process should run in.</p>
* @throws IOException <p>If the process can't be readProcess.</p> * @throws IOException <p>If the process can't be readProcess.</p>
@ -149,6 +154,7 @@ public final class FFMpegHelper {
/** /**
* Reads from a process reader * Reads from a process reader
*
* @param reader <p>The reader of a process.</p> * @param reader <p>The reader of a process.</p>
* @return <p>The output from the readProcess.</p> * @return <p>The output from the readProcess.</p>
* @throws IOException <p>On reader failure.</p> * @throws IOException <p>On reader failure.</p>
@ -164,6 +170,7 @@ public final class FFMpegHelper {
/** /**
* Creates a list containing all required arguments for converting a video to a web playable video * Creates a list containing all required arguments for converting a video to a web playable video
*
* @param executable <p>The executable to use (ffmpeg/ffprobe).</p> * @param executable <p>The executable to use (ffmpeg/ffprobe).</p>
* @param fileName <p>The name of the file to execute on.</p> * @param fileName <p>The name of the file to execute on.</p>
* @return <p>A base list of ffmpeg commands for converting a video for web</p> * @return <p>A base list of ffmpeg commands for converting a video for web</p>
@ -183,6 +190,7 @@ public final class FFMpegHelper {
/** /**
* Creates a list containing command line arguments for a general file * Creates a list containing command line arguments for a general file
*
* @param executable <p>The executable to use (ffmpeg/ffprobe).</p> * @param executable <p>The executable to use (ffmpeg/ffprobe).</p>
* @param fileName <p>The name of the file to execute on.</p> * @param fileName <p>The name of the file to execute on.</p>
* @return <p>A base list of ffmpeg commands for converting a file.</p> * @return <p>A base list of ffmpeg commands for converting a file.</p>
@ -198,6 +206,7 @@ public final class FFMpegHelper {
/** /**
* Adds debugging parameters for only converting parts of a file * Adds debugging parameters for only converting parts of a file
*
* @param command <p>The list containing the command to run.</p> * @param command <p>The list containing the command to run.</p>
* @param start <p>The offset before converting.</p> * @param start <p>The offset before converting.</p>
* @param length <p>The offset for stopping the conversion.</p> * @param length <p>The offset for stopping the conversion.</p>
@ -211,6 +220,7 @@ public final class FFMpegHelper {
/** /**
* Parses a list of video stream parameters to a video stream object * Parses a list of video stream parameters to a video stream object
*
* @param streamParts <p>A list of parameters belonging to an video stream.</p> * @param streamParts <p>A list of parameters belonging to an video stream.</p>
* @param relativeIndex <p>The relative index of the video stream.</p> * @param relativeIndex <p>The relative index of the video stream.</p>
* @return <p>A SubtitleStream object.</p> * @return <p>A SubtitleStream object.</p>
@ -237,6 +247,7 @@ public final class FFMpegHelper {
/** /**
* Parses a list of audio stream parameters to an audio stream object * Parses a list of audio stream parameters to an audio stream object
*
* @param streamParts <p>A list of parameters belonging to an audio stream.</p> * @param streamParts <p>A list of parameters belonging to an audio stream.</p>
* @param relativeIndex <p>The relative index of the audio stream.</p> * @param relativeIndex <p>The relative index of the audio stream.</p>
* @return <p>A SubtitleStream object.</p> * @return <p>A SubtitleStream object.</p>
@ -266,6 +277,7 @@ public final class FFMpegHelper {
/** /**
* Parses a list of subtitle stream parameters to a subtitle stream object * Parses a list of subtitle stream parameters to a subtitle stream object
*
* @param streamParts <p>A list of parameters belonging to a subtitle stream.</p> * @param streamParts <p>A list of parameters belonging to a subtitle stream.</p>
* @param relativeIndex <p>The relative index of the subtitle.</p> * @param relativeIndex <p>The relative index of the subtitle.</p>
* @param file <p>The file currently being converted.</p> * @param file <p>The file currently being converted.</p>

View File

@ -16,6 +16,7 @@ public final class FileUtil {
/** /**
* Adds parentheses with an integer if the output file already exists * Adds parentheses with an integer if the output file already exists
*
* @param targetPath <p>The path the file should ideally be saved at.</p> * @param targetPath <p>The path the file should ideally be saved at.</p>
* @param extension <p>The extension of the target file.</p> * @param extension <p>The extension of the target file.</p>
* @return <p>A filename guaranteed not to collide with other files.</p> * @return <p>A filename guaranteed not to collide with other files.</p>
@ -32,6 +33,7 @@ public final class FileUtil {
/** /**
* Gets filename without extension from File object * Gets filename without extension from File object
*
* @param file <p>A file object.</p> * @param file <p>A file object.</p>
* @return <p>A filename.</p> * @return <p>A filename.</p>
*/ */
@ -41,6 +43,7 @@ public final class FileUtil {
/** /**
* Removes the extension from a file name * Removes the extension from a file name
*
* @param file <p>A filename.</p> * @param file <p>A filename.</p>
* @return <p>A filename without its extension.</p> * @return <p>A filename without its extension.</p>
*/ */
@ -50,15 +53,20 @@ public final class FileUtil {
/** /**
* Recursively lists all files in a folder * Recursively lists all files in a folder
*
* @param folder <p>The folder to start from.</p> * @param folder <p>The folder to start from.</p>
* @param maxRecursions <p>Maximum number of recursions</p> * @param maxRecursions <p>Maximum number of recursions</p>
* @return A list of files * @return A list of files
*/ */
public static File[] listFilesRecursive(File folder, String[] extensions, int maxRecursions) { 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() && File[] listOfFiles = folder.listFiles((file) -> file.isFile() &&
ListUtil.listContains(extensions, (item) -> file.getName().endsWith(item))); ListUtil.listContains(extensions, (item) -> file.getName().endsWith(item)));
if (listOfFiles == null) { return null; } if (listOfFiles == null) {
return null;
}
if (maxRecursions > 1) { if (maxRecursions > 1) {
File[] listOfFolders = folder.listFiles((dir, name) -> new File(dir, name).isDirectory()); File[] listOfFolders = folder.listFiles((dir, name) -> new File(dir, name).isDirectory());
if (listOfFolders != null) { if (listOfFolders != null) {
@ -94,6 +102,7 @@ public final class FileUtil {
/** /**
* Gets a resource as an InputStream * Gets a resource as an InputStream
*
* @param resourceName <p>The name of the resource you want to read.</p> * @param resourceName <p>The name of the resource you want to read.</p>
* @return <p>An input stream which can be used to access the resource.</p> * @return <p>An input stream which can be used to access the resource.</p>
*/ */

View File

@ -15,6 +15,7 @@ public final class ListUtil {
/** /**
* Combines two arrays to one * Combines two arrays to one
*
* @param listA <p>The first array.</p> * @param listA <p>The first array.</p>
* @param listB <p>The second array.</p> * @param listB <p>The second array.</p>
* @param <T> <p>The type of the two lists.</p> * @param <T> <p>The type of the two lists.</p>
@ -32,6 +33,7 @@ public final class ListUtil {
/** /**
* Gets all list items according to the predicate * Gets all list items according to the predicate
*
* @param list <p>The list to process.</p> * @param list <p>The list to process.</p>
* @param predicate <p>The predicate to test.</p> * @param predicate <p>The predicate to test.</p>
* @param <T> <p>The type of the list.</p> * @param <T> <p>The type of the list.</p>
@ -63,6 +65,7 @@ public final class ListUtil {
/** /**
* Gets a list from a comma separated string at index in list * Gets a list from a comma separated string at index in list
*
* @param list <p>A list of tokens.</p> * @param list <p>A list of tokens.</p>
* @param index <p>The index of the token containing comma separated entries.</p> * @param index <p>The index of the token containing comma separated entries.</p>
* @return <p>A string list.</p> * @return <p>A string list.</p>

View File

@ -8,14 +8,15 @@ import java.io.OutputStreamWriter;
* A class which helps with outputting information * A class which helps with outputting information
*/ */
public final class OutputUtil { public final class OutputUtil {
private static boolean debug;
private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
private static boolean debug;
private OutputUtil() { private OutputUtil() {
} }
/** /**
* Sets whether to show debug messages * Sets whether to show debug messages
*
* @param debug <p>The debug message to show.</p> * @param debug <p>The debug message to show.</p>
*/ */
public static void setDebug(boolean debug) { public static void setDebug(boolean debug) {
@ -24,6 +25,7 @@ public final class OutputUtil {
/** /**
* Prints something and a newline to the commandline efficiently * Prints something and a newline to the commandline efficiently
*
* @param input <p>The text to print.</p> * @param input <p>The text to print.</p>
* @throws IOException <p>If a write is not possible.</p> * @throws IOException <p>If a write is not possible.</p>
*/ */
@ -36,6 +38,7 @@ public final class OutputUtil {
/** /**
* Prints a string * Prints a string
*
* @param input <p>The string to print.</p> * @param input <p>The string to print.</p>
* @throws IOException <p>If the writer fails to write.</p> * @throws IOException <p>If the writer fails to write.</p>
*/ */
@ -47,6 +50,7 @@ public final class OutputUtil {
/** /**
* Prints a newline * Prints a newline
*
* @throws IOException <p>If a write is not possible.</p> * @throws IOException <p>If a write is not possible.</p>
*/ */
public static void println() throws IOException { public static void println() throws IOException {
@ -56,6 +60,7 @@ public final class OutputUtil {
/** /**
* Closes the writer * Closes the writer
*
* @throws IOException <p>If the writer cannot be closed.</p> * @throws IOException <p>If the writer cannot be closed.</p>
*/ */
public static void close() throws IOException { public static void close() throws IOException {
@ -64,6 +69,7 @@ public final class OutputUtil {
/** /**
* Prints a message if debug messages should be shown * Prints a message if debug messages should be shown
*
* @param message <p>The debug message to show.</p> * @param message <p>The debug message to show.</p>
* @throws IOException <p>If a write is not possible.</p> * @throws IOException <p>If a write is not possible.</p>
*/ */

View File

@ -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.ArrayList;
import java.util.List; 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 * This function parses command inputs into understandable converter instructions
*
* @param tokens <p>A list of tokens containing all arguments</p> * @param tokens <p>A list of tokens containing all arguments</p>
*/ */
private static void parse(List<String> tokens) { private static void parse(List<String> tokens) {
String[] types = {"animeconverter", "audioconverter", "videoconverter"}; String[] types = {"animeconverter", "audioconverter", "videoconverter"};
Main.converterArgument[] commonArgs = { ConverterArgument[] commonArgs = {
new Main.converterArgument("-recursions", true, Main.converterArgumentValueType.INT) new ConverterArgument("-recursions", true, ConverterArgumentValue.INT)
}; };
Main.converterArgument[] animeArgs = { ConverterArgument[] animeArgs = {
}; };
Main.converterArgument[] audioArgs = { ConverterArgument[] audioArgs = {
new Main.converterArgument("-outext", true, new ConverterArgument("-outext", true,
Main.converterArgumentValueType.SINGLE_VALUE) ConverterArgumentValue.SINGLE_VALUE)
}; };
Main.converterArgument[] videoArgs = { ConverterArgument[] videoArgs = {
new Main.converterArgument("-outext", true, new ConverterArgument("-outext", true,
Main.converterArgumentValueType.SINGLE_VALUE) ConverterArgumentValue.SINGLE_VALUE)
}; };
String type = tokens.get(0).toLowerCase(); 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."); throw new IllegalArgumentException("Unknown converter type chosen.");
} }
if (tokens.size() < 2) { if (tokens.size() < 2) {
@ -40,6 +50,7 @@ public class Parser {
/** /**
* Tokenizes a string * Tokenizes a string
*
* @param input <p>A string.</p> * @param input <p>A string.</p>
* @return <p>A list of tokens.</p> * @return <p>A list of tokens.</p>
*/ */
@ -89,6 +100,7 @@ public class Parser {
/** /**
* Checks whether a string builder is empty * Checks whether a string builder is empty
*
* @param builder <p>The string builder to check.</p> * @param builder <p>The string builder to check.</p>
* @return <p>True if the string builder is non empty.</p> * @return <p>True if the string builder is non empty.</p>
*/ */

View File

@ -10,6 +10,7 @@ final class StringUtil {
/** /**
* Finds all substrings between two substrings in a string * Finds all substrings between two substrings in a string
*
* @param string <p>The string containing the substrings.</p> * @param string <p>The string containing the substrings.</p>
* @param start <p>The substring before the wanted substring.</p> * @param start <p>The substring before the wanted substring.</p>
* @param end <p>The substring after the wanted substring.</p> * @param end <p>The substring after the wanted substring.</p>