package com.github.kahalemakai.opencsv.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Log4j
@RequiredArgsConstructor(staticName = "init")
public class ParameterMap {
    private final Map<String, String> parameters = new HashMap<>();
    private final Pattern VALID_NAME = Pattern.compile("^[a-zA-Z]+[a-zA-Z0-9-_]*:[a-zA-Z]+[a-zA-Z0-9-_]*$");

    public void put(final String name, final String value) throws IllegalStateException, IllegalArgumentException {
        final Matcher matcher = VALID_NAME.matcher(name);
        if (!matcher.matches()) {
            final String msg = String.format("parameter '%s' is invalid. must match pattern %s", name, VALID_NAME.pattern());
            log.error(msg);
            throw new IllegalArgumentException(msg);
        }
        if (parameters.containsKey(name)) {
            final String msg = String.format("ConfigParser already includes mapping for parameter '%s'", name);
            log.error(msg);
            throw new IllegalStateException(msg);
        }
        parameters.put(name, value);

    }

    public Optional<String> get(final String name) {
        return Optional.ofNullable(parameters.get(name));
    }

}

@@ -255,16 +255,87 @@
 ttern;%0A%0A
+/**%0A * Bookkeeping of parameters to inject into xml configuration.%0A */%0A
 @Log4j%0A@
@@ -407,16 +407,52 @@
 erMap %7B%0A
+    /**%0A     * Backing map.%0A     */%0A
     priv
@@ -511,16 +511,84 @@
 ap%3C%3E();%0A
+    /**%0A     * Pattern for valid parameter names (ns:name).%0A     */%0A
     priv
@@ -685,24 +685,327 @@
 -9-_%5D*$%22);%0A%0A
+    /**%0A     * Put a new key=value pair into the parameter map.%0A     * @param name name of parameter%0A     * @param value value of parameter%0A     * @throws IllegalArgumentException if name of the parameter is invalid%0A     * @throws IllegalStateException if the parameter has already been defined%0A     */%0A
     public v
@@ -1057,37 +1057,40 @@
 ) throws Illegal
-State
+Argument
 Exception, Illeg
@@ -1087,32 +1087,29 @@
 ion, Illegal
-Argument
+State
 Exception %7B%0A
@@ -1706,16 +1706,179 @@
 %0A    %7D%0A%0A
+    /**%0A     * Get the value of a parameter, if exists.%0A     * @param name name of the parameter to look up%0A     * @return value of a parameter, if exists%0A     */%0A
     publ

add javadoc for ParameterMap