Brooklyn

brooklyn.util.text
[Java] Class Strings

java.lang.Object
  brooklyn.util.text.Strings

public class Strings

Field Summary
static java.lang.String VALID_NON_ALPHANUM_FILE_CHARS

 
Method Summary
static java.lang.String[] combineArrays(java.lang.String[]... arrays)

static java.lang.String getLastWord(java.lang.String s)

static boolean isEmpty(java.lang.CharSequence s)

Checks if the given string is null or is an empty string.

static boolean isLowerCase(java.lang.String s)

static java.lang.String join(java.lang.Iterable list, java.lang.String seperator)

given a list containing e.g.

static java.lang.String join(java.lang.Object[] list, java.lang.String seperator)

given an array containing e.g.

static java.lang.String[] makeArray(java.lang.String prefix, int count)

returns e.g. { "prefix01", ..., "prefix96" }; see more functional NumericRangeGlobExpander for "prefix{01-96}"

static java.lang.String makePaddedString(java.lang.String base, int len, java.lang.String left_pad, java.lang.String right_pad)

pads the string with "pad" at the left up to len; no padding if base longer than len

static java.lang.String makeRandomId(int l)

provided for convenience, see Identifiers#makeRandomId(int)#makeRandomId(int)

static java.lang.String makeRealString(double x, int maxlen, int prec, int leftPadLen)

creates a string from a real number, with specified accuracy (more iff it comes for free, ie integer-part); switches to E notation if needed to fit within maxlen; can be padded left up too (not useful)

static java.lang.String makeRealString(double x, int maxlen, int prec, int leftPadLen, double skipDecimalThreshhold, boolean useEForSmallNumbers)

creates a string from a real number, with specified accuracy (more iff it comes for free, ie integer-part); switches to E notation if needed to fit within maxlen; can be padded left up too (not useful)

static java.lang.String makeRealStringNearZero(double x, int maxlen, int prec, int leftPadLen)

creates a string from a real number, with specified accuracy (more iff it comes for free, ie integer-part); switches to E notation if needed to fit within maxlen; can be padded left up too (not useful)

static java.lang.String makeRepeated(char c, int length)

static java.lang.String makeTimeString(long utcMillis)

static java.lang.String makeValidFilename(java.lang.String s)

returns a valid filename based on 's'; throws exception if no valid filename can be formed; valid filename looks to start with first alphanum char, then include all alphanum char plus those in VALID_NON_ALPHANUM_FILE_CHARS

static java.lang.String makeValidJavaName(java.lang.String s)

returns a valid java type name based on the given string; removes certain chars (like apostrophe), replaces 1+ non-java chars by _, and prepends _ if the first char is only valid as an identifier part (not start); if all chars are invalid, returns "__hash"+s.hashCode()

static java.lang.String makeValidUniqueJavaName(java.lang.String s)

returns a valid java type name based on the given string, translated as per makeValidJavaName, but with hashcode appended where necessary to guarantee uniqueness (for all but simple strings)

static java.lang.String makeZeroPaddedString(int i, int len)

pads the string with 0's at the left up to len; no padding if i longer than len

static java.lang.String maxlen(java.lang.String s, int maxlen)

returns up to maxlen characters from the start of s

static java.lang.String removeAllFromEnd(java.lang.String string, java.lang.String... suffixes)

as removeFromEnd, but repeats until all such suffixes are gone

static java.lang.String removeAllFromStart(java.lang.String string, java.lang.String... prefixes)

as removeFromStart, but repeats until all such suffixes are gone

static java.lang.String removeFromEnd(java.lang.String string, java.lang.String... suffixes)

removes the first suffix in the list which is present at the end of string and returns that string; ignores subsequent suffixes if a matching one is found; returns the original string if no suffixes are at the end

static java.lang.String removeFromStart(java.lang.String string, java.lang.String... prefixes)

removes the first prefix in the list which is present at the start of string and returns that string; ignores subsequent prefixes if a matching one is found; returns the original string if no prefixes match

