Class CommandHelper


  • public class CommandHelper
    extends java.lang.Object
    A utility that provides convenience methods for working with command lines.
    • Constructor Summary

      Constructors 
      Constructor Description
      CommandHelper()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String[] refreshCmds​(java.util.Optional<java.lang.String> hyphen, java.lang.String... commands)
      Produces String array containing one of two Java command line tools to execute, followed by the given commands/arguments.
      java.lang.String[] toCmdArray​(java.io.File aJar, java.util.List<java.lang.String> args)
      Produces a String array that contains commands that the java tool could execute from the command line.
      java.lang.String toCommand​(java.io.File aJar, java.util.List<java.lang.String> args)
      Produces a String that the java tool could execute from the command line.
      java.lang.String toString​(java.lang.String... args)
      Produces a flattened representation of the given String array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CommandHelper

        public CommandHelper()
    • Method Detail

      • toString

        public java.lang.String toString​(java.lang.String... args)
        Produces a flattened representation of the given String array.
        Parameters:
        args - A sequence of Strings that will be flattened into a single String.
        Returns:
        All of the elements of the given args param, concatenated into a single String.
      • toCmdArray

        public java.lang.String[] toCmdArray​(java.io.File aJar,
                                             java.util.List<java.lang.String> args)
        Produces a String array that contains commands that the java tool could execute from the command line.
        Parameters:
        aJar - A File representing a jar.
        args - The sequence of commands or arguments that the main class within the given aJar param would process.
        Returns:
        A String array that expands to: „java -jar ${aJar} ${args}...
      • toCommand

        public java.lang.String toCommand​(java.io.File aJar,
                                          java.util.List<java.lang.String> args)
        Produces a String that the java tool could execute from the command line.
        Parameters:
        aJar - A File representing a jar.
        args - The sequence of commands or arguments that the main class within the given aJar param would process.
        Returns:
        A String of the form: „java -jar ${aJar} ${args}...
      • refreshCmds

        public java.lang.String[] refreshCmds​(java.util.Optional<java.lang.String> hyphen,
                                              java.lang.String... commands)
        Produces String array containing one of two Java command line tools to execute, followed by the given commands/arguments.
        Parameters:
        hyphen - An Optional containing either an „Optional.of(‚-‘)“ or „Optional.empty()“.
        commands - The sequence of commands or arguments that the particular selected program would process.
        Returns:
        java -jar ${commands}...“ if the hypen param is „Optional.of(‚-‘)“. Otherwise, returns „jar ${commands}“ if the hypen param is „Optional.empty()“ (or anything other than „Optional.of(‚-‘)“).