HHH-8491 formatting and improved readability
This commit is contained in:
parent
d224991d1b
commit
312283cb0e
|
@ -65,19 +65,19 @@ public class LocaleTypeDescriptor extends AbstractTypeDescriptor<Locale> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int found = 0, position = 0;
|
boolean separatorFound = false;
|
||||||
|
int position = 0;
|
||||||
char[] chars = string.toCharArray();
|
char[] chars = string.toCharArray();
|
||||||
|
|
||||||
for ( int i = 0; i < chars.length; i++ ) {
|
for ( int i = 0; i < chars.length; i++ ) {
|
||||||
// We just look for separators
|
// We just look for separators
|
||||||
if ( chars[i] == '_' ) {
|
if ( chars[i] == '_' ) {
|
||||||
switch ( found ) {
|
if ( !separatorFound ) {
|
||||||
case 0:
|
|
||||||
// On the first separator we know that we have at least a language
|
// On the first separator we know that we have at least a language
|
||||||
string = new String( chars, position, i - position );
|
string = new String( chars, position, i - position );
|
||||||
position = i + 1;
|
position = i + 1;
|
||||||
break;
|
}
|
||||||
case 1:
|
else {
|
||||||
// On the second separator we have to check whether there are more chars available for variant
|
// On the second separator we have to check whether there are more chars available for variant
|
||||||
if ( chars.length > i + 1 ) {
|
if ( chars.length > i + 1 ) {
|
||||||
// There is a variant so add it to the constructor
|
// There is a variant so add it to the constructor
|
||||||
|
@ -90,21 +90,18 @@ public class LocaleTypeDescriptor extends AbstractTypeDescriptor<Locale> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
found++;
|
separatorFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( found ) {
|
if ( !separatorFound ) {
|
||||||
case 0:
|
|
||||||
// No separator found, there is only a language
|
// No separator found, there is only a language
|
||||||
return new Locale( string );
|
return new Locale( string );
|
||||||
case 1:
|
}
|
||||||
|
else {
|
||||||
// Only one separator found, there is a language and a country
|
// Only one separator found, there is a language and a country
|
||||||
return new Locale( string, new String( chars, position, chars.length - position ) );
|
return new Locale( string, new String( chars, position, chars.length - position ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should never happen
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked" })
|
@SuppressWarnings({ "unchecked" })
|
||||||
|
|
|
@ -23,17 +23,14 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.type.descriptor.java;
|
package org.hibernate.test.type.descriptor.java;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.type.descriptor.java.LocaleTypeDescriptor;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
import org.hibernate.type.descriptor.java.LocaleTypeDescriptor;
|
||||||
import static org.junit.Assert.assertEquals;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the {@link LocaleTypeDescriptor} class.
|
* Tests of the {@link LocaleTypeDescriptor} class.
|
||||||
|
|
Loading…
Reference in New Issue