com.ebasetech.ufs.utility
Class StringUtil

java.lang.Object
  extended bycom.ebasetech.ufs.utility.StringUtil

public class StringUtil
extends java.lang.Object

Handy string utility functions.


Field Summary
private static java.lang.String[] booleanStrings
           
private static char[] illegalChars
           
static java.lang.String lineSeparator
           
 
Constructor Summary
StringUtil()
           
 
Method Summary
static boolean areStringsEqual(java.lang.String one, java.lang.String two)
           
static boolean areStringsEqual(java.lang.String one, java.lang.String two, boolean ignoreCase)
           
static boolean beginsWith(java.lang.String str, java.lang.String prefix)
           
static int compareStrings(java.lang.String one, java.lang.String two, boolean ignoreCase)
           
static java.lang.String fromInputStream(java.io.InputStream in)
           
static int indexOfIgnoreCase(java.lang.String str, java.lang.String toFind)
           
static int indexOfIgnoreCase(java.lang.String str, java.lang.String toFind, int fromIndex)
          same as indexOf, but ignores case.
static boolean isObjectAString(java.lang.Object object, boolean allowNull, boolean allowZeroLength)
           
static boolean isStringABoolean(java.lang.String value)
           
static boolean isStringADouble(java.lang.String value)
           
static boolean isStringAnInteger(java.lang.String value)
          Check that value is a simple integer.
static boolean isStringNullOrEmpty(java.lang.String string)
           
static java.lang.String makeFirstLetterUpperCase(java.lang.String txt)
           
static java.lang.String makeNewString(char ch, int length)
          make a new string of length, all chars set to ch
static java.lang.String makeUniqueName(java.util.Collection existingNames, java.lang.String newName)
          makes a unique name, avoiding a collection of existing names.
static java.lang.String makeUniqueName(java.lang.String name, java.lang.String[] others, boolean ignoreCase)
          makes a unique name, avoid others in String array.
static int occurrence(java.lang.String str, java.lang.String toFind, int occurrence)
          like indexOf, but find the nth occurrence of a string
static java.lang.String padOutLeft(java.lang.String src, char padding, int length)
           
static java.lang.String padOutRight(java.lang.String src, char padding, int length)
          add padding to end of src until it is specified length
static java.lang.String removeIllegalCharacters(java.lang.String text)
           
static java.lang.String replace(java.lang.String aInput, java.lang.String aOldPattern, java.lang.String aNewPattern, int maxReplace)
          A bit like String.replaceAll.
static java.lang.String replaceAll(java.lang.String aInput, java.lang.String aOldPattern, java.lang.String aNewPattern)
          like replace, but does them all.
static java.lang.String replaceInside(java.lang.String string, char oldChar, char newChar, char startChar, char endChar)
          an unusual method.
static java.lang.String substituteVariables(java.lang.String aInput, java.lang.String substitutionString, java.lang.Object[] args)
          !!!KEEP IN SYNC WITH JAVASCRIPT FUNCTION standard argument substitution function for ebase.
static java.lang.String trimCharRight(java.lang.String value, char toRemove)
          Remove all toRemove characters from the right.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lineSeparator

public static final java.lang.String lineSeparator

illegalChars

private static final char[] illegalChars

booleanStrings

private static java.lang.String[] booleanStrings
Constructor Detail

StringUtil

public StringUtil()
Method Detail

isObjectAString

public static boolean isObjectAString(java.lang.Object object,
                                      boolean allowNull,
                                      boolean allowZeroLength)
Parameters:
object -
Returns:
true if the object is a string with length greater than 0

isStringNullOrEmpty

public static boolean isStringNullOrEmpty(java.lang.String string)
Returns:
true is string is either null or ""

areStringsEqual

public static boolean areStringsEqual(java.lang.String one,
                                      java.lang.String two)
Returns:
true if the strings have same value.

areStringsEqual

public static boolean areStringsEqual(java.lang.String one,
                                      java.lang.String two,
                                      boolean ignoreCase)
Parameters:
ignoreCase - ignore case in the equals!
Returns:
true if the strings have same value.

compareStrings

public static int compareStrings(java.lang.String one,
                                 java.lang.String two,
                                 boolean ignoreCase)

isStringAnInteger

public static boolean isStringAnInteger(java.lang.String value)
Check that value is a simple integer. i.e. all digit chars except an optional leading '-' n.b. Strings like 1e23 will return false.


