public class StringUtils
extends java.lang.Object
Title: Framework Support Library
Description: Contains utilities for various processing of string-like entities.
Copyright: Copyright (c) 2009
Company: StreamScape Technologies
Modifier and Type | Field and Description |
---|---|
static java.util.List |
EMPTY_TOKENS |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
containsChars(java.lang.String str,
char[] characters,
boolean withSpaces)
Checks if the specified string contains any character in the specified set of characters.
|
static boolean |
containsChars(java.lang.String str,
java.lang.String characters,
boolean withSpaces)
Checks if the specified string contains any character in the specified set of characters.
|
static java.lang.String |
deNormalizeObjectName(java.lang.String objectName) |
static boolean |
endsWithAny(java.lang.String string,
java.lang.String[] searchStrings)
Checks if a CharSequence ends with any of an array of specified strings.
|
static boolean |
equalsNullSafe(java.lang.String str1,
java.lang.String str2) |
static boolean |
equalsNullTrimSafe(java.lang.String str1,
java.lang.String str2) |
static java.lang.String |
escapeDsObjectName(java.lang.String name) |
static byte[] |
getEmptyUTF() |
static java.lang.String |
hashEventId(java.lang.String eventId)
Generates a hash value for the
Event Id . |
static long |
hostToLong(java.lang.String host)
Converts host:port string to a long containing ip and port.
|
static boolean |
isAllLowerCase(java.lang.String str) |
static boolean |
isAllUpperCase(java.lang.String str) |
static boolean |
isAlpha(java.lang.String str) |
static boolean |
isAlphanumeric(java.lang.String str) |
static boolean |
isEmpty(java.lang.String str) |
static boolean |
isNumeric(java.lang.String str) |
static int |
lastIndexOfAny(java.lang.CharSequence str,
java.lang.CharSequence[] searchStrings)
Find the latest index of any of a set of potential substrings.
|
static int |
lengthUTF(java.lang.String str)
Returns length of the UTF encoding of the string
|
static java.lang.String |
normalizeObjectName(java.lang.String objectName) |
static java.lang.String |
normalizeSpace(java.lang.String str) |
static java.lang.String |
normalizeString(java.lang.String str)
Attempt to normalize the variable name to avoid special characters.
|
static java.lang.String |
prependSeparatorIfNotEmpty(java.lang.String s) |
static java.lang.String |
prependSeparatorIfNotEmptyAndRelative(java.lang.String s) |
static java.lang.String |
removeEnd(java.lang.String str,
java.lang.String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
|
static java.util.List |
split(java.lang.String str,
char delimiter)
Splits the specified string into tokens in accordance with the specified delimiter.
|
static java.util.List |
split(java.lang.String str,
char delimiter1,
char delimiter2)
Splits the specified string into tokens in accordance with the specified delimiters.
|
static void |
split(java.lang.String str,
char delimiter1,
char delimiter2,
java.util.List result)
Splits the specified string into tokens in accordance with the specified delimiters.
|
static void |
split(java.lang.String str,
char delimiter,
java.util.List result)
Splits the specified string into tokens in accordance with the specified delimiter.
|
static java.util.List |
split(java.lang.String str,
java.lang.String delimiter)
Splits the specified string into tokens in accordance with the specified delimiter.
|
static void |
split(java.lang.String str,
java.lang.String delimiter,
java.util.List result)
Splits the specified string into tokens in accordance with the specified delimiter.
|
static java.util.List |
splitWithoutEmptyTokens(java.lang.String str,
char delimiter)
Splits the specified string into tokens in accordance with the specified delimiter and excludes empty tokens from result.
|
static void |
splitWithoutEmptyTokens(java.lang.String str,
char delimiter,
java.util.List result)
Splits the specified string into tokens in accordance with the specified delimiter and excludes empty tokens from result.
|
static java.util.List |
splitWithTrim(java.lang.String str,
char delimiter)
Splits the specified string into tokens in accordance with the specified delimiter and trims each token of the result.
|
static java.util.List |
splitWithTrim(java.lang.String str,
char delimiter1,
char delimiter2)
Splits the specified string into tokens in accordance with the specified delimiters and trims each token of the result.
|
static void |
splitWithTrim(java.lang.String str,
char delimiter1,
char delimiter2,
java.util.List result)
Splits the specified string into tokens in accordance with the specified delimiters and trims each token of the result.
|
static void |
splitWithTrim(java.lang.String str,
char delimiter,
java.util.List result)
Splits the specified string into tokens in accordance with the specified delimiter and trims each token of the result.
|
static byte[] |
stringToUTF(java.lang.String str)
Sonverts string to UTF byte array
|
static java.lang.String |
toCamelCase(java.lang.String name,
boolean lcFirst,
char[] delimiters) |
static java.lang.String |
toCapitalized(java.lang.String str) |
static java.lang.String |
trimLeadingSlashes(java.lang.String s) |
static java.lang.String |
trimLeadingSlashes(java.lang.String s,
char slash) |
static java.lang.String |
trimSlashes(java.lang.String s) |
static java.lang.String |
trimTrailingSlashes(java.lang.String s) |
static java.lang.String |
trimTrailingSlashes(java.lang.String s,
char slash,
boolean keepFirst) |
static java.lang.String |
unwrapEventId(java.lang.String eventId) |
static java.lang.String |
UTFToString(byte[] utf,
int off)
converts UTF byte array to String
|
static boolean |
validateConsumerName(java.lang.String consumerName)
Validates the string that represents the consumer name.
|
static boolean |
validateEventFilter(java.lang.String eventFilter)
Validates the string that represents the event filter that can contain metacharacters.
|
static boolean |
validateEventId(java.lang.String eventId)
Validates the string that represents the event identifier.
|
static boolean |
validateObjectName(java.lang.String name) |
static boolean |
validateSemanticName(java.lang.String name) |
static boolean |
validateString(java.lang.String str) |
static java.lang.String |
wrapEventId(java.lang.String eventId) |
public static boolean containsChars(java.lang.String str, char[] characters, boolean withSpaces)
str
- the string to be checked.characters
- the characters to search for.withSpaces
- the flag specifying if the string can contain space characters.true
if the string contains any specified character, false
otherwise.public static boolean containsChars(java.lang.String str, java.lang.String characters, boolean withSpaces)
str
- the string to be checked.characters
- the characters to search for.withSpaces
- the flag specifying if the string can contain space characters.true
if the string contains any specified character, false
otherwise.public static boolean validateConsumerName(java.lang.String consumerName)
consumerName
- the consumer name to be validated.true
if the specified name has valid format or false otherwise.
public static java.lang.String hashEventId(java.lang.String eventId) throws UtilitiesException
Event Id
. This method verifies the
id for correctness and appends a 'c' for negative numbers.eventId
- StringUtilitiesException
public static boolean validateEventId(java.lang.String eventId)
eventId
- the eventId to be validated.true
if the specified id has valid format or false otherwise.
public static boolean validateEventFilter(java.lang.String eventFilter)
eventFilter
- the eventId to be validated.true
if the specified filter has valid format or false otherwise.
public static boolean validateObjectName(java.lang.String name)
public static boolean validateSemanticName(java.lang.String name)
public static boolean validateString(java.lang.String str)
public static java.lang.String normalizeObjectName(java.lang.String objectName)
public static java.lang.String deNormalizeObjectName(java.lang.String objectName)
public static java.lang.String normalizeString(java.lang.String str)
str
- the string to be normalized.public static java.lang.String UTFToString(byte[] utf, int off) throws UtilitiesException
utf
- byte[]off
- intjava.io.UTFDataFormatException
UtilitiesException
public static byte[] stringToUTF(java.lang.String str) throws UtilitiesException
str
- StringUtilitiesException
public static byte[] getEmptyUTF()
public static int lengthUTF(java.lang.String str)
str
- Stringpublic static long hostToLong(java.lang.String host) throws java.net.UnknownHostException
host
- Stringjava.net.UnknownHostException
public static java.util.List split(java.lang.String str, char delimiter)
str
- the string to be split.delimiter
- the specified delimiter.public static void split(java.lang.String str, char delimiter, java.util.List result)
str
- the string to be split.delimiter
- the specified delimiter.result
- the list of tokens.public static java.util.List split(java.lang.String str, java.lang.String delimiter)
str
- the string to be split.delimiter
- the specified delimiter.public static void split(java.lang.String str, java.lang.String delimiter, java.util.List result)
str
- the string to be split.delimiter
- the specified delimiter.result
- the list of tokens.public static java.util.List splitWithTrim(java.lang.String str, char delimiter)
str
- the string to be split.delimiter
- the specified delimiter.public static void splitWithTrim(java.lang.String str, char delimiter, java.util.List result)
str
- the string to be split.delimiter
- the specified delimiter.result
- the list of tokens.public static java.util.List split(java.lang.String str, char delimiter1, char delimiter2)
str
- the string to be split.delimiter1
- the first specified delimiter.delimiter2
- the second specified delimiter.public static void split(java.lang.String str, char delimiter1, char delimiter2, java.util.List result)
str
- the string to be split.delimiter1
- the first specified delimiter.delimiter2
- the second specified delimiter.result
- the list of tokens.public static java.util.List splitWithTrim(java.lang.String str, char delimiter1, char delimiter2)
str
- the string to be split.delimiter1
- the first specified delimiter.delimiter2
- the second specified delimiter.public static void splitWithTrim(java.lang.String str, char delimiter1, char delimiter2, java.util.List result)
str
- the string to be split.delimiter1
- the first specified delimiter.delimiter2
- the second specified delimiter.result
- the list of tokens.public static java.util.List splitWithoutEmptyTokens(java.lang.String str, char delimiter)
str
- the string to be split.delimiter
- the specified delimiter.public static void splitWithoutEmptyTokens(java.lang.String str, char delimiter, java.util.List result)
str
- the string to be split.delimiter
- the specified delimiter.result
- the list to which the result tokens will be added.public static java.lang.String trimLeadingSlashes(java.lang.String s, char slash)
public static java.lang.String trimLeadingSlashes(java.lang.String s)
public static java.lang.String trimTrailingSlashes(java.lang.String s, char slash, boolean keepFirst)
public static java.lang.String trimTrailingSlashes(java.lang.String s)
public static java.lang.String trimSlashes(java.lang.String s)
public static boolean equalsNullSafe(java.lang.String str1, java.lang.String str2)
public static boolean equalsNullTrimSafe(java.lang.String str1, java.lang.String str2)
public static java.lang.String toCapitalized(java.lang.String str)
public static java.lang.String prependSeparatorIfNotEmpty(java.lang.String s)
public static java.lang.String prependSeparatorIfNotEmptyAndRelative(java.lang.String s)
public static java.lang.String wrapEventId(java.lang.String eventId)
public static java.lang.String unwrapEventId(java.lang.String eventId)
public static java.lang.String escapeDsObjectName(java.lang.String name)
public static boolean isEmpty(java.lang.String str)
public static boolean isAlpha(java.lang.String str)
public static boolean isNumeric(java.lang.String str)
public static boolean isAlphanumeric(java.lang.String str)
public static boolean isAllUpperCase(java.lang.String str)
public static boolean isAllLowerCase(java.lang.String str)
public static java.lang.String toCamelCase(java.lang.String name, boolean lcFirst, char[] delimiters)
public static java.lang.String normalizeSpace(java.lang.String str)
public static java.lang.String removeEnd(java.lang.String str, java.lang.String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
StringUtils.removeEnd(null, *) = null StringUtils.removeEnd("", *) = "" StringUtils.removeEnd(*, null) = * StringUtils.removeEnd("*", "") = "*" StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com" StringUtils.removeEnd("www.domain.com", ".com") = "www.domain" StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
str
- the source String to search, may be null
.remove
- the String to search for and remove, may be null
.public static int lastIndexOfAny(java.lang.CharSequence str, java.lang.CharSequence[] searchStrings)
Find the latest index of any of a set of potential substrings.
A null
CharSequence will return -1
.
A null
search array will return -1
.
A null
or zero length search array entry will be ignored,
but a search array containing "" will return the length of str
if str
is not null. This method uses String.indexOf(String)
if possible
StringUtils.lastIndexOfAny(null, *) = -1 StringUtils.lastIndexOfAny(*, null) = -1 StringUtils.lastIndexOfAny(*, []) = -1 StringUtils.lastIndexOfAny(*, [null]) = -1 StringUtils.lastIndexOfAny("zzabyycdxx", ["ab","cd"]) = 6 StringUtils.lastIndexOfAny("zzabyycdxx", ["cd","ab"]) = 6 StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1 StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1 StringUtils.lastIndexOfAny("zzabyycdxx", ["mn",""]) = 10
str
- the CharSequence to check, may be null
.searchStrings
- the CharSequences to search for, may be null
.public static boolean endsWithAny(java.lang.String string, java.lang.String[] searchStrings)
Checks if a CharSequence ends with any of an array of specified strings.
StringUtils.endsWithAny(null, null) = false StringUtils.endsWithAny(null, new String[] {"abc"}) = false StringUtils.endsWithAny("abcxyz", null) = false StringUtils.endsWithAny("abcxyz", new String[] {""}) = true StringUtils.endsWithAny("abcxyz", new String[] {"xyz"}) = true StringUtils.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true
string
- the CharSequence to check, may be null
.searchStrings
- the CharSequences to find, may be null
or empty.true
if the CharSequence ends with any of the prefixes, case-insensitive, or both null
.Copyright © 2015-2024 StreamScape Technologies. All rights reserved.