Package com.sodius.oslc.core.util
Class Strings
- java.lang.Object
-
- com.sodius.oslc.core.util.Strings
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isEmpty(String string)
Returnstrue
if the given string isnull
or is the empty string.static boolean
nonEmpty(String string)
Returnstrue
if the given string is nornull
nor is the empty string.static String
requireNonEmpty(String string)
Checks that the specified string is notnull
nor the empty string.static String
requireNonEmpty(String string, String message)
Checks that the specified string is notnull
nor the empty string and throws a customizedNullPointerException
if it is.
-
-
-
Method Detail
-
isEmpty
public static boolean isEmpty(String string)
Returnstrue
if the given string isnull
or is the empty string.- Parameters:
string
- a string reference to check- Returns:
true
if the string isnull
or is the empty string
-
nonEmpty
public static boolean nonEmpty(String string)
Returnstrue
if the given string is nornull
nor is the empty string.- Parameters:
string
- a string reference to check- Returns:
true
if the string is notnull
nor is the empty string
-
requireNonEmpty
public static String requireNonEmpty(String string)
Checks that the specified string is notnull
nor the empty string. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:public Foo(String bar) { this.bar = Strings.requireNonEmpty(bar); }
- Parameters:
string
- the string to check for nullity and emptiness- Returns:
string
if notnull
nor empty- Throws:
NullPointerException
- ifstring
isnull
or the empty string
-
requireNonEmpty
public static String requireNonEmpty(String string, String message)
Checks that the specified string is notnull
nor the empty string and throws a customizedNullPointerException
if it is. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:public Foo(String bar) { this.bar = Strings.requireNonEmpty(bar, "bar must not be null nor empty"); }
- Parameters:
string
- the string to check for nullity and emptinessmessage
- detail message to be used in the event that aNullPointerException
is thrown- Returns:
string
if notnull
nor empty- Throws:
NullPointerException
- ifstring
isnull
or the empty string
-
-