Skip to content

Commit 277abdf

Browse files
committed
minor code cleanups to Identifier
1 parent 0d322a6 commit 277abdf

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/naming/DatabaseIdentifier.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
package org.hibernate.boot.model.naming;
66

7-
import org.hibernate.internal.util.StringHelper;
7+
import static org.hibernate.internal.util.StringHelper.isEmpty;
88

99
/**
1010
* Models an identifier (name), retrieved from the database.
@@ -24,13 +24,13 @@ protected DatabaseIdentifier(String text) {
2424
}
2525

2626
public static DatabaseIdentifier toIdentifier(String text) {
27-
if ( StringHelper.isEmpty( text ) ) {
27+
if ( isEmpty( text ) ) {
2828
return null;
2929
}
3030
else if ( isQuoted( text ) ) {
3131
// exclude the quotes from text
32-
final String unquotedtext = text.substring( 1, text.length() - 1 );
33-
return new DatabaseIdentifier( unquotedtext );
32+
final String unquoted = text.substring( 1, text.length() - 1 );
33+
return new DatabaseIdentifier( unquoted );
3434
}
3535
else {
3636
return new DatabaseIdentifier( text );

hibernate-core/src/main/java/org/hibernate/boot/model/naming/Identifier.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import java.util.Locale;
88

99
import org.hibernate.dialect.Dialect;
10-
import org.hibernate.internal.util.StringHelper;
1110

11+
import static java.lang.Character.isLetter;
12+
import static java.lang.Character.isLetterOrDigit;
13+
import static java.lang.Character.isWhitespace;
1214
import static org.hibernate.internal.util.StringHelper.isBlank;
15+
import static org.hibernate.internal.util.StringHelper.isEmpty;
1316

1417
/**
1518
* Models an identifier (name), which may or may not be quoted.
@@ -83,13 +86,13 @@ public static Identifier toIdentifier(String text, boolean quote, boolean quoteO
8386
int start = 0;
8487
int end = text.length();
8588
while ( start < end ) {
86-
if ( !Character.isWhitespace( text.charAt( start ) ) ) {
89+
if ( !isWhitespace( text.charAt( start ) ) ) {
8790
break;
8891
}
8992
start++;
9093
}
9194
while ( start < end ) {
92-
if ( !Character.isWhitespace( text.charAt( end - 1 ) ) ) {
95+
if ( !isWhitespace( text.charAt( end - 1 ) ) ) {
9396
break;
9497
}
9598
end--;
@@ -102,14 +105,14 @@ public static Identifier toIdentifier(String text, boolean quote, boolean quoteO
102105
else if ( quoteOnNonIdentifierChar && !quote ) {
103106
// Check the letters to determine if we must quote the text
104107
char c = text.charAt( start );
105-
if ( !Character.isLetter( c ) && c != '_' ) {
108+
if ( !isLetter( c ) && c != '_' ) {
106109
// SQL identifiers must begin with a letter or underscore
107110
quote = true;
108111
}
109112
else {
110113
for ( int i = start + 1; i < end; i++ ) {
111114
c = text.charAt( i );
112-
if ( !Character.isLetterOrDigit( c ) && c != '_' ) {
115+
if ( !isLetterOrDigit( c ) && c != '_' ) {
113116
quote = true;
114117
break;
115118
}
@@ -163,7 +166,7 @@ public static String unQuote(String name) {
163166
* @param quoted Is this a quoted identifier?
164167
*/
165168
public Identifier(String text, boolean quoted) {
166-
if ( StringHelper.isEmpty( text ) ) {
169+
if ( isEmpty( text ) ) {
167170
throw new IllegalIdentifierException( "Identifier text cannot be null" );
168171
}
169172
if ( isQuoted( text ) ) {
@@ -234,11 +237,9 @@ public String toString() {
234237

235238
@Override
236239
public boolean equals(Object o) {
237-
if ( !(o instanceof Identifier) ) {
240+
if ( !(o instanceof Identifier that) ) {
238241
return false;
239242
}
240-
241-
final Identifier that = (Identifier) o;
242243
return getCanonicalName().equals( that.getCanonicalName() );
243244
}
244245

0 commit comments

Comments
 (0)