From 82aef14e0706c2a44065c8426c259eb02e7f7434 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Wed, 11 Sep 2013 15:46:02 -0400 Subject: [PATCH] HHH-8491 formatting and improved readability --- .../descriptor/java/LocaleTypeDescriptor.java | 21 ++++++++----------- .../java/LocaleTypeDescriptorTest.java | 9 +++----- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java index 60f0281c60c7..dbf1213fd508 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java @@ -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 @@ -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" }) diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/LocaleTypeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/LocaleTypeDescriptorTest.java index 0c1da5b20530..411203b9582b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/LocaleTypeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/descriptor/java/LocaleTypeDescriptorTest.java @@ -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. *