isStringADouble

public static boolean isStringADouble(java.lang.String value)

isStringABoolean

public static boolean isStringABoolean(java.lang.String value)

trimCharRight

public static java.lang.String trimCharRight(java.lang.String value,
                                             char toRemove)
Remove all toRemove characters from the right.

Parameters:
value - the value to trim
toRemove - the char to remove
Returns:
a new string, with all toRemove removed from the right.

substituteVariables

public static java.lang.String substituteVariables(java.lang.String aInput,
                                                   java.lang.String substitutionString,
                                                   java.lang.Object[] args)
!!!KEEP IN SYNC WITH JAVASCRIPT FUNCTION standard argument substitution function for ebase. 1. numbered variables are replaced with corresponding argument. e.g. &&1 &&2 (and all instances of them) 2. unnumbered variables (e.g. &&) are replaced one at a time with the next arg. i.e. the first '&&' will get arg[0] the next will get arg[1].


replaceAll

public static java.lang.String replaceAll(java.lang.String aInput,
                                          java.lang.String aOldPattern,
                                          java.lang.String aNewPattern)
like replace, but does them all. (maxReplace =-1)

Parameters:
aInput -
aOldPattern -
aNewPattern -
Returns:

replace

public static java.lang.String replace(java.lang.String aInput,
                                       java.lang.String aOldPattern,
                                       java.lang.String aNewPattern,
                                       int maxReplace)
A bit like String.replaceAll. but doesn't use regEx, so you don't have to be careful about escaping regex chars

Parameters:
aInput - what to look in
aOldPattern - to look for
aNewPattern - what to replace with.
maxReplace - the maximum number of replaces to be done, or -1 to do them all
Returns:
will return aInput if aOldPattern is not found, otherwise a new string with replaced patterns

replaceInside

public static java.lang.String replaceInside(java.lang.String string,
                                             char oldChar,
                                             char newChar,
                                             char startChar,
                                             char endChar)
an unusual method. It replaces instances of a char with a new char. But only inside bits of the string within delimiters (startChar and endChar)


indexOfIgnoreCase

public static int indexOfIgnoreCase(java.lang.String str,
                                    java.lang.String toFind,
                                    int fromIndex)
same as indexOf, but ignores case. This sledgehammer solution could be optimised by working in similar way to String.indexOf()

Parameters:
str - the string to look in.
toFind - the string to find
Returns:
same as indexOf

indexOfIgnoreCase

public static int indexOfIgnoreCase(java.lang.String str,
                                    java.lang.String toFind)

occurrence

public static int occurrence(java.lang.String str,
                             java.lang.String toFind,
                             int occurrence)
like indexOf, but find the nth occurrence of a string

Parameters:
str -
toFind -
occurrence -
Returns:

beginsWith

public static boolean beginsWith(java.lang.String str,
                                 java.lang.String prefix)
Returns:
true if str begins with prefix

makeFirstLetterUpperCase

public static java.lang.String makeFirstLetterUpperCase(java.lang.String txt)

fromInputStream

public static java.lang.String fromInputStream(java.io.InputStream in)
                                        throws java.io.IOException
Throws:
java.io.IOException

removeIllegalCharacters

public static java.lang.String removeIllegalCharacters(java.lang.String text)

makeUniqueName

public static java.lang.String makeUniqueName(java.util.Collection existingNames,
                                              java.lang.String newName)
makes a unique name, avoiding a collection of existing names. If newName does not exist in existingNames then newName will be returned. Otherwise '.n' (where n is an incrementing number) will appended to the end of newName, until it is found to be unique.

Parameters:
existingNames - names to avoid
newName - the new name to base the new name on.
Returns:
a unique name.

makeUniqueName

public static java.lang.String makeUniqueName(java.lang.String name,
                                              java.lang.String[] others,
                                              boolean ignoreCase)
makes a unique name, avoid others in String array. appending brackets to try new names

Parameters:
name -
others -
ignoreCase -
Returns:

padOutRight

public static java.lang.String padOutRight(java.lang.String src,
                                           char padding,
                                           int length)
add padding to end of src until it is specified length


padOutLeft

public static java.lang.String padOutLeft(java.lang.String src,
                                          char padding,
                                          int length)

makeNewString

public static java.lang.String makeNewString(char ch,
                                             int length)
make a new string of length, all chars set to ch