Class ArgumentParser

java.lang.Object
com.kheops.util.ArgumentParser

public class ArgumentParser extends Object
Utility class that extracts parameter values from an argument array received in a main(String[]) method.
The following command line format is assumed:
java application -param1 value1 -param2 "value with spaces" -flag1
calling getArgValue("-param1", "default") would return value1 calling getArgValue("-param2", "default") would return value with spaces calling isArgPresent("-flag1") would return true.
  • Constructor Details

    • ArgumentParser

      public ArgumentParser(String[] args)
      Constructs new instance with the specified array of arguments.
      Parameters:
      args - the array of arguments
    • ArgumentParser

      public ArgumentParser(String args)
      Constructs new instance with the specified argument line.
      Parameters:
      args - the argument line
  • Method Details

    • getArgValue

      public String getArgValue(String argName, String defaultValue)
      Extracts the value for the specified argument. The value is the argument following the requested argument name in the argument array. If not present, specified default value is returned.
      Parameters:
      argName - the arguement to extract the value for
      defaultValue - value returned if argument name not found
      Returns:
      the argument value
    • isArgPresent

      public boolean isArgPresent(String argName)
      Tests if an argument name is present. Useful for testing the presence of flags that don't have values.
      Parameters:
      argName - the argument name to search for
      Returns:
      true if the specified aruement name is found
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getArgs

      public String[] getArgs()
      Returns:
      the list of arguments managed by this parser