java.lang.Object
org.matwoess.jsourceprofiler.common.Util
Provides utility methods for all modules to use.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisAncestorOf(Path ancestorDir, Path childPath) Checks whether a child path starts with a given directory path.static booleanisJavaFile(Path path) Checks whether a file path has a ".java" extension and is a file (not a directory).static <T> T[]prependToArray(T[] array, T... prependValues) Extend an array by prepending a number of values with the same type to it.static intrunCommand(String... command) Run a generic command using the system command line.static String[]runCommandAndGetOutput(Path cwd, String... command) Run a command line in a specified directory and get the string output as a return value.static intrunCommandInDir(Path cwd, String... command) Runs a command line in a specified working directory.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
prependToArray
Extend an array by prepending a number of values with the same type to it.First an array is created with the size of the combined lengths. Then the prepend-values are copied to it, followed by copying the original array values.
- Type Parameters:
T- the common type of both arrays- Parameters:
array- the original array to be extendedprependValues- vararg array of values that will be prepended to it- Returns:
- the extended array containing the
prependValuesfollowed by the original array values
-
isJavaFile
Checks whether a file path has a ".java" extension and is a file (not a directory).- Parameters:
path- the path to be checked- Returns:
- whether the specified path is a regular file and has a ".java" extension
-
isAncestorOf
Checks whether a child path starts with a given directory path. Also returnstrueif the child is a file directly located in theancestorDir. Will returnfalseif both paths are directories and match exactly.- Parameters:
ancestorDir- the ancestor path to check againstchildPath- the path to check whether it is a descendant- Returns:
- whether the child path is located somewhere inside the parent path
-
runCommand
Run a generic command using the system command line.The
ProcessBuilderclass will be used to execute it.- Parameters:
command- an array of strings forming a command by joining it with" "- Returns:
- the exit code of the executed command
-
runCommandInDir
Runs a command line in a specified working directory.like
runCommand(java.lang.String...)but with a directory to execute from.- Parameters:
cwd- the current working directory that will be passed to theProcessBuildercommand- the array of strings forming the command- Returns:
- the exit code of the executed command
-
runCommandAndGetOutput
Run a command line in a specified directory and get the string output as a return value.- Parameters:
cwd- the current working directory that will be passed to theProcessBuildercommand- the array of strings forming the command- Returns:
- an array of strings representing the output of the executed command
-