站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss 4.0.1 sp1 common API Documentation 英文版文档

Strings (JBoss/Common API) - JBoss 4.0.1 sp1 common API Documentation 英文版文档


org.jboss.util
Class Strings

java.lang.Object
  extended byorg.jboss.util.Strings

public final class Strings
extends Object

A collection of String utilities.

Version:
$Revision: 1.12 $
Author:
Jason Dillon, Scott Stark, Claudio Vesco, Dimitris Andreadis

Nested Class Summary
static class Strings.Range
          Represents a range between two integers.
 
Field Summary
static String EMPTY
          An empty string constant
 
Constructor Summary
Strings()
           
 
Method Summary
static String capitalize(String string)
          Capitalize the first character of the given string.
static boolean compare(String me, String you)
          Compare two strings.
static int count(String string, char c)
          Count the number of instances of character within a string.
static int count(String string, String substring)
          Count the number of instances of substring within a string.
static boolean isEjbQlIdentifier(String s)
          Check whether the given String is an identifier according to the EJB-QL definition.
static boolean isEmpty(String string)
          Check if the given string is empty.
static boolean isJavaKeyword(String s)
          Check whether the given String is a reserved Java Keyword according to the Java Language Specifications.
static boolean isValidJavaIdentifier(String s)
          Check whether the given String is a valid identifier according to the Java Language specifications.
static String join(byte[] array)
          Convert and join an array of bytes into one string.
static String join(Object[] array)
          Convert and join an array of objects into one string.
static String join(Object[] array, String delim)
          Join an array of strings into one delimited string.
static String join(Object[] array, String prefix, String separator, String suffix)
          Return a string composed of the given array.
static String join(StringBuffer buff, Object[] array, String delim)
          Join an array of strings into one delimited string.
static String join(StringBuffer buff, Object[] array, String prefix, String separator, String suffix)
          Return a string composed of the given array.
static int nthIndexOf(String string, String token, int index)
          Return the nth index of the given token occurring in the given string.
static String pad(Object obj, int count)
          Return a string padded with the given string value of an object for the given count.
static String pad(StringBuffer buff, String string, int count)
          Return a string padded with the given string for the given count.
static String pad(String string, int count)
          Return a string padded with the given string for the given count.
static Strings.Range rangeOf(String beginToken, String endToken, String string)
          Return the range from a begining token to an ending token.
static Strings.Range rangeOf(String beginToken, String endToken, String string, int fromIndex)
          Return the range from a begining token to an ending token.
static String removeWhiteSpace(String s)
          Returns a new string with all the whitespace removed
static String[] split(String string, String delim)
          Split up a string into multiple strings based on a delimiter.
static String[] split(String string, String delim, int limit)
          Split up a string into multiple strings based on a delimiter.
static String subst(StringBuffer buff, String string, Map map, String beginToken, String endToken)
          Substitute sub-strings in side of a string.
static String subst(StringBuffer buff, String string, String[] replace, char token)
          Substitute index identifiers with the replacement value from the given array for the corresponding index.
static String subst(StringBuffer buff, String from, String to, String string)
          Substitute sub-strings in side of a string.
static String subst(String string, Map map, String beginToken, String endToken)
          Substitute sub-strings in side of a string.
static String subst(String string, String[] replace)
          Substitute index identifiers (with % for the index token) with the replacement value from the given array for the corresponding index.
static String subst(String string, String[] replace, char token)
          Substitute index identifiers with the replacement value from the given array for the corresponding index.
static String subst(String from, String to, String string)
          Substitute sub-strings in side of a string.
static URL toURL(String urlspec)
          Make a URL from the given string.
static URL toURL(String urlspec, String relativePrefix)
          Make a URL from the given string.
static String[] trim(String[] strings)
          Trim each string in the given string array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY

public static final String EMPTY
An empty string constant

See Also:
Constant Field Values
Constructor Detail

Strings

public Strings()
Method Detail

subst

public static String subst(StringBuffer buff,
                           String from,
                           String to,
                           String string)
Substitute sub-strings in side of a string.

Parameters:
buff - Stirng buffer to use for substitution (buffer is not reset)
from - String to substitute from
to - String to substitute to
string - String to look for from in
Returns:
Substituted string

