Skip to content

Commit

Permalink
Fixed conflicts and bumped up update-version number.
Browse files Browse the repository at this point in the history
  • Loading branch information
kvb2univpitt committed Jul 10, 2022
2 parents dfe1204 + 75834d8 commit 8cefd71
Show file tree
Hide file tree
Showing 30 changed files with 919 additions and 101 deletions.
20 changes: 19 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.pitt.dbmi</groupId>
<artifactId>causal-cmd</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -131,6 +131,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<javadocExecutable>/usr/bin/javadoc</javadocExecutable>
<!--<show>private</show>-->
<nohelp>true</nohelp>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/edu/pitt/dbmi/causal/cmd/Applications.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,30 @@
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
*
* @author Kevin V. Bui ([email protected])
*/
public final class Applications {

/**
* Use to convert {@link Date} into a date-time string.
*/
private static final DateFormat DF = new SimpleDateFormat("EEE, MMMM dd, yyyy hh:mm:ss a");

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();
Expand Down Expand Up @@ -88,6 +100,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");
Expand All @@ -103,6 +118,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");
Expand All @@ -118,6 +136,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");
Expand All @@ -133,40 +154,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();
Expand Down
86 changes: 75 additions & 11 deletions src/main/java/edu/pitt/dbmi/causal/cmd/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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<String> argsToKeep = new LinkedList<>();
Expand All @@ -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<String, String> argsMap) throws ParseException {
CommandLine cmd = (new DefaultParser()).parse(options, args);
options.getOptions().forEach(option -> {
Expand All @@ -76,6 +95,16 @@ public static void parseLongOptions(String[] args, Options options, Map<String,
});
}

/**
* Parse options from command-line arguments by its single-character name
* into argsMap.
*
* @param args command-line arguments
* @param options single-character name options.
* @param argsMap holds options by name
* @throws ParseException whenever error occurs during parsing of a
* command-line.
*/
public static void parse(String[] args, Options options, Map<String, String> argsMap) throws ParseException {
CommandLine cmd = (new DefaultParser()).parse(options, args);
options.getOptions().forEach(option -> {
Expand All @@ -91,6 +120,13 @@ public static void parse(String[] args, Options options, Map<String, String> 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<String> argsList = new LinkedList<>();

Expand All @@ -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<String> argsList = new LinkedList<>();

Expand All @@ -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<String, String> toMapLongOptions(String[] args) {
Map<String, String> map = new HashMap<>();
Expand Down Expand Up @@ -171,11 +215,11 @@ public static Map<String, String> 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<String, String> toMapOptions(String[] args) {
Map<String, String> map = new HashMap<>();
Expand Down Expand Up @@ -204,6 +248,13 @@ public static Map<String, String> 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;
Expand All @@ -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]
Expand Down
Loading

0 comments on commit 8cefd71

Please sign in to comment.