Package org.atlanmod.commons.primitive
Class Strings
- java.lang.Object
-
- org.atlanmod.commons.primitive.Strings
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringemptyToNull(String s)Returns the given string if it is nonempty;nullotherwise.static booleanisBinary(String value)Returnstrueif thevaluerepresents an hexadecimal value.static booleanisNullOrEmpty(String s)Returnstrueif the given string is null or is the empty string.static StringnullToEmpty(String s)Returns the given string if it is non-null; the empty string otherwise.static byte[]toBytes(String value)Encodes aStringto abytearray.static byte[]toBytesBinary(String value)Encodes aStringto abytearray, where eachbyteis represented as a two-digit unsigned hexadecimal number in lower case.
-
-
-
Field Detail
-
EMPTY
@Nonnull public static final String EMPTY
The empty string"".- See Also:
- Constant Field Values
-
SPACE
@Nonnull public static final String SPACE
A string for a space character.- See Also:
- Constant Field Values
-
LR
@Nonnull public static final String LR
A string for a line separator character, dependencing on the system.- See Also:
System.lineSeparator()
-
-
Method Detail
-
isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String s)Returnstrueif the given string is null or is the empty string.- Parameters:
s- a string reference to check- Returns:
trueif the string isnullor is the empty string
-
nullToEmpty
@Nonnull public static String nullToEmpty(@Nullable String s)
Returns the given string if it is non-null; the empty string otherwise.- Parameters:
s- the string to test and possibly return- Returns:
sitself if it is non-null;EMPTYif it isnull
-
emptyToNull
@CheckForNull public static String emptyToNull(@Nullable String s)
Returns the given string if it is nonempty;nullotherwise.- Parameters:
s- the string to test and possibly return- Returns:
sitself if it is nonempty;nullif it is empty ornull
-
toBytes
@Nonnull public static byte[] toBytes(String value)
Encodes aStringto abytearray.- Parameters:
value- the value to encode- Returns:
- a
bytearray - Throws:
NullPointerException- if thevalueisnullIllegalArgumentException- ifStandardCharsets.UTF_8is not a supported encoding
-
toBytesBinary
@Nonnull public static byte[] toBytesBinary(String value)
Encodes aStringto abytearray, where eachbyteis represented as a two-digit unsigned hexadecimal number in lower case.- Parameters:
value- the value to encode- Returns:
- a
bytearray - Throws:
NullPointerException- if thevalueisnullIllegalArgumentException- if thelengthof thevalueis not even.- See Also:
Bytes.toStringBinary(byte[])
-
isBinary
public static boolean isBinary(String value)
Returnstrueif thevaluerepresents an hexadecimal value.- Parameters:
value- the string to test- Returns:
trueif thevaluerepresents an hexadecimal value
-
-