subst

public static String subst(String from,
                           String to,
                           String string)
Substitute sub-strings in side of a string.

Parameters:
from - String to substitute from
to - String to substitute to
string - String to look for from in
Returns:
Substituted string

subst

public static String subst(StringBuffer buff,
                           String string,
                           Map map,
                           String beginToken,
                           String endToken)
Substitute sub-strings in side of a string.

Parameters:
buff - String buffer to use for substitution (buffer is not reset)
string - String to subst mappings in
map - Map of from->to strings
beginToken - Beginning token
endToken - Ending token
Returns:
Substituted string

subst

public static String subst(String string,
                           Map map,
                           String beginToken,
                           String endToken)
Substitute sub-strings in side of a string.

Parameters:
string - String to subst mappings in
map - Map of from->to strings
beginToken - Beginning token
endToken - Ending token
Returns:
Substituted string

subst

public static String subst(StringBuffer buff,
                           String string,
                           String[] replace,
                           char token)
Substitute index identifiers with the replacement value from the given array for the corresponding index.

Parameters:
buff - The string buffer used for the substitution (buffer is not reset).
string - String substitution format.
replace - Array of strings whose values will be used as replacements in the given string when a token with their index is found.
token - The character token to specify the start of an index reference.
Returns:
Substituted string.

subst

public static String subst(String string,
                           String[] replace,
                           char token)
Substitute index identifiers with the replacement value from the given array for the corresponding index.

Parameters:
string - String substitution format.
replace - Array of strings whose values will be used as replacements in the given string when a token with their index is found.
token - The character token to specify the start of an index reference.
Returns:
Substituted string.

subst

public static String subst(String string,
                           String[] replace)
Substitute index identifiers (with % for the index token) with the replacement value from the given array for the corresponding index.

Parameters:
string - String substitution format.
replace - Array of strings whose values will be used as replacements in the given string when a token with their index is found.
Returns:
Substituted string.

rangeOf

public static Strings.Range rangeOf(String beginToken,
                                    String endToken,
                                    String string,
                                    int fromIndex)
Return the range from a begining token to an ending token.

Parameters:
beginToken - String to indicate begining of range.
endToken - String to indicate ending of range.
string - String to look for range in.
fromIndex - Beginning index.
Returns:
(begin index, end index) or null.

rangeOf

public static Strings.Range rangeOf(String beginToken,
                                    String endToken,
                                    String string)
Return the range from a begining token to an ending token.

Parameters:
beginToken - String to indicate begining of range.
endToken - String to indicate ending of range.
string - String to look for range in.
Returns:
(begin index, end index) or null.

split

public static String[] split(String string,
                             String delim,
                             int limit)
Split up a string into multiple strings based on a delimiter.

Parameters:
string - String to split up.
delim - Delimiter.
limit - Limit the number of strings to split into (-1 for no limit).
Returns:
Array of strings.

split

public static String[] split(String string,
                             String delim)
Split up a string into multiple strings based on a delimiter.

Parameters:
string - String to split up.
delim - Delimiter.
Returns:
Array of strings.

join

public static String join(StringBuffer buff,
                          Object[] array,
                          String delim)
Join an array of strings into one delimited string.

Parameters:
buff - String buffered used for join (buffer is not reset).
array - Array of objects to join as strings.
delim - Delimiter to join strings with or null.
Returns:
Joined string.

join

public static String join(Object[] array,
                          String delim)
Join an array of strings into one delimited string.

Parameters:
array - Array of objects to join as strings.
delim - Delimiter to join strings with or null.
Returns:
Joined string.

join

public static String join(Object[] array)
Convert and join an array of objects into one string.

Parameters:
array - Array of objects to join as strings.
Returns:
Converted and joined objects.

join

public static String join(byte[] array)
Convert and join an array of bytes into one string.

Parameters:
array - Array of objects to join as strings.
Returns:
Converted and joined objects.

join

public static String join(StringBuffer buff,
                          Object[] array,
                          String prefix,
                          String separator,
                          String suffix)
Return a string composed of the given array.

Parameters:
buff - Buffer used to construct string value (not reset).
array - Array of objects.
prefix - String prefix.
separator - Element sepearator.
suffix - String suffix.
Returns:
String in the format of: prefix + n ( + separator + n+i)* + suffix.

