Package javax0.repl

Class ParameterParser


  • public class ParameterParser
    extends java.lang.Object
    A parameter parser that is to parse the command line and after that to query the command parameters.
    • Constructor Summary

      Constructors 
      Constructor Description
      ParameterParser()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Optional<java.lang.String> get​(int i)
      Get the i-th parameter (starting with 0) from the parsed line.
      java.util.Optional<java.lang.String> get​(java.lang.String key)
      Get the value that was associated with the key on the parsed line.
      java.util.Optional<java.lang.String> get​(java.lang.String key, java.util.Set<java.lang.String> values)
      Get the value associated with the key using a set of predefined values.
      java.lang.String getOrDefault​(java.lang.String key, java.lang.String def)
      Get the value associated with the key or the default in case the key was not present on the command line.
      java.lang.String getOrDefault​(java.lang.String key, java.lang.String def, java.util.Set<java.lang.String> values)
      The same as get(String, Set) but if the key was not defined it will return the default value instead of null.
      • Methods inherited from class java.lang.Object

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

      • ParameterParser

        public ParameterParser()
    • Method Detail

      • get

        public java.util.Optional<java.lang.String> get​(java.lang.String key,
                                                        java.util.Set<java.lang.String> values)
        Get the value associated with the key using a set of predefined values. The actual value that was parsed from the line may be an unambiguous prefix of the possible values. In that case the value listed in the set will be the one that is defined in the set. If the value cannot be found in the set IllegalArgumentException will be thrown.
        Parameters:
        key - for which we want to retrieve the value
        values - the possible values
        Returns:
        the optional value found from the set or Optional.empty() if the parameter was not present on the command
      • get

        public java.util.Optional<java.lang.String> get​(java.lang.String key)
        Get the value that was associated with the key on the parsed line.
        Parameters:
        key - the full key as it was defined in the possible keys set
        Returns:
        the optional value as it was on the line or Optional.empty() in case the key was not present on the line
      • get

        public java.util.Optional<java.lang.String> get​(int i)
        Get the i-th parameter (starting with 0) from the parsed line. In case i is larger than the index of the last parameter Optional.empty() is returned.
        Parameters:
        i - index of the parameter
        Returns:
        the parameter from the line or Optional.empty() if i is too large
      • getOrDefault

        public java.lang.String getOrDefault​(java.lang.String key,
                                             java.lang.String def)
        Get the value associated with the key or the default in case the key was not present on the command line.
        Parameters:
        key - we look for
        def - the default value for the key
        Returns:
        the value for the key
      • getOrDefault

        public java.lang.String getOrDefault​(java.lang.String key,
                                             java.lang.String def,
                                             java.util.Set<java.lang.String> values)
        The same as get(String, Set) but if the key was not defined it will return the default value instead of null.
        Parameters:
        key - for which we want to retrieve the value
        def - the default value to be returned in case the key was not present on the line
        values - the possible values
        Returns:
        the value for the key