add method emptyToNull

This commit is contained in:
2024-12-13 10:56:58 -06:00
parent 21a5c98376
commit 5070f0a738
2 changed files with 30 additions and 0 deletions

View File

@ -460,4 +460,19 @@ public class StringUtils
return (Pattern.matches("[a-f0-9]{8}(?:-[a-f0-9]{4}){4}[a-f0-9]{8}", s)); return (Pattern.matches("[a-f0-9]{8}(?:-[a-f0-9]{4}){4}[a-f0-9]{8}", s));
} }
/***************************************************************************
**
***************************************************************************/
public static String emptyToNull(String s)
{
if(!hasContent(s))
{
return (null);
}
return (s);
}
} }

View File

@ -318,4 +318,19 @@ class StringUtilsTest extends BaseTest
assertEquals("Apples were eaten", StringUtils.pluralFormat(2, "Apple{,s} {was,were} eaten")); assertEquals("Apples were eaten", StringUtils.pluralFormat(2, "Apple{,s} {was,were} eaten"));
} }
/*******************************************************************************
**
*******************************************************************************/
@Test
void testEmptyToNull()
{
assertNull(StringUtils.emptyToNull(null));
assertNull(StringUtils.emptyToNull(""));
assertNull(StringUtils.emptyToNull(" "));
assertNull(StringUtils.emptyToNull(" "));
assertEquals("a", StringUtils.emptyToNull("a"));
}
} }