|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jcoderz.commons.util.StringUtil
public final class StringUtil
This class provides string related utility functions.
| Field Summary | |
|---|---|
static String |
EMPTY_STRING
The empty string "". |
| Method Summary | |
|---|---|
static String |
asciiToString(byte[] bytes)
Converts a byte array to a String using ASCII encoding. |
static String |
asciiToString(byte[] bytes,
int offset,
int length)
Converts a byte array to a String using ASCII encoding. |
static boolean |
contains(String str,
String subString)
Returns true if the first argument string contains the second argument string, and otherwise returns false. |
static boolean |
equals(String a,
String b)
Returns true if the two specified strings are equal to one another. |
static String |
fitToLength(String 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(CharSequence c)
Determines if the specified string consists only of ASCII characters. |
static boolean |
isBlankOrNull(String s)
Returns true if given string is null, the
length is zero (empty string) or if it only contains white spaces. |
static boolean |
isEmptyOrNull(String s)
Returns true if given string is null or the
length is zero (empty string). |
static boolean |
isNullOrBlank(String s)
Returns true if given string is null, the
length is zero (empty string) or if it only contains white spaces. |
static boolean |
isNullOrEmpty(String s)
Returns true if given string is null or the
length is zero (empty string). |
static String |
padLeft(String 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(String s)
Converts a String to an byte array using UTF-8 encoding. |
static String |
toString(byte[] bytes)
Converts a byte array to a String using UTF-8 encoding. |
static String |
toString(byte[] bytes,
int offset,
int length)
Converts a byte array to a String using UTF-8 encoding. |
static String |
trimLength(String 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.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String EMPTY_STRING
"".
| Method Detail |
|---|
public static String 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 String toString(byte[] bytes,
int offset,
int length)
throws RuntimeException
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.
RuntimeException - if the UTF-8 encoding is not supported by the
JDK.
public static byte[] toBytes(String s)
throws RuntimeException
s - The string to be converted.
RuntimeException - if the UTF-8 encoding is not supported by the
JDK.
public static String 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 String 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(CharSequence c)
c - the characters to check.
true if the specified characters are 7-bit
ASCII clean; false otherwise.public static boolean isNullOrEmpty(String 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(String 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(String 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(String 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(String a,
String b)
a - one string to be tested for equality.b - the other string to be tested for equality.
public static String fitToLength(String 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 maxLength
public static String padLeft(String s,
char pad,
int size)
s - the string to pad.pad - the padding character.size - the final string size.
public static String trimLength(String str,
int maxLength)
str - the string to trim.maxLength - the maximum length
public static boolean contains(String str,
String 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 | |||||||||