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

Expanding the Key API by adding methods to check if a string may be parsed into a Key #773

Closed
Steanky opened this issue Jun 2, 2022 · 2 comments · Fixed by #774
Closed

Comments

@Steanky
Copy link

Steanky commented Jun 2, 2022

Basically what the title says.

From what I've seen, the only way to check if a string (or namespace:value combination) is a valid Key is by:

  1. Duplicating the validation logic in KeyImpl
  2. Using exception handling as a control flow mechanism, e.g.
public static boolean isValidKey(String namespace, String value)
    try {
        Key.key(namespace, string);
        return true;
    }
    catch (InvalidKeyException ignored) {
        return false;
    }
}

Both of these options work, but aren't particularly elegant in my opinion. Instead, it would be better if the Key interface included isValidKey-like methods corresponding to the Key#key overloads.

This would be primarily useful for validating user input.

@kezz
Copy link
Member

kezz commented Jun 2, 2022

Sounds great, exposing a regex + method to validate would be very helpful!

1 similar comment
@kezz
Copy link
Member

kezz commented Jun 2, 2022

Sounds great, exposing a regex + method to validate would be very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants