Class KeyValueMapParameter<K,V>

java.lang.Object
google.registry.tools.params.ParameterConverterValidator<com.google.common.collect.ImmutableMap<K,V>>
google.registry.tools.params.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.StringToRegistrarRoleMap, 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.

  • Constructor Details

    • KeyValueMapParameter

      public KeyValueMapParameter(String messageForInvalid)
    • KeyValueMapParameter

      public KeyValueMapParameter()
  • Method Details

    • parseKey

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

      protected abstract V parseValue(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(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>>