Class Args

java.lang.Object
org.omegazero.common.util.Args
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Args.DefaultFormat

public abstract class Args extends Object implements Serializable
Class used for parsing command line arguments.
Since:
2.1
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    An Args implementation for the default argument format.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Map<String,Object>
    The argument data.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    getBooleanOrDefault(String key, boolean def)
    Returns the boolean value identified by the given key, or def if no value with the specified key exists or is not a boolean.
    double
    getDoubleOrDefault(String key, double def)
    Returns the double-precision floating-point number value identified by the given key, or def if no value with the specified key exists or is not a number.
    float
    getFloatOrDefault(String key, float def)
    Returns the single-precision floating-point number value identified by the given key, or def if no value with the specified key exists or is not a number.
    int
    getIntOrDefault(String key, int def)
    Returns the integer value identified by the given key, or def if no value with the specified key exists or is not a number.
    long
    getLongOrDefault(String key, long def)
    Returns the long integer value identified by the given key, or def if no value with the specified key exists or is not a number.
    Returns the string value identified by the given key, or null if no value with the specified key exists.
    Returns the string value identified by the given key, or def if no value with the specified key exists.
    static Args
    parse(String[] args)
    Parses the given array of arguments using the default format.
    abstract void
    Parses the given argument array and stores the data in this Args object.
    protected void
    put(String key, String value)
    Stores the given value identified by the key in this object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • arguments

      protected final Map<String,Object> arguments
      The argument data.
  • Constructor Details

    • Args

      public Args()
  • Method Details

    • parseArguments

      public abstract void parseArguments(String[] args)
      Parses the given argument array and stores the data in this Args object.

      Values identified as integers, booleans ("true" and "false") or floating-point numbers are automatically converted to the respective type.

      Parameters:
      args - The argument array
      Implementation Note:
      Use put(String, String) to store values
    • getValue

      public String getValue(String key)
      Returns the string value identified by the given key, or null if no value with the specified key exists.
      Parameters:
      key - The key string
      Returns:
      The value or null if it does not exist
    • getValueOrDefault

      public String getValueOrDefault(String key, String def)
      Returns the string value identified by the given key, or def if no value with the specified key exists.
      Parameters:
      key - The key string
      def - The default value to return if no value with the given key exists
      Returns:
      The value or def if it does not exist
    • getIntOrDefault

      public int getIntOrDefault(String key, int def)
      Returns the integer value identified by the given key, or def if no value with the specified key exists or is not a number.
      Parameters:
      key - The key string
      def - The default value to return if no value with the given key exists
      Returns:
      The value or def if it does not exist
    • getLongOrDefault

      public long getLongOrDefault(String key, long def)
      Returns the long integer value identified by the given key, or def if no value with the specified key exists or is not a number.
      Parameters:
      key - The key string
      def - The default value to return if no value with the given key exists
      Returns:
      The value or def if it does not exist
    • getFloatOrDefault

      public float getFloatOrDefault(String key, float def)
      Returns the single-precision floating-point number value identified by the given key, or def if no value with the specified key exists or is not a number.
      Parameters:
      key - The key string
      def - The default value to return if no value with the given key exists
      Returns:
      The value or def if it does not exist
    • getDoubleOrDefault

      public double getDoubleOrDefault(String key, double def)
      Returns the double-precision floating-point number value identified by the given key, or def if no value with the specified key exists or is not a number.
      Parameters:
      key - The key string
      def - The default value to return if no value with the given key exists
      Returns:
      The value or def if it does not exist
    • getBooleanOrDefault

      public boolean getBooleanOrDefault(String key, boolean def)
      Returns the boolean value identified by the given key, or def if no value with the specified key exists or is not a boolean.
      Parameters:
      key - The key string
      def - The default value to return if no value with the given key exists
      Returns:
      The value or def if it does not exist
    • put

      protected void put(String key, String value)
      Stores the given value identified by the key in this object. The value is automatically converted to the appropriate type, if applicable (for example, strings consisting only of digits are converted to a number).
      Parameters:
      key - The key
      value - The value
    • parse

      public static Args parse(String[] args)
      Parses the given array of arguments using the default format. See Args.DefaultFormat.parseArguments(String[]).
      Parameters:
      args - The argument array
      Returns:
      The Args object representing the parsed data