HHH-8491 formatting and improved readability

This commit is contained in:
Brett Meyer 2013-09-11 15:46:02 -04:00
parent d224991d1b
commit 312283cb0e
2 changed files with 13 additions and 19 deletions

View File

@ -65,19 +65,19 @@ public class LocaleTypeDescriptor extends AbstractTypeDescriptor<Locale> {
return null;
}
int found = 0, position = 0;
boolean separatorFound = false;
int position = 0;
char[] chars = string.toCharArray();
for ( int i = 0; i < chars.length; i++ ) {
// We just look for separators
if ( chars[i] == '_' ) {
switch ( found ) {
case 0:
if ( !separatorFound ) {
// On the first separator we know that we have at least a language
string = new String( chars, position, i - position );
position = i + 1;
break;
case 1:
}
else {
// On the second separator we have to check whether there are more chars available for variant
if ( chars.length > i + 1 ) {
// 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 ) {
case 0:
if ( !separatorFound ) {
// No separator found, there is only a language
return new Locale( string );
case 1:
}
else {
// Only one separator found, there is a language and a country
return new Locale( string, new String( chars, position, chars.length - position ) );
}
// Should never happen
return null;
}
@SuppressWarnings({ "unchecked" })

View File

@ -23,17 +23,14 @@
*/
package org.hibernate.test.type.descriptor.java;
import static org.junit.Assert.assertEquals;
import java.util.Locale;
import java.util.StringTokenizer;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.type.descriptor.java.LocaleTypeDescriptor;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
import org.hibernate.type.descriptor.java.LocaleTypeDescriptor;
import org.junit.Test;
/**
* Tests of the {@link LocaleTypeDescriptor} class.