Top Fields Constructors Methods
org.hibernate.util

public final Class StringHelper

extends Object
Class Inheritance
Imports
java.util.Iterator, .StringTokenizer, .ArrayList, .Arrays, java.util.regex.Pattern, org.hibernate.dialect.Dialect

Field Summary

Modifier and TypeField and Description
private static final int
public static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String[]
add(String[] x, String sep, String[] y)

public static boolean
booleanValue(String tfString)

private static String

Returns:

The cleaned alias, stripped of any leading non-alpha characters.
cleanAlias
(String
The generated alias to be cleaned.
alias
)

Clean the generated alias by removing any non-alpha characters from the beginning.

public static String

Returns:

The collapsed name.
collapse
(String
The name to collapse.
name
)

Collapses a name.

public static String

Returns:

The collapsed form.
collapseQualifier
(String
The qualifier to collapse.
qualifier
,
boolean
Should we include the dots in the collapsed form?
includeDots
)

Given a qualifier, collapse it.

public static String

Returns:

The name itself if it does not begin with the qualifierBase, or the properly collapsed form otherwise.
collapseQualifierBase
(String
The (potentially) qualified name.
name
,
String
The qualifier base.
qualifierBase
)

Cross between collapse and partiallyUnqualify.

public static int
countUnquoted(String string, char character)

public static int
firstIndexOfChar(String sqlString, String string, int startindex)

public static String
generateAlias(String description)

public static String

Returns:

an alias of the form foo1_
generateAlias
(String
The base name (usually an entity-name or collection-role)
description
,
int
A uniquing value
unique
)

Generate a nice alias for the given class name or collection role name and unique integer.

private static String

Returns:

The generated root alias.
generateAliasRoot
(String
The root name from which to generate a root alias.
description
)

Generates a root alias by truncating the "root name" defined by the incoming decription and removing/modifying any non-valid alias characters.

public static char
public static char
public static boolean
isEmpty(String string)

public static boolean
public static boolean

Returns:

True if the given string starts and ends with '`'; false otherwise.
isQuoted
(String
The name to check.
name
)

Determine if the given string is quoted (wrapped by '`' characters at beginning and end).

public static boolean

Returns:

True if quoted, false otherwise
isQuoted
(String
The name to check
name
,
Dialect
The dialect (to determine the "real" quoting chars).
dialect
)

Determine if the given name is quoted.

public static String
join(String seperator, String[] strings)

public static String
join(String seperator, Iterator<E> objects)

public static int
public static int[]
locateUnquoted(String string, char character)

public static String
public static String[]
multiply(String string, Iterator<E> placeholders, Iterator<E> replacements)

private static String[]
multiply(String[] strings, String placeholder, String[] replacements)

public static String

Returns:

The name itself, or the partially unqualified form if it begins with the qualifier base.
partiallyUnqualify
(String
The (potentially) qualified name.
name
,
String
The qualifier base.
qualifierBase
)

Partially unqualifies a qualified name.

public static String
qualifier(String qualifiedName)

public static String
qualify(String prefix, String name)

public static String[]
qualify(String prefix, String[] names)

public static String

Returns:

The quoted version.
quote
(String
The name to quote.
name
)

Return a representation of the given name ensuring quoting (wrapped with '`' characters).

public static String
repeat(String string, int times)

public static String
repeat(char character, int times)

public static String
replace(String template, String placeholder, String replacement)

public static String[]
replace(String[] templates, String placeholder, String replacement)

public static String
replace(String template, String placeholder, String replacement, boolean wholeWords)

public static String
replace(String template, String placeholder, String replacement, boolean wholeWords, boolean encloseInParensIfNecessary)

public static String
replace(String beforePlaceholder, String afterPlaceholder, String placeholder, String replacement, boolean wholeWords, boolean encloseInParensIfNecessary)

public static String
replaceOnce(String template, String placeholder, String replacement)

public static String
root(String qualifiedName)

public static String[]
split(String seperators, String list)

public static String[]
split(String seperators, String list, boolean include)

public static String[]
suffix(String[] columns, String suffix)

private static String
suffix(String name, String suffix)

