|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
org.jcoderz.commons.util.StringUtil
public final class StringUtil
This class provides string related utility functions.
Field Summary | |
---|---|
static |
EMPTY_STRING
The empty string "" . |
Method Summary | |
---|---|
static |
asciiToString(byte[] bytes)
Converts a byte array to a String using ASCII encoding. |
static |
asciiToString(byte[] bytes,
int offset,
int length)
Converts a byte array to a String using ASCII encoding. |
static boolean |
contains( str,
subString)
Returns true if the first argument string contains the second argument string, and otherwise returns false. |
static boolean |
equals( a,
b)
Returns true if the two specified strings are equal to one another. |
static |
fitToLength( s,
int minLength,
int maxLength)
Pads or truncates the given argument to be at least minLength chars and at most maxLength chars long. |
static boolean |
isAscii(char c)
Tests if the given character is an ASCII character, i.e. if it's integer value is less than or equal to 127. |
static boolean |
isAscii( c)
Determines if the specified string consists only of ASCII characters. |
static boolean |
isBlankOrNull( s)
Returns true if given string is null , the
length is zero (empty string) or if it only contains white spaces. |
static boolean |
isEmptyOrNull( s)
Returns true if given string is null or the
length is zero (empty string). |
static boolean |
isNullOrBlank( s)
Returns true if given string is null , the
length is zero (empty string) or if it only contains white spaces. |
static boolean |
isNullOrEmpty( s)
Returns true if given string is null or the
length is zero (empty string). |
static |
padLeft( s,
char pad,
int size)
Adds the character pad to the left-side of the string s until the string size will be size. |
static byte[] |
toBytes( s)
Converts a String to an byte array using UTF-8 encoding. |
static |
toString(byte[] bytes)
Converts a byte array to a String using UTF-8 encoding. |
static |
toString(byte[] bytes,
int offset,
int length)
Converts a byte array to a String using UTF-8 encoding. |
static |
trimLength( str,
int maxLength)
Trims the length of the given string to the given maxlength, if the string length is below the given maxlength the string returned unmodified. |
Methods inherited from class java.lang. |
---|
, , , , , , , , , , |
Field Detail |
---|
public static final EMPTY_STRING
""
.
Method Detail |
---|
public static toString(byte[] bytes)
null
, the returned string
is also null
.
bytes
- The byte array to be converted.
null
if the given byte array is null
.public static toString(byte[] bytes, int offset, int length) throws
null
, the returned string
is also null
.
bytes
- The byte array to be converted.offset
- The index of the first byte to encode.length
- The number of bytes to encode.
null
if the given byte array is null
.
- if the UTF-8 encoding is not supported by the
JDK.public static byte[] toBytes( s) throws
s
- The string to be converted.
- if the UTF-8 encoding is not supported by the
JDK.public static asciiToString(byte[] bytes, int offset, int length)
null
, the returned string
is also null
.
bytes
- The byte array to be converted.offset
- The index of the first byte to encode.length
- The number of bytes to encode.
public static asciiToString(byte[] bytes)
null
, the returned string
is also null
.
bytes
- The byte array to be converted.
public static boolean isAscii(char c)
c
- the character to test.
true
if c <= 127, false
otherwise.public static boolean isAscii( c)
c
- the characters to check.
true
if the specified characters are 7-bit
ASCII clean; false
otherwise.public static boolean isNullOrEmpty( s)
true
if given string is null
or the
length is zero (empty string).
s
- the string to test.
true
if given string is null
or the length is zero (empty string); false
otherwise.public static boolean isEmptyOrNull( s)
true
if given string is null
or the
length is zero (empty string).
s
- the string to test.
true
if given string is null
or the length is zero (empty string); false
otherwise.public static boolean isNullOrBlank( s)
true
if given string is null
, the
length is zero (empty string) or if it only contains white spaces.
The whitespace check is done using Character.isWhitespace().
s
- the string to test.
true
if given string is null
,
the length is zero (empty string) or the String contains only
whitespace characters; false
otherwise.public static boolean isBlankOrNull( s)
true
if given string is null
, the
length is zero (empty string) or if it only contains white spaces.
The whitespace check is done using Character.isWhitespace().
s
- the string to test.
true
if given string is null
,
the length is zero (empty string) or the String contains only
whitespace characters; false
otherwise.public static boolean equals( a, b)
a
- one string to be tested for equality.b
- the other string to be tested for equality.
public static fitToLength( s, int minLength, int maxLength) throws ArgumentMalformedException
s
- the string to pad or truncateminLength
- the minimum length of the stringmaxLength
- the maximum length of the string
ArgumentMalformedException
- if the string argument is null,
or if minLength is greater than maxLengthpublic static padLeft( s, char pad, int size)
s
- the string to pad.pad
- the padding character.size
- the final string size.
public static trimLength( str, int maxLength)
str
- the string to trim.maxLength
- the maximum length
public static boolean contains( str, subString)
str
- the string to test.subString
- the substring to look for in str
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |