@SuppressWarnings("unchecked") // We check this ourselves with instanceof and getDeclaringClass()
    private static <T extends Enum<T>> Map<String, T> mapOf(String key, T value,
            Object... additional) throws IllegalArgumentException {

        // Verify length of additional pairs is even
        if (additional.length % 2 != 0)
            throw new IllegalArgumentException("Array of additional key/value pairs must be even in length.");

        // Add first type-checked pair
        Map<String, T> valueMapping = new HashMap<>(1 + additional.length);
        valueMapping.put(key, value);

        Class<T> enumClass = value.getDeclaringClass();

        // Add remaining, unchecked pairs
        for (int i = 0; i < additional.length; i += 2) {

            // Verify that unchecked keys are indeed Strings
            Object additionalKey = additional[i];
            if (!(additionalKey instanceof String))
                throw new IllegalArgumentException("Keys of additional key/value pairs must be strings.");

            // Verify that unchecked values are indeed constants defined by the
            // expected enum
            Object additionalValue = additional[i + 1];
            if (!(additionalValue instanceof Enum) || enumClass != ((Enum) additionalValue).getDeclaringClass())
                throw new IllegalArgumentException("Values of additional key/value pairs must be enum constants of the correct type.");

            valueMapping.put((String) additionalKey, (T) additionalValue);

        }

        return valueMapping;

    }
Produces a new Map having the given key/value pairs. Each key MUST be a
String, and each value MUST be an enum constant belonging to the given
enum.

@param <T>
    The enum whose constants may be used as values within the Map.

@param key
    The key of the first key/value pair to include within the Map.

@param value
    The value of the first key/value pair to include within the Map.

@param additional
    Any additional key/value pairs to be included beyond the first. This
    array must be even in length, where each even element is a String
    key and each odd element is the enum constant value to be associated
    with the key immediately preceding it.

@return
    A new Map having each of the given key/value pairs.

@throws IllegalArgumentException
    If any provided key is not a String, if any provided value is not
    an enum constant from the given enum type, or if the length of
    {@code additional} is not even.
guacamole-ext/src/main/java/org/apache/guacamole/properties/EnumGuacamoleProperty.java