Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility to compare enums to Strings #815

Closed
sleberknight opened this issue Dec 1, 2022 · 0 comments · Fixed by #816
Closed

Add utility to compare enums to Strings #815

sleberknight opened this issue Dec 1, 2022 · 0 comments · Fixed by #816
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented Dec 1, 2022

The basic Java Enum class does not have methods to compare against CharSequence, e.g. that come from user input in a web form or similar. For example, I'd like to be able to do this:

// userSuppliedColor is a String
if (Color.RED.equalsString(userSuppliedColor)) {
    ...
}

or this:

if (Color.RED.equalsStringIgnoringCase(userSuppliedColor)) {
    ...
}

Alas, Java doesn't provide such methods, and amazingly I cannot find anything that does this in Google Guava or Apache Commons. It seems like this is something relatively common to want to do. Anyway, I guess we'll add our own which will at a minimum allow:

  • comparisons of a single enum constant to a CharSequence in either case-sensitive or case-insensitive manner
  • comparison of a CharSequence against multiple enum constants in case-sensitive or case-insensitive manner
@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Dec 1, 2022
@sleberknight sleberknight added this to the 2.4.0 milestone Dec 1, 2022
@sleberknight sleberknight self-assigned this Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant