Skip to content

Commit

Permalink
Introduce LettuceStrings.isEmpty(String) overload with optimized isEm…
Browse files Browse the repository at this point in the history
…pty checking #1609
  • Loading branch information
mp911de committed Feb 3, 2021
1 parent 41f648a commit fdea21a
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/main/java/io/lettuce/core/internal/LettuceStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,51 @@ private LettuceStrings() {
}

/**
* Checks if a CharSequence is empty ("") or null.
* Checks if a String is empty or null.
*
* @param cs the char sequence
* @return true if empty
* @since 6.0.3
* @see String#isEmpty()
*/
public static boolean isEmpty(final CharSequence cs) {
public static boolean isEmpty(String cs) {
return cs == null || cs.isEmpty();
}

/**
* Checks if a CharSequence has a length of 0 or null.
*
* @param cs the char sequence
* @return true if empty
* @see CharSequence#length()
*/
public static boolean isEmpty(CharSequence cs) {
if (cs instanceof String) {
return isEmpty((String) cs);
}
return cs == null || cs.length() == 0;
}

/**
* Checks if a CharSequence is not empty ("") and not null.
* Checks if a String is not empty and not null.
*
* @param cs the char sequence
* @return true if not empty
* @since 6.0.3
* @see String#isEmpty()
*/
public static boolean isNotEmpty(String cs) {
return !isEmpty(cs);
}

/**
* Checks if a CharSequence has a non-zero length and is not null.
*
* @param cs the char sequence
* @return true if not empty
* @see CharSequence#length()
*/
public static boolean isNotEmpty(final CharSequence cs) {
public static boolean isNotEmpty(CharSequence cs) {
return !isEmpty(cs);
}

Expand Down

0 comments on commit fdea21a

Please sign in to comment.