public static String
public static String
toString(Object[] array)

public static String
public static String
truncate(String string, int length)

public static String
unqualify(String qualifiedName)

public static String
public static String

Returns:

The unquoted version.
unquote
(String
The name to be unquoted.
name
)

Return the unquoted version of name (stripping the start and end '`' characters if present).

public static String

Returns:

The unquoted version.
unquote
(String
The name to be unquoted.
name
,
Dialect
The dialect (to determine the "real" quoting chars).
dialect
)

Return the unquoted version of name stripping the start and end quote characters.

public static String[]

Returns:

The unquoted versions.
unquote
(String[]
The names to be unquoted.
names
,
Dialect
The dialect (to determine the "real" quoting chars).
dialect
)

Return the unquoted version of name stripping the start and end quote characters.

public static String
unroot(String qualifiedName)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALIAS_TRUNCATE_LENGTHback to summary
private static final int ALIAS_TRUNCATE_LENGTH
WHITESPACEback to summary
public static final String WHITESPACE

Constructor Detail

StringHelperback to summary
private StringHelper()

Method Detail

addback to summary
public static String[] add(String[] x, String sep, String[] y)
booleanValueback to summary
public static boolean booleanValue(String tfString)
cleanAliasback to summary
private static String cleanAlias(String alias)

Clean the generated alias by removing any non-alpha characters from the beginning.

Parameters
alias:String

The generated alias to be cleaned.

Returns:String

The cleaned alias, stripped of any leading non-alpha characters.

collapseback to summary
public static String collapse(String name)

Collapses a name. Mainly intended for use with classnames, where an example might serve best to explain. Imagine you have a class named 'org.hibernate.util.StringHelper'; calling collapse on that classname will result in 'o.h.u.StringHelper'.

Parameters
name:String

The name to collapse.

Returns:String

The collapsed name.

collapseQualifierback to summary
public static String collapseQualifier(String qualifier, boolean includeDots)

Given a qualifier, collapse it.

Parameters
qualifier:String

The qualifier to collapse.

includeDots:boolean

Should we include the dots in the collapsed form?

Returns:String

The collapsed form.

collapseQualifierBaseback to summary
public static String collapseQualifierBase(String name, String qualifierBase)

Cross between collapse and partiallyUnqualify. Functions much like collapse except that only the qualifierBase is collapsed. For example, with a base of 'org.hibernate' the name 'org.hibernate.util.StringHelper' would become 'o.h.util.StringHelper'.

Parameters
name:String

The (potentially) qualified name.

qualifierBase:String

The qualifier base.

Returns:String

The name itself if it does not begin with the qualifierBase, or the properly collapsed form otherwise.

countUnquotedback to summary
public static int countUnquoted(String string, char character)
firstIndexOfCharback to summary
public static int firstIndexOfChar(String sqlString, String string, int startindex)
generateAliasback to summary
public static String generateAlias(String description)
generateAliasback to summary
public static String generateAlias(String description, int unique)

Generate a nice alias for the given class name or collection role name and unique integer. Subclasses of Loader do not have to use aliases of this form.

Parameters
description:String

The base name (usually an entity-name or collection-role)

unique:int

A uniquing value

Returns:String

an alias of the form foo1_

generateAliasRootback to summary
private static String generateAliasRoot(String description)

Generates a root alias by truncating the "root name" defined by the incoming decription and removing/modifying any non-valid alias characters.

Parameters
description:String

The root name from which to generate a root alias.

Returns:String

The generated root alias.

getFirstNonWhitespaceCharacterback to summary
public static char getFirstNonWhitespaceCharacter(String str)
getLastNonWhitespaceCharacterback to summary
public static char getLastNonWhitespaceCharacter(String str)
isEmptyback to summary
public static boolean isEmpty(String string)
isNotEmptyback to summary
public static boolean isNotEmpty(String string)
isQuotedback to summary
public static boolean isQuoted(String name)

Determine if the given string is quoted (wrapped by '`' characters at beginning and end).

Parameters
name:String

The name to check.

Returns:boolean

True if the given string starts and ends with '`'; false otherwise.

isQuotedback to summary
public static boolean isQuoted(String name, Dialect dialect)

