Use isEmpty().

This commit is contained in:
Gary Gregory 2021-01-16 22:30:34 -05:00
parent c7c74e936d
commit dddd8c4e26
3 changed files with 18 additions and 5 deletions

View File

@ -6707,7 +6707,7 @@ public class StringUtils {
final Set<String> searchSet = new HashSet<>(Arrays.asList(searchList));
final Set<String> replacementSet = new HashSet<>(Arrays.asList(replacementList));
searchSet.retainAll(replacementSet);
if (searchSet.size() > 0) {
if (!searchSet.isEmpty()) {
throw new IllegalStateException("Aborting to protect against StackOverflowError - " +
"output of one loop is the input of another");
}

View File

@ -282,6 +282,19 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
return size == 0;
}
/**
* Checks is the string builder is not empty (convenience Collections API style method).
* <p>
* This method is the same as checking {@link #length()} and is provided to match the
* API of Collections.
*
* @return {@code true} if the size is greater than {@code 0}.
* @since 3.12
*/
public boolean isNotEmpty() {
return size > 0;
}
/**
* Clears the string builder (convenience Collections API style method).
* <p>
@ -1390,7 +1403,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
* @since 2.3
*/
public StrBuilder appendSeparator(final char separator) {
if (size() > 0) {
if (isNotEmpty()) {
append(separator);
}
return this;
@ -1408,7 +1421,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
* @since 2.5
*/
public StrBuilder appendSeparator(final char standard, final char defaultIfEmpty) {
if (size() > 0) {
if (isNotEmpty()) {
append(standard);
} else {
append(defaultIfEmpty);

View File

@ -127,12 +127,12 @@ public class ThreadUtilsTest {
@Test
public void testAtLeastOneThreadExists() {
assertTrue(ThreadUtils.getAllThreads().size() > 0);
assertFalse(ThreadUtils.getAllThreads().isEmpty());
}
@Test
public void testAtLeastOneThreadGroupsExists() {
assertTrue(ThreadUtils.getAllThreadGroups().size() > 0);
assertFalse(ThreadUtils.getAllThreadGroups().isEmpty());
}
@Test