join

public static String join(Object[] array,
                          String prefix,
                          String separator,
                          String suffix)
Return a string composed of the given array.

Parameters:
array - Array of objects.
prefix - String prefix.
separator - Element sepearator.
suffix - String suffix.
Returns:
String in the format of: prefix + n ( + separator + n+i)* + suffix.

count

public static int count(String string,
                        String substring)
Count the number of instances of substring within a string.

Parameters:
string - String to look for substring in.
substring - Sub-string to look for.
Returns:
Count of substrings in string.

count

public static int count(String string,
                        char c)
Count the number of instances of character within a string.

Parameters:
string - String to look for substring in.
c - Character to look for.
Returns:
Count of substrings in string.

pad

public static String pad(StringBuffer buff,
                         String string,
                         int count)
Return a string padded with the given string for the given count.

Parameters:
buff - String buffer used for padding (buffer is not reset).
string - Pad element.
count - Pad count.
Returns:
Padded string.

pad

public static String pad(String string,
                         int count)
Return a string padded with the given string for the given count.

Parameters:
string - Pad element.
count - Pad count.
Returns:
Padded string.

pad

public static String pad(Object obj,
                         int count)
Return a string padded with the given string value of an object for the given count.

Parameters:
obj - Object to convert to a string.
count - Pad count.
Returns:
Padded string.

compare

public static boolean compare(String me,
                              String you)

Compare two strings.

Both or one of them may be null.

Returns:
true if object equals or intern ==, else false.

isEmpty

public static boolean isEmpty(String string)
Check if the given string is empty.

Parameters:
string - String to check
Returns:
True if string is empty

nthIndexOf

public static int nthIndexOf(String string,
                             String token,
                             int index)
Return the nth index of the given token occurring in the given string.

Parameters:
string - String to search.
token - Token to match.
index - Nth index.
Returns:
Index of nth item or -1.

capitalize

public static String capitalize(String string)
Capitalize the first character of the given string.

Parameters:
string - String to capitalize.
Returns:
Capitalized string.
Throws:
IllegalArgumentException - String is null or empty.

trim

public static String[] trim(String[] strings)
Trim each string in the given string array.

This modifies the string array.

Parameters:
strings - String array to trim.
Returns:
String array with each element trimmed.

toURL

public static URL toURL(String urlspec,
                        String relativePrefix)
                 throws MalformedURLException
Make a URL from the given string.

If the string is a properly formatted file URL, then the file portion will be made canonical.

If the string is an invalid URL then it will be converted into a file URL.

Parameters:
urlspec - The string to construct a URL for.
relativePrefix - The string to prepend to relative file paths, or null to disable prepending.
Returns:
A URL for the given string.
Throws:
MalformedURLException - Could not make a URL for the given string.

toURL

public static URL toURL(String urlspec)
                 throws MalformedURLException
Make a URL from the given string.

Parameters:
urlspec - The string to construct a URL for.
Returns:
A URL for the given string.
Throws:
MalformedURLException - Could not make a URL for the given string.
See Also:
toURL(String,String)

isJavaKeyword

public static final boolean isJavaKeyword(String s)
Check whether the given String is a reserved Java Keyword according to the Java Language Specifications.

Parameters:
s - String to check
Returns:
true if the given String is a reserved Java keyword, false otherwise.

isEjbQlIdentifier

public static final boolean isEjbQlIdentifier(String s)
Check whether the given String is an identifier according to the EJB-QL definition. See The EJB 2.0 Documentation Section 11.2.6.1.

Parameters:
s - String to check
Returns:
true if the given String is a reserved identifier in EJB-QL, false otherwise.

isValidJavaIdentifier

public static final boolean isValidJavaIdentifier(String s)
Check whether the given String is a valid identifier according to the Java Language specifications. See The Java Language Specification Second Edition, Section 3.8 for the definition of what is a valid identifier.

Parameters:
s - String to check
Returns:
true if the given String is a valid Java identifier, false otherwise.

removeWhiteSpace

public static String removeWhiteSpace(String s)
Returns a new string with all the whitespace removed

Parameters:
s - the source string
Returns:
the string without whitespace or null


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.