Class ArgumentReader

All Implemented Interfaces:
Serializable, ConcurrentMap<String,List<String>>, Map<String,List<String>>

public class ArgumentReader extends ConcurrentHashMap<String,List<String>>
See Also:
  • Field Details

    • commandList

      protected final List<String> commandList
  • Constructor Details

    • ArgumentReader

      protected ArgumentReader(boolean parseEnv, String... args)
      Parses a string arguments into key value
      Parameters:
      args - strings with arguments
  • Method Details

    • parseArgs

      public static ArgumentReader parseArgs(String... args)
      Parses a string arguments into key values
      example: [mvn clean install --Dencoding="UTF-8", --javaVersion 8 -v=true --args=1,2,3]
      example (commands): [mvn, clean, install]
      example (kv): [Dencoding=UTF-8, javaVersion=8, v=true, args=1,2,3]
      See:
      getString(String, int, String...)
      getLong(String, int, String...)
      getDouble(String, int, String...)
      getValue(String, int, String...)
      get(String, String)
      getCommands()
      hasCommand(String)
      Parameters:
      args - strings with arguments
    • parseArgs

      public static ArgumentReader parseArgs(boolean parseEnv, String... args)
      Parses a string arguments into key values
      example: [mvn clean install --Dencoding="UTF-8", --javaVersion 8 -v=true --args=1,2,3]
      example (commands): [mvn, clean, install]
      example (kv): [Dencoding=UTF-8, javaVersion=8, v=true, args=1,2,3]
      See:
      getString(String, int, String...)
      getLong(String, int, String...)
      getDouble(String, int, String...)
      getValue(String, int, String...)
      get(String, String)
      getCommands()
      hasCommand(String)
      Parameters:
      args - strings with arguments
      parseEnv - if true, will also parse environment variables
    • getCommand

      public String getCommand()
      get command
      Returns:
      command
    • getCommand

      public String getCommand(int index)
      get command
      Parameters:
      index - number of command
      Returns:
      command or null if no command were found
    • getCommands

      public List<String> getCommands()
      get commands
      Returns:
      all commands
    • hasCommand

      public boolean hasCommand(String command)
      has command
      Returns:
      true if command exists
    • isPresent

      public boolean isPresent(String... keys)
      isPresent
      Parameters:
      keys - search for
      Returns:
      true if one key is present
    • getString

      public Optional<String> getString(String... keys)
      getString
      Parameters:
      keys - search for
      Returns:
      returns Optional value or Optional.empty() if no value is present
    • getString

      public Optional<String> getString(int index, String... keys)
      getString
      Parameters:
      keys - search for
      index - number of value
      Returns:
      returns Optional value or Optional.empty() if no value is present
    • getString

      public Optional<String> getString(String separator, int index, String... keys)
      getString
      Parameters:
      keys - search for
      index - number of value
      separator - handles values as list if present
      Returns:
      returns Optional value or Optional.empty() if no value is present
    • getStrings

      public List<String> getStrings(String... keys)
      getStrings
      Parameters:
      keys - search for
      Returns:
      returns values or empty list if no value is present
    • getStrings

      public List<String> getStrings(char separator, String... keys)
      getStrings
      Parameters:
      keys - search for
      separator - handles values as list if present
      Returns:
      returns values or empty list if no value is present
    • getStrings

      public List<String> getStrings(String separator, String[] keys)
      getStrings
      Parameters:
      keys - search for
      separator - handles values as list if present
      Returns:
      returns values or empty list if no value is present
    • getBoolean

      public boolean getBoolean(String... keys)
      getBoolean
      Parameters:
      keys - search for
      Returns:
      true if [value == 1], [value == true], [key != && value == null]
    • getBoolean

      public boolean getBoolean(int index, String... keys)
      getBoolean
      Parameters:
      keys - search for
      index - number of value
      Returns:
      true if [value == 1], [value == true], [key != && value == null]
    • getBoolean

      public boolean getBoolean(String separator, int index, String... keys)
      getBoolean
      Parameters:
      keys - search for
      index - number of value
      separator - handles values as list if present
      Returns:
      true if [value == 1], [value == true], [key != && value == null]
    • getBooleans

      public List<Boolean> getBooleans(String... keys)
      getBoolean
      Parameters:
      keys - search for
      Returns:
      boolean list if [value == 1], [value == true]
    • getBooleans

      public List<Boolean> getBooleans(String separator, String[] keys)
      getBoolean
      Parameters:
      keys - search for
      separator - handles values as list if present
      Returns:
      boolean list if [value == 1], [value == true]
    • getLong

      public Optional<Long> getLong(String... keys)
    • getLong

      public Optional<Long> getLong(int index, String... keys)
      getLong
      Parameters:
      keys - search for
      index - number of value
      Returns:
      Optional of Long if [value is an integer]
    • getLong

      public Optional<Long> getLong(String separator, int index, String... keys)
      getLong
      Parameters:
      keys - search for
      index - number of value
      separator - handles values as list if present
      Returns:
      Optional of Long if [value is an integer]
    • getLongs

      public List<Long> getLongs(String... keys)
      getLongs
      Parameters:
      keys - search for
      Returns:
      Optional of Long if [value is an integer]
    • getLongs

      public List<Long> getLongs(char separator, String... keys)
      getLongs
      Parameters:
      keys - search for
      separator - handles values as list if present
      Returns:
      Optional of Long if [value is an integer]
    • getLongs

      public List<Long> getLongs(String separator, String[] keys)
      getLongs
      Parameters:
      keys - search for
      separator - handles values as list if present
      Returns:
      Optional of Long if [value is an integer]
    • getDouble

      public Optional<Double> getDouble(String... keys)
      getDouble
      Parameters:
      keys - search for
      Returns:
      Optional of Long if [value is an integer]
    • getDouble

      public Optional<Double> getDouble(int index, String... keys)
      getDouble
      Parameters:
      keys - search for
      index - number of value
      Returns:
      Optional of Long if [value is an integer]
    • getDouble

      public Optional<Double> getDouble(String separator, int index, String... keys)
      getDouble
      Parameters:
      keys - search for
      index - number of value
      separator - handles values as list if present
      Returns:
      Optional of Long if [value is an integer]
    • getDoubles

      public List<Double> getDoubles(String... keys)
      getDoubles
      Parameters:
      keys - search for
      Returns:
      Optional of Long if [value is an integer]
    • getDoubles

      public List<Double> getDoubles(char separator, String... keys)
      getDoubles
      Parameters:
      keys - search for
      separator - handles values as list if present
      Returns:
      Optional of Long if [value is an integer]
    • getDoubles

      public List<Double> getDoubles(String separator, String[] keys)
      getDoubles
      Parameters:
      keys - search for
      separator - handles values as list if present
      Returns:
      Optional of Long if [value is an integer]
    • get

      public List<String> get(String key)
      get
      Parameters:
      key - search for
      Returns:
      list of values or empty list if not found
    • get

      public List<String> get(String separator, String key)
      get
      Parameters:
      key - search for
      separator - handles values as list if present
      Returns:
      list of values or empty list if not found
    • removeDuplicates

      protected List<String> removeDuplicates(List<String> result)
    • parseEnvironment

      public ArgumentReader parseEnvironment()
    • parseCommandLine

      protected ArgumentReader parseCommandLine(String input)
    • addKV

      protected ArgumentReader addKV(String key, String value)
    • parseCommands

      protected String parseCommands(String input)
    • addCommands

      protected ArgumentReader addCommands(String[] cmdList)
    • getStripedValue

      protected String getStripedValue(String value)
    • parseToKeyValue

      protected String[] parseToKeyValue(String argument)
    • getValues

      protected List<String> getValues(String separator, String[] keys)
    • getValue

      protected String getValue(String separator, int index, String... keys)
      getValue
      Parameters:
      keys - search for
      index - number of value
      separator - handles values as list if present
      Returns:
      value or null if no value was found
    • toBoolean

      protected Function<String,Boolean> toBoolean()
    • toLong

      protected Function<String,Long> toLong()
    • toDouble

      protected Function<String,Double> toDouble()
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map<String,List<String>>
      Overrides:
      equals in class ConcurrentHashMap<String,List<String>>
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<String,List<String>>
      Overrides:
      hashCode in class ConcurrentHashMap<String,List<String>>