static java.lang.String replaceAll(java.lang.String source, java.util.Map replacements)

replaces all key->value entries from the replacement map in source (non-regex)

static java.lang.String replaceAll(java.lang.String source, java.lang.String pattern, java.lang.String replacement)

NON-REGEX replaceAll - replaces all instances in source, of the given pattern, with the given replacement (not interpreting any arguments as regular expressions)

static java.lang.String replaceAllNonRegex(java.lang.String source, java.lang.String pattern, java.lang.String replacement)

NON-REGEX replacement -- explicit method name for reabaility, doing same as Strings.replaceAll

static java.lang.String replaceAllRegex(java.lang.String source, java.lang.String pattern, java.lang.String replacement)

REGEX replacement -- explicit method name for reabaility, doing same as String.replaceAll

static java.lang.String reverse(java.lang.String name)

static java.lang.String toInitialCapOnly(java.lang.String value)

static void trimAll(java.lang.String[] s)

static java.lang.String trimEnd(java.lang.String s)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

VALID_NON_ALPHANUM_FILE_CHARS

public static final java.lang.String VALID_NON_ALPHANUM_FILE_CHARS


 
Method Detail

combineArrays

public static java.lang.String[] combineArrays(java.lang.String[]... arrays)


getLastWord

public static java.lang.String getLastWord(java.lang.String s)


isEmpty

public static boolean isEmpty(java.lang.CharSequence s)
Checks if the given string is null or is an empty string. Useful for pre-String.isEmpty. And useful for StringBuilder etc.
Parameters:
s - the String to check
Returns:
true if empty or null, false otherwise.


isLowerCase

public static boolean isLowerCase(java.lang.String s)


join

public static java.lang.String join(java.lang.Iterable list, java.lang.String seperator)
given a list containing e.g. "a", "b", with separator "," produces "a,b"


join

public static java.lang.String join(java.lang.Object[] list, java.lang.String seperator)
given an array containing e.g. "a", "b", with separator "," produces "a,b"


makeArray

public static java.lang.String[] makeArray(java.lang.String prefix, int count)
returns e.g. { "prefix01", ..., "prefix96" }; see more functional NumericRangeGlobExpander for "prefix{01-96}"


makePaddedString

public static java.lang.String makePaddedString(java.lang.String base, int len, java.lang.String left_pad, java.lang.String right_pad)
pads the string with "pad" at the left up to len; no padding if base longer than len


makeRandomId

public static java.lang.String makeRandomId(int l)
provided for convenience, see Identifiers#makeRandomId(int)#makeRandomId(int)


makeRealString

public static java.lang.String makeRealString(double x, int maxlen, int prec, int leftPadLen)
creates a string from a real number, with specified accuracy (more iff it comes for free, ie integer-part); switches to E notation if needed to fit within maxlen; can be padded left up too (not useful)
Parameters:
x - number to use
maxlen - maximum length for the numeric string, if possible (-1 to suppress)
prec - number of digits accuracy desired (more kept for integers)
leftPadLen - will add spaces at left if necessary to make string this long (-1 to suppress) [probably not usef]
Returns:
such a string


makeRealString

public static java.lang.String makeRealString(double x, int maxlen, int prec, int leftPadLen, double skipDecimalThreshhold, boolean useEForSmallNumbers)
creates a string from a real number, with specified accuracy (more iff it comes for free, ie integer-part); switches to E notation if needed to fit within maxlen; can be padded left up too (not useful)
Parameters:
x - number to use
maxlen - maximum length for the numeric string, if possible (-1 to suppress)
prec - number of digits accuracy desired (more kept for integers)
leftPadLen - will add spaces at left if necessary to make string this long (-1 to suppress) [probably not usef]
skipDecimalThreshhold - if positive it will not add a decimal part if the fractional part is less than this threshhold (but for a value 3.00001 it would show zeroes, e.g. with 3 precision and positive threshhold <= 0.00001 it would show 3.00); if zero or negative then decimal digits are always shown
useEForSmallNumbers - whether to use E notation for numbers near zero
Returns:
such a string


