Class KeyValueMapParameter<K,​V>

  • Type Parameters:
    K - instance key type
    V - instance value type
    All Implemented Interfaces:
    com.beust.jcommander.IParameterValidator, com.beust.jcommander.IStringConverter<com.google.common.collect.ImmutableMap<K,​V>>
    Direct Known Subclasses:
    KeyValueMapParameter.CurrencyUnitToStringMap, KeyValueMapParameter.StringToIntegerMap, KeyValueMapParameter.StringToStringMap, TransitionListParameter

    public abstract class KeyValueMapParameter<K,​V>
    extends ParameterConverterValidator<com.google.common.collect.ImmutableMap<K,​V>>
    Combined converter and validator class for key-value map JCommander argument strings.

    These strings have the form <K-str>=<V-str>,[<K-str>=<V-str>]* where <K-str> and <V-str> are strings that can be parsed into instances of some key type K and value type V, respectively. This class converts a string into an ImmutableMap mapping K to V. Validation and conversion share the same logic; validation is just done by attempting conversion and throwing exceptions if need be.

    Subclasses must implement parseKey() and parseValue() to define how to parse <K-str> and <V-str> into K and V, respectively.

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      com.google.common.collect.ImmutableMap<K,​V> convert​(java.lang.String keyValueMapString)  
      protected abstract K parseKey​(java.lang.String rawKey)
      Override to define how to parse rawKey into an object of type K.
      protected abstract V parseValue​(java.lang.String rawValue)
      Override to define how to parse rawValue into an object of type V.
      protected com.google.common.collect.ImmutableMap<K,​V> processMap​(com.google.common.collect.ImmutableMap<K,​V> map)
      Override to perform any post-processing on the map.
      • Methods inherited from class java.lang.Object

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

      • KeyValueMapParameter

        public KeyValueMapParameter​(java.lang.String messageForInvalid)
      • KeyValueMapParameter

        public KeyValueMapParameter()
    • Method Detail

      • parseKey

        protected abstract K parseKey​(java.lang.String rawKey)
        Override to define how to parse rawKey into an object of type K.
      • parseValue

        protected abstract V parseValue​(java.lang.String rawValue)
        Override to define how to parse rawValue into an object of type V.
      • processMap

        protected com.google.common.collect.ImmutableMap<K,​V> processMap​(com.google.common.collect.ImmutableMap<K,​V> map)
        Override to perform any post-processing on the map.
      • convert

        public final com.google.common.collect.ImmutableMap<K,​V> convert​(java.lang.String keyValueMapString)
        Specified by:
        convert in interface com.beust.jcommander.IStringConverter<K>
        Specified by:
        convert in class ParameterConverterValidator<com.google.common.collect.ImmutableMap<K,​V>>