org.datanucleus.util
Class StringUtils

java.lang.Object
  extended by org.datanucleus.util.StringUtils

public class StringUtils
extends java.lang.Object

Utilities for String manipulation.


Constructor Summary
StringUtils()
           
 
Method Summary
static boolean areStringsEqual(java.lang.String str1, java.lang.String str2)
          Utility to tell if two strings are the same.
static java.lang.String booleanArrayToString(boolean[] ba)
          Utility to convert a boolean[] to a String.
static java.lang.String collectionToString(java.util.Collection coll)
          Converts the given collection of objects to string as a comma-separated list.
static java.lang.String exponentialFormatBigDecimal(java.math.BigDecimal bd)
          Formats the given BigDecimal value into a floating-point literal (like we find in SQL).
static java.lang.String getDecodedStringFromURLString(java.lang.String urlString)
          Convenience method to decode a URL string for use (so spaces are allowed)
static java.lang.String getEncodedURLStringFromString(java.lang.String string)
          Convenience method to encode a URL string for use (so spaces are allowed)
static java.io.File getFileForFilename(java.lang.String filename)
          Convenience method to get a File for the specified filename.
static int getIntValueForProperty(java.util.Properties props, java.lang.String propName, int defaultValue)
          Convenience method to extract an integer property value from a Properties file.
static java.util.jar.JarFile getJarFileForFilename(java.lang.String filename)
          Convenience method to get a JarFile for the specified filename.
static java.lang.String getStringFromStackTrace(java.lang.Throwable ex)
          Convert an exception to a String with full stack trace
static java.lang.String intArrayToString(int[] ia)
          Utility to convert an int[] to a String.
static boolean isEmpty(java.lang.String s)
          check string is null or length is 0.
static boolean isWhitespace(java.lang.String str)
          Utility to check if a string is whitespace.
static java.lang.String leftAlignedPaddedString(java.lang.String input, int length)
          Utility to return a left-aligned version of a string padded to the number of characters specified.
static java.lang.String mapToString(java.util.Map map)
          Converts the given map of objects to string as a comma-separated list.
static boolean notEmpty(java.lang.String s)
          check string isnot null and length > 0.
static java.lang.String objectArrayToString(java.lang.Object[] arr)
          Utility to convert an Object[] to a String.
static java.lang.String removeSpecialTagsFromString(java.lang.String str)
          Method to return the input string with all special tags (end-of-line, tab, etc) replaced by spaces.
static java.lang.String replaceAll(java.lang.String theString, java.lang.String toReplace, java.lang.String replacement)
          Replaces each substring of this string that matches toReplace.
static java.lang.String rightAlignedPaddedString(java.lang.String input, int length)
          Utility to return a right-aligned version of a string padded to the number of characters specified.
static java.lang.String[] split(java.lang.String valuesString, java.lang.String token)
          Splits a list of values separated by a token
static java.lang.String toJVMIDString(java.lang.Object obj)
          Utility to convert an object to a JVM type string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
Method Detail

getStringFromStackTrace

public static java.lang.String getStringFromStackTrace(java.lang.Throwable ex)
Convert an exception to a String with full stack trace

Parameters:
ex - the exception
Returns:
a String with the full stacktrace error text

getFileForFilename

public static java.io.File getFileForFilename(java.lang.String filename)
Convenience method to get a File for the specified filename. Caters for URL-encoded characters in the filename (treatment of spaces on Windows etc)

Parameters:
filename - Name of file
Returns:
The File

getJarFileForFilename

public static java.util.jar.JarFile getJarFileForFilename(java.lang.String filename)
                                                   throws java.io.IOException
Convenience method to get a JarFile for the specified filename. Caters for URL-encoded characters in the filename (treatment of spaces on Windows etc)

Parameters:
filename - Name of file
Returns:
The JarFile
Throws:
java.io.IOException

getDecodedStringFromURLString

public static java.lang.String getDecodedStringFromURLString(java.lang.String urlString)
Convenience method to decode a URL string for use (so spaces are allowed)

Parameters:
urlString - The URL string
Returns:
The string

getEncodedURLStringFromString

public static java.lang.String getEncodedURLStringFromString(java.lang.String string)
Convenience method to encode a URL string for use (so spaces are allowed)

Parameters:
string - The string
Returns:
The encoded string

replaceAll

public static java.lang.String replaceAll(java.lang.String theString,
                                          java.lang.String toReplace,
                                          java.lang.String replacement)
