Package org.hibernate.internal.util
Class StringHelper
java.lang.Object
org.hibernate.internal.util.StringHelper
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]static Stringstatic Stringstatic StringCollapses a name.static StringcollapseQualifier(String qualifier, boolean includeDots) Given a qualifier, collapse it.static StringcollapseQualifierBase(String name, String qualifierBase) Cross betweencollapse(java.lang.String)andpartiallyUnqualify(java.lang.String, java.lang.String).static intstatic intstatic intcountUnquoted(String string, char character) static intfirstIndexOfChar(String sqlString, String string, int startindex) static intfirstIndexOfChar(String sqlString, BitSet keys, int startindex) static StringgenerateAlias(String description) Deprecated, for removal: This API element is subject to removal in a future version.No longer usedstatic StringgenerateAlias(String description, int unique) Deprecated, for removal: This API element is subject to removal in a future version.No longer usedstatic charstatic charstatic StringgetNonEmptyOrConjunctionIfBothNonEmpty(String firstExpression, String secondExpression) static intindexOfIdentifierWord(String str, String word) Used to find the ordinal parameters (e.g.static booleanstatic booleanstatic booleanisNotBlank(@Nullable String string) static booleanisNotEmpty(@Nullable String string) static booleanDetermine if the given string is quoted (wrapped by '`' characters at beginning and end).static booleanDetermine if the given name is quoted.static Stringstatic Stringstatic Stringstatic Stringstatic <T> Stringjoin(Collection<T> values, StringHelper.Renderer<T> renderer) static StringjoinWithQualifierAndSuffix(String[] values, String qualifier, String suffix, String deliminator) static intlastIndexOfLetter(String string) static String[]static @Nullable StringnullIfBlank(@Nullable String value) static @Nullable StringnullIfEmpty(@Nullable String value) static StringpartiallyUnqualify(String name, String qualifierBase) Partially unqualifies a qualified name.static Stringstatic Stringstatic String[]static StringqualifyConditionally(String prefix, String name) static StringqualifyConditionallyIfNot(String prefix, String name) Qualifiesnamewithprefixseparated by a '.' ifnameis not already qualifiedprefixis not nullstatic Stringrepeat(char character, int times) static Stringstatic Stringstatic voidrepeat(String string, int times, String separator, StringBuilder buffer) static String[]static Stringstatic Stringstatic Stringreplace(String template, String placeholder, String replacement, boolean wholeWords, boolean encloseInParensIfNecessary) static Stringreplace(String beforePlaceholder, String afterPlaceholder, String placeholder, String replacement, boolean wholeWords, boolean encloseInParensIfNecessary) static StringreplaceOnce(String template, String placeholder, String replacement) static Stringstatic StringsafeInterning(String string) Return the interned form of a String, or null if the parameter is null.static String[]static String[]static String[]splitAtCommas(@Nullable String incomingString) static String[]static String[]splitTrimmingTokens(String separators, String list, boolean include) static @Nullable StringsubStringNullIfEmpty(String value, Character startChar) static String[]static Stringstatic Stringstatic Stringstatic StringunqualifyEntityName(String entityName) static StringReturn the unquoted version of name (stripping the start and end '`' characters if present).static String[]Return the unquoted version of name stripping the start and end quote characters.static StringReturn the unquoted version of name stripping the start and end quote characters.static String
-
Field Details
-
WHITESPACE
- See Also:
-
EMPTY_STRINGS
-
-
Method Details
-
lastIndexOfLetter
-
join
-
join
-
join
-
join
-
joinWithQualifierAndSuffix
-
add
-
repeat
-
repeat
-
repeat
-
repeat
-
replace
-
replace
-
replace
-
replace
-
replace
-
indexOfIdentifierWord
Used to find the ordinal parameters (e.g. '?1') in a string. -
getLastNonWhitespaceCharacter
-
getFirstNonWhitespaceCharacter
-
replaceOnce
-
split
-
split
-
splitTrimmingTokens
-
splitFull
-
unqualify
-
qualifier
-
collapse
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- The name to collapse.- Returns:
- The collapsed name.
-
collapseQualifier
Given a qualifier, collapse it.- Parameters:
qualifier- The qualifier to collapse.includeDots- Should we include the dots in the collapsed form?- Returns:
- The collapsed form.
-
partiallyUnqualify
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- The (potentially) qualified name.qualifierBase- The qualifier base.- Returns:
- The name itself, or the partially unqualified form if it begins with the qualifier base.
-
collapseQualifierBase
Cross betweencollapse(java.lang.String)andpartiallyUnqualify(java.lang.String, java.lang.String). Functions much likecollapse(java.lang.String)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- The (potentially) qualified name.qualifierBase- The qualifier base.- Returns:
- The name itself if it does not begin with the qualifierBase, or the properly collapsed form otherwise.
-
suffix
-
root
-
unroot
-
toString
-
multiply
-
count
-
count
-
countUnquoted
-
isNotEmpty
-
isEmpty
-
isNotBlank
-
isBlank
-
qualify
-
qualifyConditionally
-
qualifyConditionallyIfNot
Qualifiesnamewithprefixseparated by a '.' ifnameis not already qualifiedprefixis not null
- API Note:
- Similar to
qualifyConditionally(java.lang.String, java.lang.String), except that here we explicitly check whethernameis already qualified.
-
qualify
-
firstIndexOfChar
-
firstIndexOfChar
-
truncate
-
generateAlias
Deprecated, for removal: This API element is subject to removal in a future version.No longer used -
generateAlias
@Deprecated(since="7", forRemoval=true) public static String generateAlias(String description, int unique) Deprecated, for removal: This API element is subject to removal in a future version.No longer usedGenerate 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- The base name (usually an entity-name or collection-role)unique- A uniquing value- Returns:
- an alias of the form foo1_
-
unqualifyEntityName
-
isQuoted
Determine if the given string is quoted (wrapped by '`' characters at beginning and end).- Parameters:
name- The name to check.- Returns:
- True if the given string starts and ends with '`'; false otherwise.
-
unquote
Return the unquoted version of name (stripping the start and end '`' characters if present).- Parameters:
name- The name to be unquoted.- Returns:
- The unquoted version.
-
isQuoted
Determine if the given name is quoted. It is considered quoted if either:- starts AND ends with backticks (`)
- starts with dialect-specified
open-quoteAND ends with dialect-specifiedclose-quote
- Parameters:
name- The name to checkdialect- The dialect (to determine the "real" quoting chars).- Returns:
- True if quoted, false otherwise
-
unquote
Return the unquoted version of name stripping the start and end quote characters.- Parameters:
name- The name to be unquoted.dialect- The dialect (to determine the "real" quoting chars).- Returns:
- The unquoted version.
-
unquote
Return the unquoted version of name stripping the start and end quote characters.- Parameters:
names- The names to be unquoted.dialect- The dialect (to determine the "real" quoting chars).- Returns:
- The unquoted versions.
-
nullIfEmpty
-
nullIfBlank
-
subStringNullIfEmpty
-
splitAtCommas
-
join
-
coalesce
-
coalesce
-
getNonEmptyOrConjunctionIfBothNonEmpty
public static String getNonEmptyOrConjunctionIfBothNonEmpty(String firstExpression, String secondExpression) - Parameters:
firstExpression- the first expressionsecondExpression- the second expression- Returns:
- if
firstExpressionandsecondExpressionare both non-empty, then "( " +firstExpression+ " ) and ( " +secondExpression+ " )" is returned; iffirstExpressionis non-empty andsecondExpressionis empty, thenfirstExpressionis returned; iffirstExpressionis empty andsecondExpressionis non-empty, thensecondExpressionis returned; if bothfirstExpressionandsecondExpressionare empty, then null is returned.
-
safeInterning
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- The string to intern.- Returns:
- The interned string.
-