com.github.drinkjava2.jdialects.hibernatesrc.utils
Class StringHelper

java.lang.Object
  extended by com.github.drinkjava2.jdialects.hibernatesrc.utils.StringHelper

public final class StringHelper
extends Object

Author:
Hibernate, Yong Zhu(modify)

Nested Class Summary
static interface StringHelper.Renderer<T>
           
 
Field Summary
static String BATCH_ID_PLACEHOLDER
           
static String[] EMPTY_STRINGS
           
static String WHITESPACE
           
 
Method Summary
static String[] add(String[] x, String sep, String[] y)
           
static boolean booleanValue(String tfString)
           
static String collapse(String name)
          Collapses a name.
static String collapseQualifier(String qualifier, boolean includeDots)
          Given a qualifier, collapse it.
static String collapseQualifierBase(String name, String qualifierBase)
          Cross between collapse(java.lang.String) and partiallyUnqualify(java.lang.String, java.lang.String).
static int countUnquoted(String string, char character)
           
static int firstIndexOfChar(String sqlString, BitSet keys, int startindex)
           
static int firstIndexOfChar(String sqlString, String string, 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 getFirstNonWhitespaceCharacter(String str)
           
static char getLastNonWhitespaceCharacter(String str)
           
static boolean isEmpty(String string)
           
static boolean isEmptyOrWhiteSpace(String string)
           
static boolean isNotEmpty(String string)
           
static boolean isQuoted(String name)
          Determine if the given string is quoted (wrapped by '`' characters at beginning and end).
static
<T> String
join(Collection<T> values, StringHelper.Renderer<T> renderer)
           
static String join(String separator, Iterable objects)
           
static String join(String seperator, Iterator objects)
           
static String join(String seperator, String[] strings)
           
static
<T> String
join(T[] values, StringHelper.Renderer<T> renderer)
           
static String joinWithQualifierAndSuffix(String[] values, String qualifier, String suffix, String deliminator)
           
static int lastIndexOfLetter(String string)
           
static String moveAndToBeginning(String filter)
           
static String[] multiply(String string, Iterator placeholders, Iterator replacements)
           
static String nullIfEmpty(String value)
           
static List<String> parseCommaSeparatedString(String incomingString)
           
static String partiallyUnqualify(String name, String qualifierBase)
          Partially unqualifies a qualified name.
static String qualifier(String qualifiedName)
           
static String qualify(String prefix, String name)
           
static String[] qualify(String prefix, String[] names)
           
static String qualifyConditionally(String prefix, String name)
           
static String[] qualifyIfNot(String prefix, String[] names)
           
static String quote(String name)
          Return a representation of the given name ensuring quoting (wrapped with '`' characters).
static String repeat(char character, int times)
           
static String repeat(String string, int times)
           
static String repeat(String string, int times, String deliminator)
           
static String[] replace(String[] templates, String placeholder, String replacement)
           
static String replace(String template, String placeholder, String replacement)
           
static String replace(String template, String placeholder, String replacement, boolean wholeWords)
           
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 root(String qualifiedName)
           
static String[] split(String separators, String list)
           
static String[] split(String separators, String list, boolean include)
           
static String[] splitTrimmingTokens(String separators, String list, boolean include)
           
static String[] suffix(String[] columns, String suffix)
           
static String[] toArrayElement(String s)
          Takes a String s and returns a new String[1] with s as the only element.
static String toString(Object[] array)
           
static String truncate(String string, int length)
           
static String unqualify(String qualifiedName)
           
static String unqualifyEntityName(String entityName)
           
static String unquote(String name)
          Return the unquoted version of name (stripping the start and end '`' characters if present).
static String unroot(String qualifiedName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WHITESPACE

public static final String WHITESPACE
See Also:
Constant Field Values

EMPTY_STRINGS

public static final String[] EMPTY_STRINGS

BATCH_ID_PLACEHOLDER

public static final String BATCH_ID_PLACEHOLDER
See Also:
Constant Field Values
Method Detail

lastIndexOfLetter

public static int lastIndexOfLetter(String string)

join

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

joinWithQualifierAndSuffix

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

join

public static String join(String seperator,
                          Iterator objects)

join

public static String join(String separator,
                          Iterable objects)

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)

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)

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)

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)

booleanValue

public static boolean booleanValue(String tfString)

toString

public static String toString(Object[] array)

multiply

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

countUnquoted

public static int countUnquoted(String string,
                                char character)

isNotEmpty

public static boolean isNotEmpty(String string)

isEmpty

public static boolean isEmpty(String string)

isEmptyOrWhiteSpace

public static boolean isEmptyOrWhiteSpace(String string)

qualify

public static String qualify(String prefix,
                             String name)

qualifyConditionally

public static String qualifyConditionally(String prefix,
                                          String name)

qualify

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

qualifyIfNot

public static String[] qualifyIfNot(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)

moveAndToBeginning

public static String moveAndToBeginning(String filter)

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.

quote

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 - The name to quote.
Returns:
The quoted version.

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.

toArrayElement

public static String[] toArrayElement(String s)
Takes a String s and returns a new String[1] with s as the only element. If s is null or "", return String[0].

Parameters:
s -
Returns:
String[]

nullIfEmpty

public static String nullIfEmpty(String value)

parseCommaSeparatedString

public static List<String> parseCommaSeparatedString(String incomingString)

join

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

join

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


Copyright © 2018. All rights reserved.