mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
add method emptyToNull
This commit is contained in:
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user