minor code cleanups to StringHelper

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-11-08 00:09:37 +01:00
parent 3457b2d283
commit b33890b38b
1 changed files with 153 additions and 173 deletions

View File

@ -15,17 +15,22 @@ import java.util.StringTokenizer;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.loader.internal.AliasConstantsHelper; import org.hibernate.loader.internal.AliasConstantsHelper;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import static java.lang.Character.isDigit;
import static java.lang.Character.isJavaIdentifierPart;
import static java.lang.Character.isLetter;
import static java.lang.Character.isWhitespace;
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_STRING_ARRAY;
public final class StringHelper { public final class StringHelper {
private static final int ALIAS_TRUNCATE_LENGTH = 10; private static final int ALIAS_TRUNCATE_LENGTH = 10;
public static final String WHITESPACE = " \n\r\f\t"; public static final String WHITESPACE = " \n\r\f\t";
public static final String[] EMPTY_STRINGS = ArrayHelper.EMPTY_STRING_ARRAY; public static final String[] EMPTY_STRINGS = EMPTY_STRING_ARRAY;
private static final Pattern COMMA_SEPARATED_PATTERN = Pattern.compile( "\\s*,\\s*" ); private static final Pattern COMMA_SEPARATED_PATTERN = Pattern.compile( "\\s*,\\s*" );
@ -34,9 +39,9 @@ public final class StringHelper {
public static int lastIndexOfLetter(String string) { public static int lastIndexOfLetter(String string) {
for ( int i = 0; i < string.length(); i++ ) { for ( int i = 0; i < string.length(); i++ ) {
char character = string.charAt( i ); final char character = string.charAt( i );
// Include "_". See HHH-8073 // Include "_". See HHH-8073
if ( !Character.isLetter( character ) && !( '_' == character ) ) { if ( !isLetter( character ) && !( '_' == character ) ) {
return i - 1; return i - 1;
} }
} }
@ -44,37 +49,43 @@ public final class StringHelper {
} }
public static String join(String separator, String[] strings) { public static String join(String separator, String[] strings) {
int length = strings.length; final int length = strings.length;
if ( length == 0 ) { if ( length == 0 ) {
return ""; return "";
} }
// Allocate space for length * firstStringLength; else {
// If strings[0] is null, then its length is defined as 4, since that's the // Allocate space for length * firstStringLength;
// length of "null". // If strings[0] is null, then its length is defined as 4, since that's the
final int firstStringLength = strings[0] != null ? strings[0].length() : 4; // length of "null".
StringBuilder buf = new StringBuilder( length * firstStringLength ) final int firstStringLength = strings[0] != null ? strings[0].length() : 4;
.append( strings[0] ); final StringBuilder buf =
for ( int i = 1; i < length; i++ ) { new StringBuilder( length * firstStringLength )
buf.append( separator ).append( strings[i] ); .append( strings[0] );
for ( int i = 1; i < length; i++ ) {
buf.append( separator ).append( strings[i] );
}
return buf.toString();
} }
return buf.toString();
} }
public static String join(String separator, Object[] values) { public static String join(String separator, Object[] values) {
int length = values.length; final int length = values.length;
if ( length == 0 ) { if ( length == 0 ) {
return ""; return "";
} }
// Allocate space for length * firstStringLength; else {
// If strings[0] is null, then its length is defined as 4, since that's the // Allocate space for length * firstStringLength;
// length of "null". // If strings[0] is null, then its length is defined as 4, since that's the
final int firstStringLength = values[0] != null ? values[0].toString().length() : 4; // length of "null".
StringBuilder buf = new StringBuilder( length * firstStringLength ) final int firstStringLength = values[0] != null ? values[0].toString().length() : 4;
.append( values[0] ); final StringBuilder buf =
for ( int i = 1; i < length; i++ ) { new StringBuilder( length * firstStringLength )
buf.append( separator ).append( values[i] ); .append( values[0] );
for ( int i = 1; i < length; i++ ) {
buf.append( separator ).append( values[i] );
}
return buf.toString();
} }
return buf.toString();
} }
public static String join(String separator, Iterable<?> objects) { public static String join(String separator, Iterable<?> objects) {
@ -82,7 +93,7 @@ public final class StringHelper {
} }
public static String join(String separator, Iterator<?> objects) { public static String join(String separator, Iterator<?> objects) {
StringBuilder buf = new StringBuilder(); final StringBuilder buf = new StringBuilder();
if ( objects.hasNext() ) { if ( objects.hasNext() ) {
buf.append( objects.next() ); buf.append( objects.next() );
} }
@ -97,12 +108,13 @@ public final class StringHelper {
String qualifier, String qualifier,
String suffix, String suffix,
String deliminator) { String deliminator) {
int length = values.length; final int length = values.length;
if ( length == 0 ) { if ( length == 0 ) {
return ""; return "";
} }
StringBuilder buf = new StringBuilder( length * ( values[0].length() + suffix.length() ) ) final StringBuilder buf =
.append( qualify( qualifier, values[0] ) ).append( suffix ); new StringBuilder( length * ( values[0].length() + suffix.length() ) )
.append( qualify( qualifier, values[0] ) ).append( suffix );
for ( int i = 1; i < length; i++ ) { for ( int i = 1; i < length; i++ ) {
buf.append( deliminator ).append( qualify( qualifier, values[i] ) ).append( suffix ); buf.append( deliminator ).append( qualify( qualifier, values[i] ) ).append( suffix );
} }
@ -118,16 +130,13 @@ public final class StringHelper {
} }
public static String repeat(String string, int times) { public static String repeat(String string, int times) {
StringBuilder buf = new StringBuilder( string.length() * times ); return string.repeat( Math.max( 0, times ) );
for ( int i = 0; i < times; i++ ) {
buf.append( string );
}
return buf.toString();
} }
public static String repeat(String string, int times, String deliminator) { public static String repeat(String string, int times, String deliminator) {
StringBuilder buf = new StringBuilder( ( string.length() * times ) + ( deliminator.length() * ( times - 1 ) ) ) final StringBuilder buf =
.append( string ); new StringBuilder( string.length() * times + deliminator.length() * ( times - 1 ) )
.append( string );
for ( int i = 1; i < times; i++ ) { for ( int i = 1; i < times; i++ ) {
buf.append( deliminator ).append( string ); buf.append( deliminator ).append( string );
} }
@ -135,7 +144,7 @@ public final class StringHelper {
} }
public static String repeat(char character, int times) { public static String repeat(char character, int times) {
char[] buffer = new char[times]; final char[] buffer = new char[times];
Arrays.fill( buffer, character ); Arrays.fill( buffer, character );
return new String( buffer ); return new String( buffer );
} }
@ -152,7 +161,7 @@ public final class StringHelper {
} }
public static String[] replace(String[] templates, String placeholder, String replacement) { public static String[] replace(String[] templates, String placeholder, String replacement) {
String[] result = new String[templates.length]; final String[] result = new String[templates.length];
for ( int i = 0; i < templates.length; i++ ) { for ( int i = 0; i < templates.length; i++ ) {
result[i] = replace( templates[i], placeholder, replacement ); result[i] = replace( templates[i], placeholder, replacement );
} }
@ -200,7 +209,7 @@ public final class StringHelper {
final boolean actuallyReplace = final boolean actuallyReplace =
!wholeWords !wholeWords
|| afterPlaceholder.isEmpty() || afterPlaceholder.isEmpty()
|| !Character.isJavaIdentifierPart( afterPlaceholder.charAt( 0 ) ); || !isJavaIdentifierPart( afterPlaceholder.charAt( 0 ) );
// We only need to check the left param to determine if the placeholder is already // We only need to check the left param to determine if the placeholder is already
// enclosed in parentheses (HHH-10383) // enclosed in parentheses (HHH-10383)
// Examples: // Examples:
@ -215,9 +224,9 @@ public final class StringHelper {
final boolean encloseInParens = final boolean encloseInParens =
actuallyReplace actuallyReplace
&& encloseInParensIfNecessary && encloseInParensIfNecessary
&& !( getLastNonWhitespaceCharacter( beforePlaceholder ) == '(' ) && && !( getLastNonWhitespaceCharacter( beforePlaceholder ) == '(' )
!( getLastNonWhitespaceCharacter( beforePlaceholder ) == ',' && getFirstNonWhitespaceCharacter( && !( getLastNonWhitespaceCharacter( beforePlaceholder ) == ','
afterPlaceholder ) == ')' ); && getFirstNonWhitespaceCharacter( afterPlaceholder ) == ')' );
final StringBuilder buf = new StringBuilder( beforePlaceholder ); final StringBuilder buf = new StringBuilder( beforePlaceholder );
if ( encloseInParens ) { if ( encloseInParens ) {
buf.append( '(' ); buf.append( '(' );
@ -246,7 +255,7 @@ public final class StringHelper {
placeholderIndex = template.indexOf( placeholder, placeholderIndex + 1 ); placeholderIndex = template.indexOf( placeholder, placeholderIndex + 1 );
isPartialPlaceholderMatch = placeholderIndex != -1 && isPartialPlaceholderMatch = placeholderIndex != -1 &&
template.length() > placeholderIndex + placeholder.length() && template.length() > placeholderIndex + placeholder.length() &&
Character.isJavaIdentifierPart( template.charAt( placeholderIndex + placeholder.length() ) ); isJavaIdentifierPart( template.charAt( placeholderIndex + placeholder.length() ) );
} while ( placeholderIndex != -1 && isPartialPlaceholderMatch ); } while ( placeholderIndex != -1 && isPartialPlaceholderMatch );
return placeholderIndex; return placeholderIndex;
@ -260,29 +269,27 @@ public final class StringHelper {
* Used to find the ordinal parameters (e.g. '?1') in a string. * Used to find the ordinal parameters (e.g. '?1') in a string.
*/ */
public static int indexOfIdentifierWord(String str, String word) { public static int indexOfIdentifierWord(String str, String word) {
if ( str == null || str.length() == 0 || word == null || word.length() == 0 ) { if ( str != null && !str.isEmpty() && word != null && !word.isEmpty() ) {
return -1; int position = str.indexOf( word );
} while ( position >= 0 && position < str.length() ) {
if (
int position = str.indexOf( word ); ( position == 0 || !isJavaIdentifierPart( str.charAt( position - 1 ) ) ) &&
while ( position >= 0 && position < str.length() ) { ( position + word.length() == str.length()
if ( || !isJavaIdentifierPart( str.charAt( position + word.length() ) ) )
( position == 0 || !Character.isJavaIdentifierPart( str.charAt( position - 1 ) ) ) && ) {
( position + word.length() == str.length() || !Character.isJavaIdentifierPart( str.charAt( position + word.length() ) ) ) return position;
) { }
return position; position = str.indexOf( word, position + 1 );
} }
position = str.indexOf( word, position + 1 );
} }
return -1; return -1;
} }
public static char getLastNonWhitespaceCharacter(String str) { public static char getLastNonWhitespaceCharacter(String str) {
if ( str != null && str.length() > 0 ) { if ( str != null && !str.isEmpty() ) {
for ( int i = str.length() - 1; i >= 0; i-- ) { for ( int i = str.length() - 1; i >= 0; i-- ) {
char ch = str.charAt( i ); final char ch = str.charAt( i );
if ( !Character.isWhitespace( ch ) ) { if ( !isWhitespace( ch ) ) {
return ch; return ch;
} }
} }
@ -291,10 +298,10 @@ public final class StringHelper {
} }
public static char getFirstNonWhitespaceCharacter(String str) { public static char getFirstNonWhitespaceCharacter(String str) {
if ( str != null && str.length() > 0 ) { if ( str != null && !str.isEmpty() ) {
for ( int i = 0; i < str.length(); i++ ) { for ( int i = 0; i < str.length(); i++ ) {
char ch = str.charAt( i ); final char ch = str.charAt( i );
if ( !Character.isWhitespace( ch ) ) { if ( !isWhitespace( ch ) ) {
return ch; return ch;
} }
} }
@ -304,25 +311,24 @@ public final class StringHelper {
public static String replaceOnce(String template, String placeholder, String replacement) { public static String replaceOnce(String template, String placeholder, String replacement) {
if ( template == null ) { if ( template == null ) {
return null; // returning null! return null;
}
int loc = template.indexOf( placeholder );
if ( loc < 0 ) {
return template;
} }
else { else {
return template.substring( 0, loc ) + replacement + template.substring( loc + placeholder.length() ); final int loc = template.indexOf( placeholder );
return loc < 0 ? template
: template.substring( 0, loc )
+ replacement
+ template.substring( loc + placeholder.length() );
} }
} }
public static String[] split(String separators, String list) { public static String[] split(String separators, String list) {
return split( separators, list, false ); return split( separators, list, false );
} }
public static String[] split(String separators, String list, boolean include) { public static String[] split(String separators, String list, boolean include) {
StringTokenizer tokens = new StringTokenizer( list, separators, include ); final StringTokenizer tokens = new StringTokenizer( list, separators, include );
String[] result = new String[tokens.countTokens()]; final String[] result = new String[tokens.countTokens()];
int i = 0; int i = 0;
while ( tokens.hasMoreTokens() ) { while ( tokens.hasMoreTokens() ) {
result[i++] = tokens.nextToken(); result[i++] = tokens.nextToken();
@ -331,8 +337,8 @@ public final class StringHelper {
} }
public static String[] splitTrimmingTokens(String separators, String list, boolean include) { public static String[] splitTrimmingTokens(String separators, String list, boolean include) {
StringTokenizer tokens = new StringTokenizer( list, separators, include ); final StringTokenizer tokens = new StringTokenizer( list, separators, include );
String[] result = new String[tokens.countTokens()]; final String[] result = new String[tokens.countTokens()];
int i = 0; int i = 0;
while ( tokens.hasMoreTokens() ) { while ( tokens.hasMoreTokens() ) {
result[i++] = tokens.nextToken().trim(); result[i++] = tokens.nextToken().trim();
@ -349,17 +355,17 @@ public final class StringHelper {
prevIndex = index + separators.length(); prevIndex = index + separators.length();
} }
parts.add( list.substring( prevIndex ) ); parts.add( list.substring( prevIndex ) );
return parts.toArray(new String[0]); return parts.toArray( EMPTY_STRING_ARRAY );
} }
public static String unqualify(String qualifiedName) { public static String unqualify(String qualifiedName) {
int loc = qualifiedName.lastIndexOf( '.' ); final int loc = qualifiedName.lastIndexOf( '.' );
return ( loc < 0 ) ? qualifiedName : qualifiedName.substring( loc + 1 ); return loc < 0 ? qualifiedName : qualifiedName.substring( loc + 1 );
} }
public static String qualifier(String qualifiedName) { public static String qualifier(String qualifiedName) {
int loc = qualifiedName.lastIndexOf( '.' ); final int loc = qualifiedName.lastIndexOf( '.' );
return ( loc < 0 ) ? "" : qualifiedName.substring( 0, loc ); return loc < 0 ? "" : qualifiedName.substring( 0, loc );
} }
/** /**
@ -375,14 +381,14 @@ public final class StringHelper {
if ( name == null ) { if ( name == null ) {
return null; return null;
} }
int breakPoint = name.lastIndexOf( '.' ); else {
if ( breakPoint < 0 ) { final int breakPoint = name.lastIndexOf( '.' );
return name; if ( breakPoint < 0 ) {
return name;
}
return collapseQualifier( name.substring( 0, breakPoint ), true )
+ name.substring( breakPoint ); // includes last '.'
} }
return collapseQualifier(
name.substring( 0, breakPoint ),
true
) + name.substring( breakPoint ); // includes last '.'
} }
/** /**
@ -394,16 +400,16 @@ public final class StringHelper {
* @return The collapsed form. * @return The collapsed form.
*/ */
public static String collapseQualifier(String qualifier, boolean includeDots) { public static String collapseQualifier(String qualifier, boolean includeDots) {
StringTokenizer tokenizer = new StringTokenizer( qualifier, "." ); final StringTokenizer tokenizer = new StringTokenizer( qualifier, "." );
StringBuilder sb = new StringBuilder(); final StringBuilder result = new StringBuilder();
sb.append( tokenizer.nextToken().charAt( 0 ) ); result.append( tokenizer.nextToken().charAt( 0 ) );
while ( tokenizer.hasMoreTokens() ) { while ( tokenizer.hasMoreTokens() ) {
if ( includeDots ) { if ( includeDots ) {
sb.append( '.' ); result.append( '.' );
} }
sb.append( tokenizer.nextToken().charAt( 0 ) ); result.append( tokenizer.nextToken().charAt( 0 ) );
} }
return sb.toString(); return result.toString();
} }
/** /**
@ -416,10 +422,9 @@ public final class StringHelper {
* @return The name itself, or the partially unqualified form if it begins with the qualifier base. * @return The name itself, or the partially unqualified form if it begins with the qualifier base.
*/ */
public static String partiallyUnqualify(String name, String qualifierBase) { public static String partiallyUnqualify(String name, String qualifierBase) {
if ( name == null || !name.startsWith( qualifierBase ) ) { return name == null || !name.startsWith( qualifierBase )
return name; ? name
} : name.substring( qualifierBase.length() + 1 ); // +1 to start after the following '.'
return name.substring( qualifierBase.length() + 1 ); // +1 to start after the following '.'
} }
/** /**
@ -433,47 +438,51 @@ public final class StringHelper {
* @return The name itself if it does not begin with the qualifierBase, or the properly collapsed form otherwise. * @return The name itself if it does not begin with the qualifierBase, or the properly collapsed form otherwise.
*/ */
public static String collapseQualifierBase(String name, String qualifierBase) { public static String collapseQualifierBase(String name, String qualifierBase) {
if ( name == null || !name.startsWith( qualifierBase ) ) { return name == null || !name.startsWith( qualifierBase )
return collapse( name ); ? collapse( name )
} : collapseQualifier( qualifierBase, true )
return collapseQualifier( qualifierBase, true ) + name.substring( qualifierBase.length() ); + name.substring( qualifierBase.length() );
} }
public static String[] suffix(String[] columns, String suffix) { public static String[] suffix(String[] columns, String suffix) {
if ( suffix == null ) { if ( suffix == null ) {
return columns; return columns;
} }
String[] qualified = new String[columns.length]; else {
for ( int i = 0; i < columns.length; i++ ) { final String[] qualified = new String[columns.length];
qualified[i] = suffix( columns[i], suffix ); for ( int i = 0; i < columns.length; i++ ) {
qualified[i] = suffix( columns[i], suffix );
}
return qualified;
} }
return qualified;
} }
private static String suffix(String name, String suffix) { private static String suffix(String name, String suffix) {
return ( suffix == null ) ? name : name + suffix; return suffix == null ? name : name + suffix;
} }
public static String root(String qualifiedName) { public static String root(String qualifiedName) {
int loc = qualifiedName.indexOf( '.' ); final int loc = qualifiedName.indexOf( '.' );
return ( loc < 0 ) ? qualifiedName : qualifiedName.substring( 0, loc ); return loc < 0 ? qualifiedName : qualifiedName.substring( 0, loc );
} }
public static String unroot(String qualifiedName) { public static String unroot(String qualifiedName) {
int loc = qualifiedName.indexOf( '.' ); final int loc = qualifiedName.indexOf( '.' );
return ( loc < 0 ) ? qualifiedName : qualifiedName.substring( loc + 1 ); return loc < 0 ? qualifiedName : qualifiedName.substring( loc + 1 );
} }
public static String toString(Object[] array) { public static String toString(Object[] array) {
int len = array.length; final int len = array.length;
if ( len == 0 ) { if ( len == 0 ) {
return ""; return "";
} }
StringBuilder buf = new StringBuilder( len * 12 ); else {
for ( int i = 0; i < len - 1; i++ ) { final StringBuilder buf = new StringBuilder( len * 12 );
buf.append( array[i] ).append( ", " ); for ( int i = 0; i < len - 1; i++ ) {
buf.append( array[i] ).append( ", " );
}
return buf.append( array[len - 1] ).toString();
} }
return buf.append( array[len - 1] ).toString();
} }
public static String[] multiply(String string, Iterator<String> placeholders, Iterator<String[]> replacements) { public static String[] multiply(String string, Iterator<String> placeholders, Iterator<String[]> replacements) {
@ -485,7 +494,7 @@ public final class StringHelper {
} }
private static String[] multiply(String[] strings, String placeholder, String[] replacements) { private static String[] multiply(String[] strings, String placeholder, String[] replacements) {
String[] results = new String[replacements.length * strings.length]; final String[] results = new String[replacements.length * strings.length];
int n = 0; int n = 0;
for ( String replacement : replacements ) { for ( String replacement : replacements ) {
for ( String string : strings ) { for ( String string : strings ) {
@ -497,14 +506,11 @@ public final class StringHelper {
public static int count(String text, String match) { public static int count(String text, String match) {
int count = 0; int count = 0;
int index = text.indexOf( match ); int index = text.indexOf( match );
while ( index > -1 ) { while ( index > -1 ) {
count++; count++;
index = text.indexOf( match, index + 1 ); index = text.indexOf( match, index + 1 );
} }
return count; return count;
} }
@ -512,22 +518,17 @@ public final class StringHelper {
if ( text == null ) { if ( text == null ) {
return 0; return 0;
} }
text = text.trim(); text = text.trim();
if ( text.isEmpty() ) { if ( text.isEmpty() ) {
return 0; return 0;
} }
int count = 0; int count = 0;
for ( int i = 0, max = text.length(); i < max; i++ ) { for ( int i = 0, max = text.length(); i < max; i++ ) {
final char check = text.charAt( i ); final char check = text.charAt( i );
if ( check == match ) { if ( check == match ) {
count++; count++;
} }
} }
return count; return count;
} }
@ -542,7 +543,7 @@ public final class StringHelper {
// embedded within a quote-block can really be handled as two separate // embedded within a quote-block can really be handled as two separate
// quote-blocks for the purposes of this method... // quote-blocks for the purposes of this method...
int count = 0; int count = 0;
int stringLength = string.length(); final int stringLength = string.length();
boolean inQuote = false; boolean inQuote = false;
for ( int indx = 0; indx < stringLength; indx++ ) { for ( int indx = 0; indx < stringLength; indx++ ) {
char c = string.charAt( indx ); char c = string.charAt( indx );
@ -610,12 +611,14 @@ public final class StringHelper {
if ( prefix == null ) { if ( prefix == null ) {
return names; return names;
} }
int len = names.length; else {
String[] qualified = new String[len]; final int len = names.length;
for ( int i = 0; i < len; i++ ) { final String[] qualified = new String[len];
qualified[i] = qualify( prefix, names[i] ); for ( int i = 0; i < len; i++ ) {
qualified[i] = qualify( prefix, names[i] );
}
return qualified;
} }
return qualified;
} }
public static int firstIndexOfChar(String sqlString, BitSet keys, int startindex) { public static int firstIndexOfChar(String sqlString, BitSet keys, int startindex) {
@ -628,7 +631,7 @@ public final class StringHelper {
} }
public static int firstIndexOfChar(String sqlString, String string, int startindex) { public static int firstIndexOfChar(String sqlString, String string, int startindex) {
BitSet keys = new BitSet(); final BitSet keys = new BitSet();
for ( int i = 0, size = string.length(); i < size; i++ ) { for ( int i = 0, size = string.length(); i < size; i++ ) {
keys.set( string.charAt( i ) ); keys.set( string.charAt( i ) );
} }
@ -636,12 +639,7 @@ public final class StringHelper {
} }
public static String truncate(String string, int length) { public static String truncate(String string, int length) {
if ( string.length() <= length ) { return string.length() <= length ? string : string.substring( 0, length );
return string;
}
else {
return string.substring( 0, length );
}
} }
public static String generateAlias(String description) { public static String generateAlias(String description) {
@ -677,12 +675,7 @@ public final class StringHelper {
.replace( '/', '_' ) // entityNames may now include slashes for the representations .replace( '/', '_' ) // entityNames may now include slashes for the representations
.replace( '$', '_' ); //classname may be an inner class .replace( '$', '_' ); //classname may be an inner class
result = cleanAlias( result ); result = cleanAlias( result );
if ( Character.isDigit( result.charAt( result.length() - 1 ) ) ) { return isDigit( result.charAt( result.length() - 1 ) ) ? result + "x" : result; //ick!
return result + "x"; //ick!
}
else {
return result;
}
} }
/** /**
@ -694,13 +687,13 @@ public final class StringHelper {
* @return The cleaned alias, stripped of any leading non-alpha characters. * @return The cleaned alias, stripped of any leading non-alpha characters.
*/ */
private static String cleanAlias(String alias) { private static String cleanAlias(String alias) {
char[] chars = alias.toCharArray(); final char[] chars = alias.toCharArray();
// shortcut check... // shortcut check...
if ( !Character.isLetter( chars[0] ) ) { if ( !isLetter( chars[0] ) ) {
for ( int i = 1; i < chars.length; i++ ) { for ( int i = 1; i < chars.length; i++ ) {
// as soon as we encounter our first letter, return the substring // as soon as we encounter our first letter, return the substring
// from that position // from that position
if ( Character.isLetter( chars[i] ) ) { if ( isLetter( chars[i] ) ) {
return alias.substring( i ); return alias.substring( i );
} }
} }
@ -709,22 +702,9 @@ public final class StringHelper {
} }
public static String unqualifyEntityName(String entityName) { public static String unqualifyEntityName(String entityName) {
String result = unqualify( entityName ); final String result = unqualify( entityName );
int slashPos = result.indexOf( '/' ); final int slashPos = result.indexOf( '/' );
if ( slashPos > 0 ) { return slashPos > 0 ? result.substring( 0, slashPos - 1 ) : result;
result = result.substring( 0, slashPos - 1 );
}
return result;
}
public static String moveAndToBeginning(String filter) {
if ( !isBlank( filter ) ) {
filter += " and ";
if ( filter.startsWith( " and " ) ) {
filter = filter.substring( 4 );
}
}
return filter;
} }
/** /**
@ -738,11 +718,11 @@ public final class StringHelper {
if ( name == null || name.isEmpty() ) { if ( name == null || name.isEmpty() ) {
return false; return false;
} }
else {
final char first = name.charAt( 0 ); final char first = name.charAt( 0 );
final char last = name.charAt( name.length() - 1 ); final char last = name.charAt( name.length() - 1 );
return first == last && ( first == '`' || first == '"' );
return first == last && ( first == '`' || first == '"' ); }
} }
/** /**
@ -773,11 +753,12 @@ public final class StringHelper {
if ( name == null || name.isEmpty() ) { if ( name == null || name.isEmpty() ) {
return false; return false;
} }
final char first = name.charAt( 0 ); else {
final char last = name.charAt( name.length() - 1 ); final char first = name.charAt( 0 );
final char last = name.charAt( name.length() - 1 );
return ( ( first == last ) && ( first == '`' || first == '"' ) ) return first == last && ( first == '`' || first == '"' )
|| ( first == dialect.openQuote() && last == dialect.closeQuote() ); || first == dialect.openQuote() && last == dialect.closeQuote();
}
} }
/** /**
@ -836,11 +817,10 @@ public final class StringHelper {
if ( isEmpty( value ) ) { if ( isEmpty( value ) ) {
return null; return null;
} }
int index = value.indexOf( startChar ); else {
if ( index != -1 ) { final int index = value.indexOf( startChar );
return value.substring( index + 1 ); return index != -1 ? value.substring( index + 1 ) : value;
} }
return value;
} }
public static String[] splitAtCommas(String incomingString) { public static String[] splitAtCommas(String incomingString) {