Skip to content

Commit

Permalink
Adding javadoc and increasing unit test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
heuermh committed Feb 15, 2018
1 parent 9201086 commit 57b1460
Show file tree
Hide file tree
Showing 7 changed files with 664 additions and 9 deletions.
5 changes: 5 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.version.prefix}</artifactId>
Expand Down
144 changes: 143 additions & 1 deletion core/src/main/java/org/bdgenomics/cannoli/util/CommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,44 @@ abstract class CommandBuilder<C extends CommandBuilder> {
private final List<String> arguments = new ArrayList<String>();


/**
* Add one or more arguments to the list of command arguments for this command builder.
*
* @param arguments variable number of arguments to add, must not be null
* @return this command builder
*/
public final C add(final String... arguments) {
return addArguments(arguments);
}

/**
* Add one or more arguments to the list of command arguments for this command builder.
*
* @param arguments arguments to add, must not be null
* @return this command builder
*/
public final C add(final Iterable<String> arguments) {
return addArguments(arguments);
}

/**
* Add an argument to the list of command arguments for this command builder.
*
* @param argument argument to add, must not be null
* @return this command builder
*/
public final C addArgument(final String argument) {
checkNotNull(argument);
arguments.add(argument);
return (C) this;
}

/**
* Add one or more arguments to the list of command arguments for this command builder.
*
* @param arguments variable number of arguments to add, must not be null
* @return this command builder
*/
public final C addArguments(final String... arguments) {
checkNotNull(arguments);
for (String argument : arguments) {
Expand All @@ -79,6 +103,12 @@ public final C addArguments(final String... arguments) {
return (C) this;
}

/**
* Add one or more arguments to the list of command arguments for this command builder.
*
* @param arguments arguments to add, must not be null
* @return this command builder
*/
public final C addArguments(final Iterable<String> arguments) {
checkNotNull(arguments);
for (String argument : arguments) {
Expand All @@ -87,25 +117,50 @@ public final C addArguments(final Iterable<String> arguments) {
return (C) this;
}

/**
* Add an environment variable to the map of environment variables for this command builder.
*
* @param variable environment variable to add, must not be null
* @param value environment variable value to add, must not be null
* @return this command builder
*/
public final C addEnvironment(final String variable, final String value) {
checkNotNull(variable);
checkNotNull(value);
environment.put(variable, value);
return (C) this;
}

/**
* Add environment variables to the map of environment variables for this command builder.
*
* @param environment environment variables to add, must not be null
* @return this command builder
*/
public final C addEnvironment(final Map<String, String> environment) {
checkNotNull(environment);
this.environment.putAll(environment);
return (C) this;
}

/**
* Add a file to the list of files to make available locally for this command builder.
*
* @param file file to add, must not be null
* @return this command builder
*/
public final C addFile(final String file) {
checkNotNull(file);
files.add(file);
return (C) this;
}

/**
* Add zero or more files to the list of files to make available locally for this command builder.
*
* @param files variable number of files to add, must not be null
* @return this command builder
*/
public final C addFiles(final String... files) {
checkNotNull(files);
for (String file : files) {
Expand All @@ -114,6 +169,12 @@ public final C addFiles(final String... files) {
return (C) this;
}

/**
* Add files to the list of files to make available locally for this command builder.
*
* @param files files to add, must not be null
* @return this command builder
*/
public final C addFiles(final Iterable<String> files) {
checkNotNull(files);
for (String file : files) {
Expand All @@ -122,60 +183,128 @@ public final C addFiles(final Iterable<String> files) {
return (C) this;
}

/**
* Set the executable for this command builder.
*
* @param executable executable, must not be null
* @return this command builder
*/
public final C setExecutable(final String executable) {
checkNotNull(executable);
this.executable = executable;
return (C) this;
}

public final C setTimeout(@Nullable final Integer seconds) {
/**
* Set how long to let a single partition run for, in seconds, for this builder.
*
* @param timeout how long to let a single partition run for, in seconds
* @return this command builder
*/
public final C setTimeout(@Nullable final Long timeout) {
this.timeout = timeout;
return (C) this;
}

/**
* Set how long to let a single partition run for, in the specified time unit, for this builder.
*
* @param duration duration
* @param timeUnit time unit, must not be null
* @return this command builder
*/
public final C setTimeout(final long duration, final TimeUnit timeUnit) {
checkNotNull(timeUnit);
this.timeout = timeUnit.toSeconds(duration);
return (C) this;
}

/**
* Set the number of bases to flank each command invocation by for this builder.
*
* @param flankSize number of bases to flank each command invocation by
* @return this command builder
*/
public final C setFlankSize(@Nullable final Integer flankSize) {
this.flankSize = flankSize;
return (C) this;
}

/**
* Return an immutable map of environment variables for this command builder.
*
* @return an immutable map of environment variables for this command builder
*/
public final Map<String, String> getEnvironment() {
return ImmutableMap.copyOf(environment);
}

/**
* Return an immutable list of files to make available locally for this command builder.
*
* @return an immutable list of files to make available locally for this command builder
*/
public final List<String> getFiles() {
return ImmutableList.copyOf(files);
}

/**
* Return how long to let a single partition run for, in seconds, for this builder. May be null.
*
* @return how long to let a single partition run for, in seconds, for this builder
*/
public final Long getTimeout() {
return timeout;
}

/**
* Return how long to let a single partition run for, in seconds, for this builder, as an optional.
*
* @return how long to let a single partition run for, in seconds, for this builder, as an optional
*/
public final Optional<Long> getOptTimeout() {
return Optional.ofNullable(timeout);
}

/**
* Return the number of bases to flank each command invocation by for this builder. May be null.
*
* @return the number of bases to flank each command invocation by for this builder
*/
public final Integer getFlankSize() {
return flankSize;
}

/**
* Return the number of bases to flank each command invocation by for this builder, as an optional.
*
* @return the number of bases to flank each command invocation by for this builder, as an optional
*/
public final Optional<Integer> getOptFlankSize() {
return Optional.ofNullable(flankSize);
}

/**
* Return the executable for this command builder.
*
* @return the executable for this command builder
*/
public final String getExecutable() {
return executable;
}

/**
* Return an immutable list of command arguments for this command builder.
*
* @return an immutable list of command arguments for this command builder
*/
public final List<String> getArguments() {
return ImmutableList.copyOf(arguments);
}

/**
* Reset the values in this command builder. Call this method in <code>reset()</code> in subclasses.
*/
protected final void resetCommandBuilder() {
environment.clear();
files.clear();
Expand All @@ -185,6 +314,19 @@ protected final void resetCommandBuilder() {
arguments.clear();
}

/**
* Reset this command builder.
*
* @return this command builder
*/
public abstract C reset();

/**
* Build and return the command for this command builder as a list of strings.
*
* @return the command for this command builder as a list of strings.
* @throws IllegalStateException if this builder is in an illegal state, e.g.
* if required values are not set
*/
public abstract List<String> build();
}
Loading

0 comments on commit 57b1460

Please sign in to comment.