Top Inners Fields Constructors Methods
org.hibernate.internal.util

public final Class StringHelper

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .BitSet, .Collection, .Iterator, .List, .Locale, .StringTokenizer, org.hibernate.boot.model.source.internal.hbm.CommaSeparatedStringHelper, org.hibernate.dialect.Dialect, org.hibernate.internal.util.collections.ArrayHelper, org.hibernate.loader.internal.AliasConstantsHelper, org.checkerframework.checker.nullness.qual.NonNull, .Nullable

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
private static final int
public static final String[]
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)

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
coalesce(@NonNull String fallbackValue, @NonNull String... values)

public static String
coalesce(@NonNull String fallbackValue, String value)

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
count(String text, String match)

public static int
count(String text, char match)

public static int
countUnquoted(String string, char character)

public static int
firstIndexOfChar(String sqlString, BitSet keys, int startindex)

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 description and removing/modifying any non-valid alias characters.

public static char
public static char
public static String

Returns:

if firstExpression and secondExpression are both non-empty, then "( " + firstExpression + " ) and ( " + secondExpression + " )" is returned; if firstExpression is non-empty and secondExpression is empty, then firstExpression is returned; if firstExpression is empty and secondExpression is non-empty, then secondExpression is returned; if both firstExpression and secondExpression are empty, then null is returned.
getNonEmptyOrConjunctionIfBothNonEmpty
(String
the first expression
firstExpression
,
String
the second expression
secondExpression
)

public static int
indexOfIdentifierWord(String str, String word)

Used to find the ordinal parameters (e.g. '?1') in a string.

private static int
indexOfPlaceHolder(String template, String placeholder, boolean wholeWords)

public static boolean
isBlank(String string)

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
(final 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
(final String
The name to check
name
,
final Dialect
The dialect (to determine the "real" quoting chars).
dialect
)

Determine if the given name is quoted.

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

public static String
join(String separator, Object[] values)

public static String
join(String separator, Iterable<?> objects)

public static String
join(String separator, Iterator<?> objects)

public static <T> String
join(Collection<T> values, StringHelper.Renderer<T> renderer)

public static String
joinWithQualifierAndSuffix(String[] values, String qualifier, String suffix, String deliminator)

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

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

public static String
public static List<String>
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
public static String
qualifyConditionallyIfNot(String prefix, String name)

Qualifies name with prefix separated by a '.' if

  • name is not already qualified
  • prefix is not null
public static String
repeat(String string, int times)

public static String
repeat(String string, int times, String deliminator)

public static String
repeat(char character, int times)

public static void
repeat(String string, int times, String separator, StringBuilder buffer)

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

Returns:

The interned string.
safeInterning
(final String
The string to intern.
string
)

Return the interned form of a String, or null if the parameter is null.

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

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

public static String[]
splitFull(String separators, String list)

public static String[]
splitTrimmingTokens(String separators, String list, boolean include)

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

private static String
suffix(String name, String suffix)

public static String
toString(Object[] array)

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
(final String[]
The names to be unquoted.
names
,
final 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
EMPTY_STRINGSback to summary
public static final String[] EMPTY_STRINGS
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)
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.

coalesceback to summary
public static String coalesce(@NonNull String fallbackValue, @NonNull String... values)
coalesceback to summary
public static String coalesce(@NonNull String fallbackValue, String value)
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.internal.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.internal.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.

countback to summary
public static int count(String text, String match)
countback to summary
public static int count(String text, char match)
countUnquotedback to summary
public static int countUnquoted(String string, char character)
firstIndexOfCharback to summary
public static int firstIndexOfChar(String sqlString, BitSet keys, int startindex)
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 description 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)
getNonEmptyOrConjunctionIfBothNonEmptyback to summary
public static String getNonEmptyOrConjunctionIfBothNonEmpty(String firstExpression, String secondExpression)
Parameters
firstExpression:String

the first expression

secondExpression:String

the second expression

Returns:String

if firstExpression and secondExpression are both non-empty, then "( " + firstExpression + " ) and ( " + secondExpression + " )" is returned; if firstExpression is non-empty and secondExpression is empty, then firstExpression is returned; if firstExpression is empty and secondExpression is non-empty, then secondExpression is returned; if both firstExpression and secondExpression are empty, then null is returned.

indexOfIdentifierWordback to summary
public static int indexOfIdentifierWord(String str, String word)

Used to find the ordinal parameters (e.g. '?1') in a string.

indexOfPlaceHolderback to summary
private static int indexOfPlaceHolder(String template, String placeholder, boolean wholeWords)
isBlankback to summary
public static boolean isBlank(String string)
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(final 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(final String name, final 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 separator, String[] strings)
joinback to summary
public static String join(String separator, Object[] values)
joinback to summary
public static String join(String separator, Iterable<?> objects)
joinback to summary
public static String join(String separator, Iterator<?> objects)
joinback to summary
public static <T> String join(Collection<T> values, StringHelper.Renderer<T> renderer)
joinWithQualifierAndSuffixback to summary
public static String joinWithQualifierAndSuffix(String[] values, String qualifier, String suffix, String deliminator)
lastIndexOfLetterback to summary
public static int lastIndexOfLetter(String string)
moveAndToBeginningback to summary
public static String moveAndToBeginning(String filter)
multiplyback to summary
public static String[] multiply(String string, Iterator<String> placeholders, Iterator<String[]> replacements)
multiplyback to summary
private static String[] multiply(String[] strings, String placeholder, String[] replacements)
nullIfEmptyback to summary
public static String nullIfEmpty(@Nullable String value)
parseCommaSeparatedStringback to summary
public static List<String> parseCommaSeparatedString(String incomingString)
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.internal.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)
qualifyConditionallyback to summary
public static String qualifyConditionally(String prefix, String name)
qualifyConditionallyIfNotback to summary
public static String qualifyConditionallyIfNot(String prefix, String name)

Qualifies name with prefix separated by a '.' if

  • name is not already qualified
  • prefix is not null

API Note

Similar to qualifyConditionally, except that here we explicitly check whether name is already qualified.

repeatback to summary
public static String repeat(String string, int times)
repeatback to summary
public static String repeat(String string, int times, String deliminator)
repeatback to summary
public static String repeat(char character, int times)
repeatback to summary
public static void repeat(String string, int times, String separator, StringBuilder buffer)
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)
safeInterningback to summary
public static String safeInterning(final String string)

Return the interned form of a String, or null if the parameter is null.

Use with caution: excessive interning is known to cause issues. Best to use only with strings which are known to be long-lived constants, and for which the chances of being actual duplicates is proven. (Even better: avoid needing interning by design changes such as reusing the known reference)

Parameters
string:String

The string to intern.

Returns:String

The interned string.

splitback to summary
public static String[] split(String separators, String list)
splitback to summary
public static String[] split(String separators, String list, boolean include)
splitFullback to summary
public static String[] splitFull(String separators, String list)
splitTrimmingTokensback to summary
public static String[] splitTrimmingTokens(String separators, String list, boolean include)
subStringNullIfEmptyback to summary
public static String subStringNullIfEmpty(String value, Character startChar)
suffixback to summary
public static String[] suffix(String[] columns, String suffix)
suffixback to summary
private static String suffix(String name, String suffix)
toStringback to summary
public static String toString(Object[] array)
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(final String[] names, final 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)
org.hibernate.internal.util back to summary

public Interface StringHelper.Renderer<T>


Method Summary

Modifier and TypeMethod and Description
public String
render(T value)

Method Detail

renderback to summary
public String render(T value)