Package com.amazonaws.util
Class StringUtils
- java.lang.Object
-
- com.amazonaws.util.StringUtils
-
public class StringUtils extends Object
Utilities for converting objects to strings.
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMMA_SEPARATOR
static Charset
UTF8
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
appendCompactedString(StringBuilder destination, String source)
This method appends a string to a string builder and collapses contiguous white space is a single space.static boolean
beginsWithIgnoreCase(String data, String seq)
Performs a case insensitive comparison and returns true if the data begins with the given sequence.static int
compare(String str1, String str2)
Compare two strings with Locale.ENGLISH This method is preferred over String.compareTo() method.static String
fromBigDecimal(BigDecimal value)
static String
fromBigInteger(BigInteger value)
static String
fromBoolean(Boolean value)
static String
fromByte(Byte b)
Returns the string representation of the specified Byte.static String
fromByteBuffer(ByteBuffer byteBuffer)
Base64 encodes the data in the specified byte buffer (from the current position to the buffer's limit) and returns it as a base64 encoded string.static String
fromDate(Date value)
Converts the specified date to an ISO 8601 timestamp string and returns it.static String
fromDouble(Double d)
Returns the string representation of the specified double.static String
fromFloat(Float value)
static String
fromInteger(Integer value)
static String
fromLong(Long value)
static String
fromString(String value)
static boolean
isNullOrEmpty(String value)
static String
join(String joiner, String... parts)
Joins the strings in parts with joiner between each stringstatic String
lowerCase(String str)
Converts a given String to lower case with Locale.ENGLISHstatic String
replace(String originalString, String partToMatch, String replacement)
static BigDecimal
toBigDecimal(String s)
static BigInteger
toBigInteger(String s)
static Boolean
toBoolean(StringBuilder value)
static Integer
toInteger(StringBuilder value)
static String
toString(StringBuilder value)
static String
trim(String value)
A null-safe trim method.static String
upperCase(String str)
Converts a given String to upper case with Locale.ENGLISH
-
-
-
Field Detail
-
COMMA_SEPARATOR
public static final String COMMA_SEPARATOR
- See Also:
- Constant Field Values
-
UTF8
public static final Charset UTF8
-
-
Method Detail
-
toInteger
public static Integer toInteger(StringBuilder value)
-
toString
public static String toString(StringBuilder value)
-
toBoolean
public static Boolean toBoolean(StringBuilder value)
-
fromBigInteger
public static String fromBigInteger(BigInteger value)
-
fromBigDecimal
public static String fromBigDecimal(BigDecimal value)
-
toBigInteger
public static BigInteger toBigInteger(String s)
-
toBigDecimal
public static BigDecimal toBigDecimal(String s)
-
fromDate
public static String fromDate(Date value)
Converts the specified date to an ISO 8601 timestamp string and returns it.- Parameters:
value
- The date to format as an ISO 8601 timestamp string.- Returns:
- An ISO 8601 timestamp string created from the specified date.
-
fromDouble
public static String fromDouble(Double d)
Returns the string representation of the specified double.- Parameters:
d
- The double to represent as a string.- Returns:
- The string representation of the specified double.
-
fromByte
public static String fromByte(Byte b)
Returns the string representation of the specified Byte.- Parameters:
b
- The Byte to represent as a string.- Returns:
- The string representation of the specified Byte.
-
fromByteBuffer
public static String fromByteBuffer(ByteBuffer byteBuffer)
Base64 encodes the data in the specified byte buffer (from the current position to the buffer's limit) and returns it as a base64 encoded string.- Parameters:
byteBuffer
- The data to base64 encode and return as a string; must not be null.- Returns:
- The base64 encoded contents of the specified byte buffer.
-
replace
public static String replace(String originalString, String partToMatch, String replacement)
-
join
public static String join(String joiner, String... parts)
Joins the strings in parts with joiner between each string- Parameters:
joiner
- the string to insert between the strings in partsparts
- the parts to join
-
trim
public static String trim(String value)
A null-safe trim method. If the input string is null, returns null; otherwise returns a trimmed version of the input.
-
isNullOrEmpty
public static boolean isNullOrEmpty(String value)
- Returns:
- true if the given value is either null or the empty string
-
lowerCase
public static String lowerCase(String str)
Converts a given String to lower case with Locale.ENGLISH- Parameters:
str
- the string to be converted to lower case- Returns:
- the lower case of string, or itself if string is null/empty
-
upperCase
public static String upperCase(String str)
Converts a given String to upper case with Locale.ENGLISH- Parameters:
str
- the string to be converted to upper case- Returns:
- the upper case of string, or itself if string is null/empty
-
compare
public static int compare(String str1, String str2)
Compare two strings with Locale.ENGLISH This method is preferred over String.compareTo() method.- Parameters:
str1
- String 1str2
- String 2- Returns:
- negative integer if str1 lexicographically precedes str2 positive integer if str1 lexicographically follows str2 0 if both strings are equal
- Throws:
IllegalArgumentException
- throws exception if both or either of the strings is null
-
appendCompactedString
public static void appendCompactedString(StringBuilder destination, String source)
This method appends a string to a string builder and collapses contiguous white space is a single space. This is equivalent to: destination.append(source.replaceAll("\\s+", " ")) but does not create a Pattern object that needs to compile the match string; it also prevents us from having to make a Matcher object as well.
-
-