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 String
static String
static String
Collapses a name.static String
collapseQualifier
(String qualifier, boolean includeDots) Given a qualifier, collapse it.static String
collapseQualifierBase
(String name, String qualifierBase) Cross betweencollapse(java.lang.String)
andpartiallyUnqualify(java.lang.String, java.lang.String)
.static int
static int
static int
countUnquoted
(String string, char character) static int
firstIndexOfChar
(String sqlString, String string, int startindex) static int
firstIndexOfChar
(String sqlString, BitSet keys, int startindex) static String
generateAlias
(String description) static String
generateAlias
(String description, int unique) Generate a nice alias for the given class name or collection role name and unique integer.static char
static char
static String
getNonEmptyOrConjunctionIfBothNonEmpty
(String firstExpression, String secondExpression) static int
indexOfIdentifierWord
(String str, String word) Used to find the ordinal parameters (e.g.static boolean
static boolean
static boolean
isNotBlank
(@Nullable String string) static boolean
isNotEmpty
(@Nullable String string) static boolean
Determine if the given string is quoted (wrapped by '`' characters at beginning and end).static boolean
Determine if the given name is quoted.static String
static String
static String
static String
static <T> String
join
(Collection<T> values, StringHelper.Renderer<T> renderer) static String
joinWithQualifierAndSuffix
(String[] values, String qualifier, String suffix, String deliminator) static int
lastIndexOfLetter
(String string) static String[]
static String
nullIfBlank
(@Nullable String value) static String
nullIfEmpty
(@Nullable String value) static String
partiallyUnqualify
(String name, String qualifierBase) Partially unqualifies a qualified name.static String
static String
static String[]
static String
qualifyConditionally
(String prefix, String name) static String
qualifyConditionallyIfNot
(String prefix, String name) Qualifiesname
withprefix
separated by a '.' ifname
is not already qualifiedprefix
is not nullstatic String
repeat
(char character, int times) static String
static String
static void
repeat
(String string, int times, String separator, StringBuilder buffer) static String[]
static String
static String
static String
replace
(String template, String placeholder, String replacement, boolean wholeWords, boolean encloseInParensIfNecessary) static String
replace
(String beforePlaceholder, String afterPlaceholder, String placeholder, String replacement, boolean wholeWords, boolean encloseInParensIfNecessary) static String
replaceOnce
(String template, String placeholder, String replacement) static String
static String
safeInterning
(String string) Return the interned form of a String, or null if the parameter is null.static String[]
static String[]
static String[]
splitAtCommas
(String incomingString) static String[]
static String[]
splitTrimmingTokens
(String separators, String list, boolean include) static String
subStringNullIfEmpty
(String value, Character startChar) static String[]
static String
static String
static String
static String
unqualifyEntityName
(String entityName) static String
Return 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 String
Return 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
Qualifiesname
withprefix
separated by a '.' ifname
is not already qualifiedprefix
is not null
- API Note:
- Similar to
qualifyConditionally(java.lang.String, java.lang.String)
, except that here we explicitly check whethername
is already qualified.
-
qualify
-
firstIndexOfChar
-
firstIndexOfChar
-
truncate
-
generateAlias
-
generateAlias
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
- 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-quote
AND 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
firstExpression
andsecondExpression
are both non-empty, then "( " +firstExpression
+ " ) and ( " +secondExpression
+ " )" is returned; iffirstExpression
is non-empty andsecondExpression
is empty, thenfirstExpression
is returned; iffirstExpression
is empty andsecondExpression
is non-empty, thensecondExpression
is returned; if bothfirstExpression
andsecondExpression
are 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.
-