com.googlecode.flyway.core.util
Class StringUtils

java.lang.Object
  extended by com.googlecode.flyway.core.util.StringUtils

public class StringUtils
extends java.lang.Object

Various string-related utilities.


Method Summary
static java.lang.String collapseWhitespace(java.lang.String str)
          Replaces all sequences of whitespace by a single blank.
static boolean isNumeric(java.lang.String str)
          Checks if the String contains only unicode digits.
static java.lang.String trimOrPad(java.lang.String str, int length)
          Trims or pads (with spaces) this string, so it has this exact length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

trimOrPad

public static java.lang.String trimOrPad(java.lang.String str,
                                         int length)
Trims or pads (with spaces) this string, so it has this exact length.

Parameters:
str - The string to adjust. null is treated as an empty string.
length - The exact length to reach.
Returns:
The adjusted string.

isNumeric

public static boolean isNumeric(java.lang.String str)

Checks if the String contains only unicode digits. A decimal point is not a unicode digit and returns false.

null will return false. An empty String ("") will return true.

 StringUtils.isNumeric(null)   = false
 StringUtils.isNumeric("")     = true
 StringUtils.isNumeric("  ")   = false
 StringUtils.isNumeric("123")  = true
 StringUtils.isNumeric("12 3") = false
 StringUtils.isNumeric("ab2c") = false
 StringUtils.isNumeric("12-3") = false
 StringUtils.isNumeric("12.3") = false
 

Parameters:
str - the String to check, may be null
Returns:
true if only contains digits, and is non-null

collapseWhitespace

public static java.lang.String collapseWhitespace(java.lang.String str)
Replaces all sequences of whitespace by a single blank. Ex.: " " -> " "

Parameters:
str - The string to analyse.
Returns:
The input string, with all whitespace collapsed.


Copyright © 2010. All Rights Reserved.