C0urante commented on a change in pull request #11777: URL: https://github.com/apache/kafka/pull/11777#discussion_r817276211
########## File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java ########## @@ -1415,4 +1415,21 @@ public static boolean isBlank(String str) { return res; } + /** + * Get an array containing all of the {@link Object#toString names} of a given enumerable type. + * @param enumClass the enum class; may not be null + * @return an array with the names of every value for the enum class; never null, but may be empty + * if there are no values defined for the enum + */ + public static String[] enumOptions(Class<? extends Enum<?>> enumClass) { + Objects.requireNonNull(enumClass); + if (!enumClass.isEnum()) { + throw new IllegalArgumentException("Class " + enumClass + " is not an enumerable type"); + } + + return Stream.of(enumClass.getEnumConstants()) + .map(Object::toString) Review comment: I opted for `toString` instead of `name` since the former can be overridden, but the latter can't. The Javadoc does explicitly link to the `toString` method, but that's probably not enough to cancel out the assumption people might make that the text "name" refers to `Enum::name`. I can tweak it to say "string representations", which is a little clunkier but shouldn't mislead people like "name" might. LMK if you have other thoughts. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org