Replaces each substring of this string that matches toReplace. Used to replace replaceAll when using J2SDK 1.3.1. This method is available at String.replace in J2SDK 1.4. TODO Remove this when enhancer moves to 2.0

Parameters:
theString - The string to use
toReplace - The string to replace.
replacement - The replacement string.
Returns:
The updated string after replacing.

isWhitespace

public static boolean isWhitespace(java.lang.String str)
Utility to check if a string is whitespace. If the string is null, returns true also.

Parameters:
str - The string to check
Returns:
Whether the string is just whitespace

areStringsEqual

public static boolean areStringsEqual(java.lang.String str1,
                                      java.lang.String str2)
Utility to tell if two strings are the same. Extends the basic String 'equals' method by allowing for nulls.

Parameters:
str1 - The first string
str2 - The second string
Returns:
Whether the strings are equal.

leftAlignedPaddedString

public static java.lang.String leftAlignedPaddedString(java.lang.String input,
                                                       int length)
Utility to return a left-aligned version of a string padded to the number of characters specified.

Parameters:
input - The input string
length - The length desired
Returns:
The updated string

rightAlignedPaddedString

public static java.lang.String rightAlignedPaddedString(java.lang.String input,
                                                        int length)
Utility to return a right-aligned version of a string padded to the number of characters specified.

Parameters:
input - The input string
length - The length desired
Returns:
The updated string

split

public static java.lang.String[] split(java.lang.String valuesString,
                                       java.lang.String token)
Splits a list of values separated by a token

Parameters:
valuesString - the text to be splited
token - the token
Returns:
an array with all values

toJVMIDString

public static java.lang.String toJVMIDString(java.lang.Object obj)
Utility to convert an object to a JVM type string. Returns the same as would have been output from Object.toString() if the class hadn't overridden it.

Parameters:
obj - The object
Returns:
The String version

booleanArrayToString

public static java.lang.String booleanArrayToString(boolean[] ba)
Utility to convert a boolean[] to a String.

Parameters:
ba - The boolean[]
Returns:
String version

intArrayToString

public static java.lang.String intArrayToString(int[] ia)
Utility to convert an int[] to a String.

Parameters:
ia - The int[]
Returns:
String version

objectArrayToString

public static java.lang.String objectArrayToString(java.lang.Object[] arr)
Utility to convert an Object[] to a String.

Parameters:
arr - The Object[]
Returns:
String version

collectionToString

public static java.lang.String collectionToString(java.util.Collection coll)
Converts the given collection of objects to string as a comma-separated list. If the list is empty the string "<none>" is returned.

Parameters:
coll - collection of objects to be converted
Returns:
A string containing each object in the given collection, converted toString() and separated by commas.

mapToString

public static java.lang.String mapToString(java.util.Map map)
Converts the given map of objects to string as a comma-separated list. If the map is empty the string "<none>" is returned.

Parameters:
map - Map of to be converted
Returns:
A string containing each object in the given map, converted toString() and separated by commas.

getIntValueForProperty

public static int getIntValueForProperty(java.util.Properties props,
                                         java.lang.String propName,
                                         int defaultValue)
Convenience method to extract an integer property value from a Properties file.

Parameters:
props - The Properties
propName - Name of the property
defaultValue - The default value to use (in case not specified)
Returns:
The value

isEmpty

public static boolean isEmpty(java.lang.String s)
check string is null or length is 0.

Parameters:
s - check string
Returns:
return true if string is null or length is 0. return false other case.

notEmpty

public static boolean notEmpty(java.lang.String s)
check string isnot null and length > 0.

Parameters:
s - check string
Returns:
return true if string isnot null and length greater than 0. return false other case.

exponentialFormatBigDecimal

public static java.lang.String exponentialFormatBigDecimal(java.math.BigDecimal bd)
Formats the given BigDecimal value into a floating-point literal (like we find in SQL). BigDecimal.toString() is not well suited to this purpose because it never uses E-notation, which causes some values with large exponents to be output as long strings with tons of zeroes in them.

Parameters:
bd - The number to format.
Returns:
The formatted String.

removeSpecialTagsFromString

public static java.lang.String removeSpecialTagsFromString(java.lang.String str)
Method to return the input string with all special tags (end-of-line, tab, etc) replaced by spaces.

Parameters:
str - The string
Returns:
The cleaned up string


Copyright © 2011. All Rights Reserved.