From 750715663d8f3c20224a861f678af1a10927bf28 Mon Sep 17 00:00:00 2001 From: Kevin Bui Date: Wed, 15 Jun 2022 12:27:42 -0400 Subject: [PATCH 1/6] Added maven plugin to generate javadocs. --- pom.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pom.xml b/pom.xml index 269999c..13631aa 100644 --- a/pom.xml +++ b/pom.xml @@ -131,6 +131,24 @@ + + org.apache.maven.plugins + maven-javadoc-plugin + 3.4.0 + + /usr/bin/javadoc + + true + + + + attach-javadocs + + jar + + + + From 58772dd53d2c0a4c6eabbc8dc9c26896e9d2718d Mon Sep 17 00:00:00 2001 From: Kevin Bui Date: Sun, 19 Jun 2022 14:22:15 -0400 Subject: [PATCH 2/6] Added javadocs for the main package. --- .../causal/cmd/AlgorithmRunException.java | 2 + .../pitt/dbmi/causal/cmd/Applications.java | 61 +++++++++++++ .../java/edu/pitt/dbmi/causal/cmd/Args.java | 86 ++++++++++++++++--- .../dbmi/causal/cmd/CausalCmdApplication.java | 21 ++++- .../edu/pitt/dbmi/causal/cmd/CmdArgs.java | 2 + .../edu/pitt/dbmi/causal/cmd/CmdOptions.java | 80 +++++++++++++++++ .../edu/pitt/dbmi/causal/cmd/CmdParams.java | 1 + .../edu/pitt/dbmi/causal/cmd/CmdParser.java | 60 +++++++++++++ .../dbmi/causal/cmd/CmdParserException.java | 2 + .../edu/pitt/dbmi/causal/cmd/DataTypes.java | 1 + .../edu/pitt/dbmi/causal/cmd/Delimiters.java | 2 + .../pitt/dbmi/causal/cmd/OptionFactory.java | 24 ++++++ .../pitt/dbmi/causal/cmd/ParseOptions.java | 2 + .../dbmi/causal/cmd/ValidationException.java | 1 + 14 files changed, 332 insertions(+), 13 deletions(-) diff --git a/src/main/java/edu/pitt/dbmi/causal/cmd/AlgorithmRunException.java b/src/main/java/edu/pitt/dbmi/causal/cmd/AlgorithmRunException.java index 8a138b7..5b6e300 100644 --- a/src/main/java/edu/pitt/dbmi/causal/cmd/AlgorithmRunException.java +++ b/src/main/java/edu/pitt/dbmi/causal/cmd/AlgorithmRunException.java @@ -19,6 +19,8 @@ package edu.pitt.dbmi.causal.cmd; /** + * The class {@code AlgorithmRunException} occurs when an algorithm that is + * attempted to run or was running failed. * * Oct 2, 2017 10:45:47 AM * diff --git a/src/main/java/edu/pitt/dbmi/causal/cmd/Applications.java b/src/main/java/edu/pitt/dbmi/causal/cmd/Applications.java index afc9a5a..60625e8 100644 --- a/src/main/java/edu/pitt/dbmi/causal/cmd/Applications.java +++ b/src/main/java/edu/pitt/dbmi/causal/cmd/Applications.java @@ -37,6 +37,8 @@ import org.apache.commons.cli.Options; /** + * The class {@code Applications} is a utility class for displaying help + * information and for getting the application jar file information.. * * Jan 8, 2019 12:04:29 PM * @@ -49,6 +51,13 @@ public final class Applications { private Applications() { } + /** + * Print out help messages to terminal for options that are not satisfied.. + * + * @param args user's input of options and arguments + * @param parseOptions options that has been parsed + * @param footer help message footer + */ public static void showHelp(String[] args, ParseOptions parseOptions, String footer) { Options opts = parseOptions.getOptions(); Options invalidOpts = parseOptions.getInvalidValueOptions(); @@ -88,6 +97,9 @@ public static void showHelp(String[] args, ParseOptions parseOptions, String foo } } + /** + * Print out a list of independence tests with descriptions to terminal.. + */ public static void showTestsAndDescriptions() { System.out.println("================================================================================"); System.out.println("Independence Tests"); @@ -103,6 +115,9 @@ public static void showTestsAndDescriptions() { }); } + /** + * Print out a list of scores with descriptions to terminal.. + */ public static void showScoresAndDescriptions() { System.out.println("================================================================================"); System.out.println("Scores"); @@ -118,6 +133,9 @@ public static void showScoresAndDescriptions() { }); } + /** + * Print out a list of algorithms with descriptions to terminal.. + */ public static void showAlgorithmsAndDescriptions() { System.out.println("================================================================================"); System.out.println("Algorithms"); @@ -133,40 +151,83 @@ public static void showAlgorithmsAndDescriptions() { }); } + /** + * Print out help messages to terminal for the given options. + * + * @param options options to print out in help messages. + */ public static void showHelp(Options options) { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(-1); formatter.printHelp(getHelpTitle(), options, true); } + /** + * Print out help messages to terminal for the given options with message + * footer. + * + * @param options options to print out in help messages. + * @param footer message footer + */ public static void showHelp(Options options, String footer) { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(-1); formatter.printHelp(getHelpTitle(), null, options, footer, true); } + /** + * Get the application version. + * + * @return the application version + */ public static String getVersion() { return String.format("Version %s", jarVersion()); } + /** + * Formats the given {@link Date} into a date-time string. + * + * @param date the time value to be formatted into a date-time string. + * @return the formatted date-time string of the given Date + */ public static String fmtDate(Date date) { return DF.format(date); } + /** + * Formats the current {@link Date} into a date-time string. + * + * @return the formatted date-time string of the current Date + */ public static String fmtDateNow() { return fmtDate(new Date(System.currentTimeMillis())); } + /** + * et the application jar filename. + * + * @return the jar filename. + */ public static String jarTitle() { return Applications.class.getPackage().getImplementationTitle(); } + /** + * Get the application jar file version. + * + * @return the jar file version + */ public static String jarVersion() { String version = Applications.class.getPackage().getImplementationVersion(); return (version == null) ? "unknown" : version; } + /** + * Get the title for the help message. + * + * @return title of the help message + */ private static String getHelpTitle() { String title = jarTitle(); String version = jarVersion(); diff --git a/src/main/java/edu/pitt/dbmi/causal/cmd/Args.java b/src/main/java/edu/pitt/dbmi/causal/cmd/Args.java index 4c2b3d7..1c8fd0a 100644 --- a/src/main/java/edu/pitt/dbmi/causal/cmd/Args.java +++ b/src/main/java/edu/pitt/dbmi/causal/cmd/Args.java @@ -30,6 +30,8 @@ import org.apache.commons.cli.ParseException; /** + * The class {@code Args} is a utility class for parsing, extracting, and + * manipulate command-line arguments . * * Mar 9, 2017 3:37:35 PM * @@ -40,6 +42,13 @@ public final class Args { private Args() { } + /** + * Remove the given option from the command-line arguments. + * + * @param args command-line arguments + * @param option option to remove + * @return command-line arguments + */ public static String[] removeLongOption(String[] args, String option) { CmdOptions cmdOptions = CmdOptions.getInstance(); List argsToKeep = new LinkedList<>(); @@ -63,9 +72,19 @@ public static String[] removeLongOption(String[] args, String option) { } } - return argsToKeep.toArray(new String[argsToKeep.size()]); + return argsToKeep.toArray(String[]::new); } + /** + * Parse options from command-line arguments by its multi-character name + * into argsMap. + * + * @param args command-line arguments + * @param options multi-character name options. + * @param argsMap holds options by name + * @throws ParseException whenever error occurs during parsing of a + * command-line. + */ public static void parseLongOptions(String[] args, Options options, Map argsMap) throws ParseException { CommandLine cmd = (new DefaultParser()).parse(options, args); options.getOptions().forEach(option -> { @@ -76,6 +95,16 @@ public static void parseLongOptions(String[] args, Options options, Map argsMap) throws ParseException { CommandLine cmd = (new DefaultParser()).parse(options, args); options.getOptions().forEach(option -> { @@ -91,6 +120,13 @@ public static void parse(String[] args, Options options, Map arg }); } + /** + * Extract multi-character name options from command-line arguments. + * + * @param args command-line arguments + * @param options multi-character name options. + * @return extracted command-line arguments + */ public static String[] extractLongOptions(String[] args, Options options) { List argsList = new LinkedList<>(); @@ -107,9 +143,17 @@ public static String[] extractLongOptions(String[] args, Options options) { } }); - return argsList.toArray(new String[argsList.size()]); + return argsList.toArray(String[]::new); } + /** + * Extract both multi-character name and single-character name options from + * command-line arguments. + * + * @param args command-line arguments + * @param options multi-character name and single-character name options. + * @return command-line arguments + */ public static String[] extractOptions(String[] args, Options options) { List argsList = new LinkedList<>(); @@ -135,15 +179,15 @@ public static String[] extractOptions(String[] args, Options options) { } }); - return argsList.toArray(new String[argsList.size()]); + return argsList.toArray(String[]::new); } /** - * Parse the long parameters from the command inputs to map where the - * parameters are map keys and parameter values are map values. + * Extract multi-character name options into a parameter-argument + * collection. * - * @param args - * @return + * @param args command-line arguments + * @return parameter-argument collection */ public static Map toMapLongOptions(String[] args) { Map map = new HashMap<>(); @@ -171,11 +215,11 @@ public static Map toMapLongOptions(String[] args) { } /** - * Parse the command inputs to map where the parameters are map keys and - * parameter values are map values. + * Extract multi-character name and and single-character name options into a + * parameter-argument collection. * - * @param args - * @return + * @param args command-line arguments + * @return parameter-argument collection */ public static Map toMapOptions(String[] args) { Map map = new HashMap<>(); @@ -204,6 +248,13 @@ public static Map toMapOptions(String[] args) { return map; } + /** + * Check if the given option is in the command-line arguments. + * + * @param args command-line arguments + * @param option option to check for + * @return true if the given option is found in the command-line arguments + */ public static boolean hasLongParam(String[] args, String option) { if (isEmpty(args)) { return false; @@ -215,10 +266,23 @@ public static boolean hasLongParam(String[] args, String option) { .anyMatch(option::equals); } + /** + * Test if the command-line arguments has any parameters or arguments. + * + * @param args command-line arguments + * @return true if the command-line arguments has not parameters or + * arguments + */ public static boolean isEmpty(String[] args) { return (args == null || args.length == 0); } + /** + * Remove extract spaces in the parameter names and arguments. + * + * @param args command-line arguments + * @return command-line arguments + */ public static String[] clean(String[] args) { return (args == null) ? new String[0] diff --git a/src/main/java/edu/pitt/dbmi/causal/cmd/CausalCmdApplication.java b/src/main/java/edu/pitt/dbmi/causal/cmd/CausalCmdApplication.java index faef6b6..f196658 100644 --- a/src/main/java/edu/pitt/dbmi/causal/cmd/CausalCmdApplication.java +++ b/src/main/java/edu/pitt/dbmi/causal/cmd/CausalCmdApplication.java @@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory; /** + * The class {@code CausalCmdApplication} is the main application . * * Mar 8, 2017 6:11:17 PM * @@ -55,7 +56,9 @@ public class CausalCmdApplication { public static boolean showExperimental; /** - * @param args the command line arguments + * Main executable method. + * + * @param args command-line arguments */ public static void main(String[] args) { args = Args.clean(args); @@ -108,6 +111,14 @@ public static void main(String[] args) { } } + /** + * Run Tetrad algorithm. + * + * @param cmdArgs command-line parameters and argument values. + * @throws AlgorithmRunException whenever algorithm fails to run + * @throws ValidationException whenever data validation fails + * @throws IOException whenever unable to read or write file + */ private static void runTetrad(CmdArgs cmdArgs) throws AlgorithmRunException, ValidationException, IOException { String outDir = cmdArgs.getOutDirectory().toString(); String prefix = cmdArgs.getFilePrefix(); @@ -118,7 +129,7 @@ private static void runTetrad(CmdArgs cmdArgs) throws AlgorithmRunException, Val Files.deleteIfExists(outTxtFile); } - try (PrintStream out = new PrintStream(new BufferedOutputStream(Files.newOutputStream(outTxtFile, StandardOpenOption.CREATE)), true)) { + try ( PrintStream out = new PrintStream(new BufferedOutputStream(Files.newOutputStream(outTxtFile, StandardOpenOption.CREATE)), true)) { writeOutParameters(cmdArgs, out); if (!cmdArgs.isSkipValidation()) { @@ -156,6 +167,12 @@ private static void runTetrad(CmdArgs cmdArgs) throws AlgorithmRunException, Val } } + /** + * Write out the command-line parameters and arguments to output stream. + * + * @param cmdArgs command-line parameters and arguments + * @param out output stream writer + */ private static void writeOutParameters(CmdArgs cmdArgs, PrintStream out) { Class algoClass = cmdArgs.getAlgorithmClass(); Class indTestClass = cmdArgs.getTestClass(); diff --git a/src/main/java/edu/pitt/dbmi/causal/cmd/CmdArgs.java b/src/main/java/edu/pitt/dbmi/causal/cmd/CmdArgs.java index d2d7199..9e54a6e 100644 --- a/src/main/java/edu/pitt/dbmi/causal/cmd/CmdArgs.java +++ b/src/main/java/edu/pitt/dbmi/causal/cmd/CmdArgs.java @@ -25,6 +25,8 @@ import java.util.Map; /** + * The class {@code CmdArgs} holds values extracted from the command-line + * arguments. * * Sep 24, 2017 10:10:21 PM * diff --git a/src/main/java/edu/pitt/dbmi/causal/cmd/CmdOptions.java b/src/main/java/edu/pitt/dbmi/causal/cmd/CmdOptions.java index ce13d6f..2fd41cd 100644 --- a/src/main/java/edu/pitt/dbmi/causal/cmd/CmdOptions.java +++ b/src/main/java/edu/pitt/dbmi/causal/cmd/CmdOptions.java @@ -34,6 +34,7 @@ import org.apache.commons.cli.Options; /** + * The class {@code CmdOptions} is a class for storing command-line options. * * Aug 27, 2017 10:42:03 PM * @@ -50,6 +51,11 @@ private CmdOptions() { addOptionalOptions(); } + /** + * Get an instance of the command-line options. + * + * @return + */ public static CmdOptions getInstance() { if (instance == null) { instance = new CmdOptions(); @@ -58,18 +64,40 @@ public static CmdOptions getInstance() { return instance; } + /** + * Destroy the instance of the command-line options. + */ public static void clear() { instance = null; } + /** + * Get multi-character name options for a given name.. + * + * @param param multi-character name + * @return + */ public Option getLongOption(String param) { return options.get(param); } + /** + * Test if the command-line options has an option with the given + * multi-character name. + * + * @param param multi-character name + * @return true if the command-line options contains the option with the + * given multi-character name. + */ public boolean hasLongParam(String param) { return options.containsKey(param); } + /** + * Get all the stored command-line options. + * + * @return command-line options + */ public Options getOptions() { Options opts = new Options(); options.entrySet().forEach(e -> { @@ -79,6 +107,11 @@ public Options getOptions() { return opts; } + /** + * Get all the application main command-line options. + * + * @return command-line options + */ public Options getMainOptions() { List