Class StringHelper

java.lang.Object
org.hibernate.internal.util.StringHelper

public final class StringHelper extends Object
  • Field Details

  • Method Details

    • lastIndexOfLetter

      public static int lastIndexOfLetter(String string)
    • join

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

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

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

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

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

      public static String[] add(String[] x, String sep, String[] y)
    • repeat

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

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

      public static String repeat(char character, int times)
    • repeat

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

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

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

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

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

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

      public static int indexOfIdentifierWord(String str, String word)
      Used to find the ordinal parameters (e.g. '?1') in a string.
    • getLastNonWhitespaceCharacter

      public static char getLastNonWhitespaceCharacter(String str)
    • getFirstNonWhitespaceCharacter

      public static char getFirstNonWhitespaceCharacter(String str)
    • replaceOnce

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

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

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

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

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

      public static String unqualify(String qualifiedName)
    • qualifier

      public static String qualifier(String qualifiedName)
    • collapse

      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 - The name to collapse.
      Returns:
      The collapsed name.
    • collapseQualifier

      public static String collapseQualifier(String qualifier, boolean includeDots)
      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

      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 - 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

      public static String collapseQualifierBase(String name, String qualifierBase)
      Cross between collapse(java.lang.String) and partiallyUnqualify(java.lang.String, java.lang.String). Functions much like collapse(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

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

      public static String root(String qualifiedName)
    • unroot

      public static String unroot(String qualifiedName)
    • toString

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

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

      public static int count(String text, String match)
    • count

      public static int count(String text, char match)
    • countUnquoted

      public static int countUnquoted(String string, char character)
    • isNotEmpty

      public static boolean isNotEmpty(@Nullable String string)
    • isEmpty

      public static boolean isEmpty(@Nullable String string)
    • isNotBlank

      public static boolean isNotBlank(@Nullable String string)
    • isBlank

      public static boolean isBlank(@Nullable String string)
    • qualify

      public static String qualify(String prefix, String name)
    • qualifyConditionally

      public static String qualifyConditionally(String prefix, String name)
    • qualifyConditionallyIfNot

      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(java.lang.String, java.lang.String), except that here we explicitly check whether name is already qualified.
    • qualify

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

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

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

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

      public static String generateAlias(String description)
    • generateAlias

      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 - The base name (usually an entity-name or collection-role)
      unique - A uniquing value
      Returns:
      an alias of the form foo1_
    • unqualifyEntityName

      public static String unqualifyEntityName(String entityName)
    • isQuoted

      public static boolean isQuoted(String name)
      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

      public static String unquote(String name)
      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

      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 - The name to check
      dialect - The dialect (to determine the "real" quoting chars).
      Returns:
      True if quoted, false otherwise
    • unquote

      public static String unquote(String name, Dialect dialect)
      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

      public static String[] unquote(String[] names, Dialect dialect)
      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

      public static String nullIfEmpty(@Nullable String value)
    • nullIfBlank

      public static String nullIfBlank(@Nullable String value)
    • subStringNullIfEmpty

      public static String subStringNullIfEmpty(String value, Character startChar)
    • splitAtCommas

      public static String[] splitAtCommas(String incomingString)
    • join

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

      public static String coalesce(@NonNull String fallbackValue, @NonNull String... values)
    • coalesce

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

      public static String getNonEmptyOrConjunctionIfBothNonEmpty(String firstExpression, String secondExpression)
      Parameters:
      firstExpression - the first expression
      secondExpression - the second expression
      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.
    • safeInterning

      public static String safeInterning(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 - The string to intern.
      Returns:
      The interned string.