Automated cleanup: suboptimal string handling (thanks IntelliJ)

This commit is contained in:
Sanne Grinovero 2023-06-20 22:15:09 +02:00 committed by Sanne Grinovero
parent 3eb7e7aea9
commit 0fb5895d08
18 changed files with 45 additions and 52 deletions

View File

@ -728,7 +728,7 @@ public class H2LegacyDialect extends Dialect {
if ( idx > 0 ) {
String constraintName = message.substring( idx + "violation: ".length() );
if ( sqle.getSQLState().equals( "23506" ) ) {
constraintName = constraintName.substring( 1, constraintName.indexOf( ":" ) );
constraintName = constraintName.substring( 1, constraintName.indexOf( ':' ) );
}
return constraintName;
}

View File

@ -677,7 +677,7 @@ public class SQLServerLegacyDialect extends AbstractTransactSQLDialect {
final StringBuilder buffer = new StringBuilder(
sql.length() + hints.length() + 12
);
final int pos = sql.indexOf( ";" );
final int pos = sql.indexOf( ';' );
if ( pos > -1 ) {
buffer.append( sql, 0, pos );
}

View File

@ -256,7 +256,7 @@ public class InferredBasicValueResolver {
if ( jdbcMapping == null ) {
throw new MappingException(
"Could not determine JavaType nor JdbcType to use" + "" +
"Could not determine JavaType nor JdbcType to use" +
" for " + ( (BasicValue) stdIndicators ).getResolvedJavaType() +
"; table = " + table.getName() +
"; column = " + selectable.getText()

View File

@ -407,7 +407,7 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr
}
else if( subPart instanceof EmbeddedAttributeMapping ){
final ModelPart subPart1 = ( (EmbeddedAttributeMapping) subPart ).findSubPart( propertyPath.substring(
propertyPath.indexOf( "." ) + 1), null );
propertyPath.indexOf( '.' ) + 1), null );
return getFetchMemento( navigablePath,subPart1 );
}
throw new UnsupportedOperationException(

View File

@ -734,7 +734,7 @@ public class H2Dialect extends Dialect {
if ( idx > 0 ) {
String constraintName = message.substring( idx + "violation: ".length() );
if ( sqle.getSQLState().equals( "23506" ) ) {
constraintName = constraintName.substring( 1, constraintName.indexOf( ":" ) );
constraintName = constraintName.substring( 1, constraintName.indexOf( ':' ) );
}
return constraintName;
}

View File

@ -405,15 +405,13 @@ public class PostgreSQLDialect extends Dialect {
separator = ",";
}
type.append( ')' );
StringBuilder cast1 = new StringBuilder();
cast1.append("create cast (varchar as " )
.append( name )
.append( ") with inout as implicit" );
StringBuilder cast2 = new StringBuilder();
cast2.append("create cast (" )
.append( name )
.append( " as varchar) with inout as implicit" );
return new String[] { type.toString(), cast1.toString(), cast2.toString() };
String cast1 = "create cast (varchar as " +
name +
") with inout as implicit";
String cast2 = "create cast (" +
name +
" as varchar) with inout as implicit";
return new String[] { type.toString(), cast1, cast2 };
}
@Override

View File

@ -670,7 +670,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
final StringBuilder buffer = new StringBuilder(
sql.length() + hints.length() + 12
);
final int pos = sql.indexOf( ";" );
final int pos = sql.indexOf( ';' );
if ( pos > -1 ) {
buffer.append( sql, 0, pos );
}

View File

@ -111,7 +111,7 @@ public class OracleAggregateSupport extends AggregateSupportImpl {
case BIGINT:
return template.replace(
placeholder,
"" + aggregateParentReadExpression + "." + column + ".number()"
aggregateParentReadExpression + "." + column + ".number()"
);
case DATE:
return template.replace(

View File

@ -34,12 +34,11 @@ public class IndexQueryHintHandler implements QueryHintHandler {
String startToken = matcher.group( 1 );
String endToken = matcher.group( 2 );
return new StringBuilder( startToken )
.append( " use index (" )
.append( hints )
.append( ") " )
.append( endToken )
.toString();
return startToken +
" use index (" +
hints +
") " +
endToken;
}
else {
return query;

View File

@ -85,7 +85,7 @@ public class Oracle12LimitHandler extends AbstractLimitHandler {
}
offsetFetchLength = sql.length() + offsetFetchString.length();
return new StringBuilder( offsetFetchLength ).append( sql ).append( offsetFetchString ).toString();
return sql + offsetFetchString;
}
protected String processSql(String sql, int forUpdateIndex, boolean hasFirstRow) {
@ -136,7 +136,7 @@ public class Oracle12LimitHandler extends AbstractLimitHandler {
private int getForUpdateIndex(String sql) {
final int forUpdateLastIndex = sql.toLowerCase( Locale.ROOT ).lastIndexOf( "for update" );
// We need to recognize cases like : select a from t where b = 'for update';
final int lastIndexOfQuote = sql.lastIndexOf( "'" );
final int lastIndexOfQuote = sql.lastIndexOf( '\'' );
if ( forUpdateLastIndex > -1 ) {
if ( lastIndexOfQuote == -1 ) {
return forUpdateLastIndex;

View File

@ -857,7 +857,7 @@ public class MappingModelCreationHelper {
}
if ( referencedPropertyName != null ) {
if ( referencedPropertyName.indexOf( "." ) > 0 ) {
if ( referencedPropertyName.indexOf( '.' ) > 0 ) {
return interpretNestedToOneKeyDescriptor(
referencedEntityDescriptor,
referencedPropertyName,

View File

@ -172,7 +172,7 @@ public class StandardHqlTranslator implements HqlTranslator {
errorText += ", ";
}
if ( e instanceof NoViableAltException ) {
errorText += message.substring( 0, message.indexOf("'") );
errorText += message.substring( 0, message.indexOf( '\'' ) );
if ( hql.isEmpty() ) {
errorText += "'*' (empty query string)";
}

View File

@ -130,12 +130,10 @@ public final class Template {
// which the tokens occur. Depending on the state of those flags we decide whether we need to qualify
// identifier references.
String symbols = new StringBuilder()
.append( PUNCTUATION )
.append( WHITESPACE )
.append( dialect.openQuote() )
.append( dialect.closeQuote() )
.toString();
String symbols = PUNCTUATION +
WHITESPACE +
dialect.openQuote() +
dialect.closeQuote();
StringTokenizer tokens = new StringTokenizer( sqlWhereString, symbols, true );
StringBuilder result = new StringBuilder();

View File

@ -8186,7 +8186,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
int lastEnd = 0;
for ( ColumnValueParameter parameter : columnWriteFragment.getParameters() ) {
final int markerStart = sqlFragment.indexOf( "?", lastEnd );
final int markerStart = sqlFragment.indexOf( '?', lastEnd );
// append the part of the fragment from the last-end position (start of string for first pass)
// to the index of the parameter marker

View File

@ -87,15 +87,15 @@ public class CacheRegionStatisticsImpl implements CacheRegionStatistics, Seriali
@Override
public String toString() {
StringBuilder buf = new StringBuilder().append( "CacheRegionStatistics" )
.append( "[region=").append( region.getName() )
.append( ",hitCount=").append( this.hitCount )
.append( ",missCount=").append( this.missCount )
.append( ",putCount=").append( this.putCount )
.append( ",elementCountInMemory=" ).append( this.getElementCountInMemory() )
.append( ",elementCountOnDisk=" ).append( this.getElementCountOnDisk() )
.append( ",sizeInMemory=" ).append( this.getSizeInMemory() )
.append( ']' );
return buf.toString();
String buf = "CacheRegionStatistics" +
"[region=" + region.getName() +
",hitCount=" + this.hitCount +
",missCount=" + this.missCount +
",putCount=" + this.putCount +
",elementCountInMemory=" + this.getElementCountInMemory() +
",elementCountOnDisk=" + this.getElementCountOnDisk() +
",sizeInMemory=" + this.getSizeInMemory() +
']';
return buf;
}
}

View File

@ -40,12 +40,10 @@ public class SessionStatisticsImpl implements SessionStatistics {
}
public String toString() {
return new StringBuilder()
.append("SessionStatistics[")
.append("entity count=").append( getEntityCount() )
.append(",collection count=").append( getCollectionCount() )
.append(']')
.toString();
return "SessionStatistics[" +
"entity count=" + getEntityCount() +
",collection count=" + getCollectionCount() +
']';
}
}

View File

@ -32,7 +32,7 @@ public abstract class StringTools {
if ( s == null ) {
return null;
}
final int lastDot = s.lastIndexOf( "." );
final int lastDot = s.lastIndexOf( '.' );
if ( lastDot == -1 ) {
return s;
}

View File

@ -127,7 +127,7 @@ public class ImportContextImpl implements ImportContext {
}
private boolean inDefaultPackage(String className) {
return className.indexOf( "." ) < 0;
return className.indexOf( '.' ) < 0;
}
private boolean isPrimitive(String className) {
@ -175,7 +175,7 @@ public class ImportContextImpl implements ImportContext {
}
public static String qualifier(String qualifiedName) {
int loc = qualifiedName.lastIndexOf( "." );
int loc = qualifiedName.lastIndexOf( '.' );
return ( loc < 0 ) ? "" : qualifiedName.substring( 0, loc );
}
}