@SuppressWarnings("unchecked")
  public static <E extends Enum<E>> EnumSet<E> parseEnumSet(final String key,
      final String valueString,
      final Class<E> enumClass,
      final boolean ignoreUnknown) throws IllegalArgumentException {

    // build a map of lower case string to enum values.
    final Map<String, E> mapping = mapEnumNamesToValues("", enumClass);

    // scan the input string and add all which match
    final EnumSet<E> enumSet = noneOf(enumClass);
    for (String element : getTrimmedStringCollection(valueString)) {
      final String item = element.toLowerCase(Locale.ROOT);
      if ("*".equals(item)) {
        enumSet.addAll(mapping.values());
        continue;
      }
      final E e = mapping.get(item);
      if (e != null) {
        enumSet.add(e);
      } else {
        // no match
        // unless configured to ignore unknown values, raise an exception
        checkArgument(ignoreUnknown, "%s: Unknown option value: %s in list %s."
                + " Valid options for enum class %s are: %s",
            key, element, valueString,
            enumClass.getName(),
            mapping.keySet().stream().collect(Collectors.joining(",")));
      }
    }
    return enumSet;
  }
@Test
  public void testCaseConflictingEnumNotSupported() throws Throwable {
    intercept(IllegalArgumentException.class,
        ERROR_MULTIPLE_ELEMENTS_MATCHING_TO_LOWER_CASE_VALUE,
        () ->
            parseEnumSet("key", "c, unrecognized",
                CaseConflictingEnum.class, false));
  }