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 new KiwiJdbc utility to return optionally stripped string, or null if blank #1049

Closed
sleberknight opened this issue Oct 5, 2023 · 1 comment · Fixed by #1059
Closed
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 Oct 5, 2023

Add a new method in KiwiJdbc to return null if a string obtained from calling ResultSet#getString is blank (i.e. null, empty string, or whitespace-only). If the string is not blank, then use an enum argument to decide whether to strip any leading or trailing whitespace from the original string.

Signature:

@Nullable
String stringOrNullIfBlank(ResultSet rs, String columnName, TrimStrategy strategy)

New enum class to describe whitespace handling

Create a simple enum that describes whether or not to strip leading and trailing whitespace.

enum TrimStrategy {
     PRESERVE, REMOVE
}

I am not wed to TrimStrategy as the name. Since I could not think of a decent name, I asked ChatGPT and here is what it came up with:

A good name for a Java enum that describes whether a String should have leading and trailing whitespace removed or not could be something clear and self-explanatory. Here are a few suggestions:

  1. WhitespaceHandling - This enum could have values like TRIM, KEEP, or NONE to indicate different handling options.

  2. StringTrimOption - This enum could include options like TRIM, NO_TRIM, or KEEP_WHITESPACE.

  3. WhitespacePolicy - This enum could represent policies for handling whitespace, with values like REMOVE, PRESERVE, or IGNORE.

  4. TrimmingStrategy - This enum might include strategies like TRIM_WHITESPACE, PRESERVE_WHITESPACE, or LEAVE_WHITESPACE.

  5. WhitespaceMode - This enum could define modes like TRIM_LEADING_AND_TRAILING, PRESERVE_LEADING_AND_TRAILING, or NO_WHITESPACE_HANDLING.

Choose a name that fits well with your project's coding style and makes the purpose of the enum clear to developers who will use it in their code. The key is to keep it descriptive and easy to understand.

Pretty good names!

This method can delegate to the new methods created in #1047 or #1048.

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Oct 5, 2023
@sleberknight sleberknight added this to the 3.1.0 milestone Oct 5, 2023
@sleberknight sleberknight self-assigned this Oct 5, 2023
@sleberknight
Copy link
Member Author

I think I prefer StringTrimOption or just TrimOption to TrimStrategy. This makes it consistent with the BooleanConversionOption enum created by #1053 (and #1055)

@sleberknight sleberknight changed the title Add new KiwiJdbc utility to return optionally stripped string, or null instead of blank Add new KiwiJdbc utility to return optionally stripped string, or null if of blank Oct 8, 2023
@sleberknight sleberknight changed the title Add new KiwiJdbc utility to return optionally stripped string, or null if of blank Add new KiwiJdbc utility to return optionally stripped string, or null if blank Oct 8, 2023
sleberknight added a commit that referenced this issue Oct 8, 2023
Add stringOrNullIfBlank method to KiwiJdbc. If the value returned
from the database is null or blank (whitespace only), this method
returns null. If the value from the database is not blank, the
string is returned after applying a StringTrimOption to it. This
option can either preserve leading and trailing whitespace, or
remove it. All intermediate whitespace (i.e. between words) is
preserved.

Also added BlankStringSource, which is copied from kiwi-test in
order to avoid a circular dependency between kiwi and kiwi-test.

Closes #1049
sleberknight added a commit that referenced this issue Oct 8, 2023
Add stringOrNullIfBlank method to KiwiJdbc. If the value returned
from the database is null or blank (whitespace only), this method
returns null. If the value from the database is not blank, the
string is returned after applying a StringTrimOption to it. This
option can either preserve leading and trailing whitespace, or
remove it. All intermediate whitespace (i.e. between words) is
preserved.

Also added BlankStringSource, which is copied from kiwi-test in
order to avoid a circular dependency between kiwi and kiwi-test.

Closes #1049
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