Skip to content

Commit 312283c

Browse files
committed
HHH-8491 formatting and improved readability
1 parent d224991 commit 312283c

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ public Locale fromString(String string) {
6565
return null;
6666
}
6767

68-
int found = 0, position = 0;
68+
boolean separatorFound = false;
69+
int position = 0;
6970
char[] chars = string.toCharArray();
7071

7172
for ( int i = 0; i < chars.length; i++ ) {
7273
// We just look for separators
7374
if ( chars[i] == '_' ) {
74-
switch ( found ) {
75-
case 0:
75+
if ( !separatorFound ) {
7676
// On the first separator we know that we have at least a language
7777
string = new String( chars, position, i - position );
7878
position = i + 1;
79-
break;
80-
case 1:
79+
}
80+
else {
8181
// On the second separator we have to check whether there are more chars available for variant
8282
if ( chars.length > i + 1 ) {
8383
// There is a variant so add it to the constructor
@@ -90,21 +90,18 @@ public Locale fromString(String string) {
9090
}
9191
}
9292

93-
found++;
93+
separatorFound = true;
9494
}
9595
}
9696

97-
switch ( found ) {
98-
case 0:
97+
if ( !separatorFound ) {
9998
// No separator found, there is only a language
10099
return new Locale( string );
101-
case 1:
100+
}
101+
else {
102102
// Only one separator found, there is a language and a country
103103
return new Locale( string, new String( chars, position, chars.length - position ) );
104104
}
105-
106-
// Should never happen
107-
return null;
108105
}
109106

110107
@SuppressWarnings({ "unchecked" })

hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/LocaleTypeDescriptorTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@
2323
*/
2424
package org.hibernate.test.type.descriptor.java;
2525

26+
import static org.junit.Assert.assertEquals;
27+
2628
import java.util.Locale;
27-
import java.util.StringTokenizer;
2829

2930
import org.hibernate.internal.util.StringHelper;
31+
import org.hibernate.testing.junit4.BaseUnitTestCase;
3032
import org.hibernate.type.descriptor.java.LocaleTypeDescriptor;
31-
3233
import org.junit.Test;
3334

34-
import org.hibernate.testing.junit4.BaseUnitTestCase;
35-
36-
import static org.junit.Assert.assertEquals;
37-
3835
/**
3936
* Tests of the {@link LocaleTypeDescriptor} class.
4037
*

0 commit comments

Comments
 (0)