Determine if the given name is quoted. It is considered quoted if either:

  1. starts AND ends with backticks (`)
  2. starts with dialect-specified open-quote AND ends with dialect-specified close-quote
Parameters
name:String

The name to check

dialect:Dialect

The dialect (to determine the "real" quoting chars).

Returns:boolean

True if quoted, false otherwise

joinback to summary
public static String join(String seperator, String[] strings)
joinback to summary
public static String join(String seperator, Iterator<E> objects)
lastIndexOfLetterback to summary
public static int lastIndexOfLetter(String string)
locateUnquotedback to summary
public static int[] locateUnquoted(String string, char character)
moveAndToBeginningback to summary
public static String moveAndToBeginning(String filter)
multiplyback to summary
public static String[] multiply(String string, Iterator<E> placeholders, Iterator<E> replacements)
multiplyback to summary
private static String[] multiply(String[] strings, String placeholder, String[] replacements)
partiallyUnqualifyback to summary
public static String partiallyUnqualify(String name, String qualifierBase)

Partially unqualifies a qualified name. For example, with a base of 'org.hibernate' the name 'org.hibernate.util.StringHelper' would become 'util.StringHelper'.

Parameters
name:String

The (potentially) qualified name.

qualifierBase:String

The qualifier base.

Returns:String

The name itself, or the partially unqualified form if it begins with the qualifier base.

qualifierback to summary
public static String qualifier(String qualifiedName)
qualifyback to summary
public static String qualify(String prefix, String name)
qualifyback to summary
public static String[] qualify(String prefix, String[] names)
quoteback to summary
public static String quote(String name)

Return a representation of the given name ensuring quoting (wrapped with '`' characters). If already wrapped return name.

Parameters
name:String

The name to quote.

Returns:String

The quoted version.

repeatback to summary
public static String repeat(String string, int times)
repeatback to summary
public static String repeat(char character, int times)
replaceback to summary
public static String replace(String template, String placeholder, String replacement)
replaceback to summary
public static String[] replace(String[] templates, String placeholder, String replacement)
replaceback to summary
public static String replace(String template, String placeholder, String replacement, boolean wholeWords)
replaceback to summary
public static String replace(String template, String placeholder, String replacement, boolean wholeWords, boolean encloseInParensIfNecessary)
replaceback to summary
public static String replace(String beforePlaceholder, String afterPlaceholder, String placeholder, String replacement, boolean wholeWords, boolean encloseInParensIfNecessary)
replaceOnceback to summary
public static String replaceOnce(String template, String placeholder, String replacement)
rootback to summary
public static String root(String qualifiedName)
splitback to summary
public static String[] split(String seperators, String list)
splitback to summary
public static String[] split(String seperators, String list, boolean include)
suffixback to summary
public static String[] suffix(String[] columns, String suffix)
suffixback to summary
private static String suffix(String name, String suffix)
toLowerCaseback to summary
public static String toLowerCase(String str)
toStringback to summary
public static String toString(Object[] array)
toUpperCaseback to summary
public static String toUpperCase(String str)
truncateback to summary
public static String truncate(String string, int length)
unqualifyback to summary
public static String unqualify(String qualifiedName)
unqualifyEntityNameback to summary
public static String unqualifyEntityName(String entityName)
unquoteback to summary
public static String unquote(String name)

Return the unquoted version of name (stripping the start and end '`' characters if present).

Parameters
name:String

The name to be unquoted.

Returns:String

The unquoted version.

unquoteback to summary
public static String unquote(String name, Dialect dialect)

Return the unquoted version of name stripping the start and end quote characters.

Parameters
name:String

The name to be unquoted.

dialect:Dialect

The dialect (to determine the "real" quoting chars).

Returns:String

The unquoted version.

unquoteback to summary
public static String[] unquote(String[] names, Dialect dialect)

Return the unquoted version of name stripping the start and end quote characters.

Parameters
names:String[]

The names to be unquoted.

dialect:Dialect

The dialect (to determine the "real" quoting chars).

Returns:String[]

The unquoted versions.

unrootback to summary
public static String unroot(String qualifiedName)