Skip to content

Commit

Permalink
HHH-8491 formatting and improved readability
Browse files Browse the repository at this point in the history
  • Loading branch information
brmeyer committed Sep 11, 2013
1 parent 97854f1 commit 82aef14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Expand Up @@ -64,19 +64,19 @@ public Locale fromString(String string) {
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
Expand All @@ -89,21 +89,18 @@ public Locale fromString(String string) {
}
}

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" })
Expand Down
Expand Up @@ -23,18 +23,15 @@
*/
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.testing.junit4.BaseUnitTestCase;
import org.hibernate.type.descriptor.java.LocaleTypeDescriptor;

import org.junit.Test;

import org.hibernate.testing.junit4.BaseUnitTestCase;

import static org.junit.Assert.assertEquals;

/**
* Tests of the {@link LocaleTypeDescriptor} class.
*
Expand Down

0 comments on commit 82aef14

Please sign in to comment.