makeRealStringNearZero

public static java.lang.String makeRealStringNearZero(double x, int maxlen, int prec, int leftPadLen)
creates a string from a real number, with specified accuracy (more iff it comes for free, ie integer-part); switches to E notation if needed to fit within maxlen; can be padded left up too (not useful)
Parameters:
x - number to use
maxlen - maximum length for the numeric string, if possible (-1 to suppress)
prec - number of digits accuracy desired (more kept for integers)
leftPadLen - will add spaces at left if necessary to make string this long (-1 to suppress) [probably not usef]
Returns:
such a string


makeRepeated

public static java.lang.String makeRepeated(char c, int length)


makeTimeString

public static java.lang.String makeTimeString(long utcMillis)


makeValidFilename

public static java.lang.String makeValidFilename(java.lang.String s)
returns a valid filename based on 's'; throws exception if no valid filename can be formed; valid filename looks to start with first alphanum char, then include all alphanum char plus those in VALID_NON_ALPHANUM_FILE_CHARS


makeValidJavaName

public static java.lang.String makeValidJavaName(java.lang.String s)
returns a valid java type name based on the given string; removes certain chars (like apostrophe), replaces 1+ non-java chars by _, and prepends _ if the first char is only valid as an identifier part (not start); if all chars are invalid, returns "__hash"+s.hashCode()

means result is usually unique to s, though this isn't guaranteed


makeValidUniqueJavaName

public static java.lang.String makeValidUniqueJavaName(java.lang.String s)
returns a valid java type name based on the given string, translated as per makeValidJavaName, but with hashcode appended where necessary to guarantee uniqueness (for all but simple strings)


makeZeroPaddedString

public static java.lang.String makeZeroPaddedString(int i, int len)
pads the string with 0's at the left up to len; no padding if i longer than len


maxlen

public static java.lang.String maxlen(java.lang.String s, int maxlen)
returns up to maxlen characters from the start of s


removeAllFromEnd

public static java.lang.String removeAllFromEnd(java.lang.String string, java.lang.String... suffixes)
as removeFromEnd, but repeats until all such suffixes are gone


removeAllFromStart

public static java.lang.String removeAllFromStart(java.lang.String string, java.lang.String... prefixes)
as removeFromStart, but repeats until all such suffixes are gone


removeFromEnd

public static java.lang.String removeFromEnd(java.lang.String string, java.lang.String... suffixes)
removes the first suffix in the list which is present at the end of string and returns that string; ignores subsequent suffixes if a matching one is found; returns the original string if no suffixes are at the end


removeFromStart

public static java.lang.String removeFromStart(java.lang.String string, java.lang.String... prefixes)
removes the first prefix in the list which is present at the start of string and returns that string; ignores subsequent prefixes if a matching one is found; returns the original string if no prefixes match


replaceAll

@SuppressWarnings("rawtypes")
public static java.lang.String replaceAll(java.lang.String source, java.util.Map replacements)
replaces all key->value entries from the replacement map in source (non-regex)


replaceAll

public static java.lang.String replaceAll(java.lang.String source, java.lang.String pattern, java.lang.String replacement)
NON-REGEX replaceAll - replaces all instances in source, of the given pattern, with the given replacement (not interpreting any arguments as regular expressions)


replaceAllNonRegex

public static java.lang.String replaceAllNonRegex(java.lang.String source, java.lang.String pattern, java.lang.String replacement)
NON-REGEX replacement -- explicit method name for reabaility, doing same as Strings.replaceAll


replaceAllRegex

public static java.lang.String replaceAllRegex(java.lang.String source, java.lang.String pattern, java.lang.String replacement)
REGEX replacement -- explicit method name for reabaility, doing same as String.replaceAll


reverse

public static java.lang.String reverse(java.lang.String name)


toInitialCapOnly

public static java.lang.String toInitialCapOnly(java.lang.String value)


trimAll

public static void trimAll(java.lang.String[] s)


trimEnd

public static java.lang.String trimEnd(java.lang.String s)


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.