Skip to content

Commit

Permalink
[pinpoint-apm#2815] add hasText()
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Aug 7, 2017
1 parent 494c626 commit 6d7af76
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ public static boolean hasLength(final String string) {
return string != null && string.length() > 0;
}

public static boolean hasText(String string) {
if (isEmpty(string)) {
return false;
}

final int length = string.length();
for (int i = 0; i < length; i++) {
if (!Character.isWhitespace(string.charAt(i))) {
return true;
}
}
return false;
}

public static <T> int getLength(final String string) {
return getLength(string, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ public void testTokenizeToStringList_compatibility() throws Exception {

}

@Test
public void testTokenizeToStringList_nullValue() throws Exception {

List<String> tokenList = StringUtils.tokenizeToStringList(null, ",");
Assert.assertEquals(tokenList.size(), 0);

}


private static List<String> backup_splitAndTrim(String value, String separator) {
if (StringUtils.isEmpty(value)) {
Expand Down Expand Up @@ -211,4 +219,28 @@ public void testGetLength_defaultNull() {
Assert.assertEquals(StringUtils.getLength("abc"), 3);
}


@Test
public void testHasLength() {

Assert.assertTrue(StringUtils.hasLength("1"));
Assert.assertTrue(StringUtils.hasLength(" "));


Assert.assertFalse(StringUtils.hasLength(null));
Assert.assertFalse(StringUtils.hasLength(""));
}

@Test
public void testHasText() {

Assert.assertTrue(StringUtils.hasText("1"));
Assert.assertTrue(StringUtils.hasText(" 1"));

Assert.assertFalse(StringUtils.hasText(null));
Assert.assertFalse(StringUtils.hasText(""));
Assert.assertFalse(StringUtils.hasText(" "));

}

}

0 comments on commit 6d7af76

Please sign in to comment.