From 312283cb0ed9d97bf5f935446d49d8836eb33604 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 | 11 ++++------ 2 files changed, 13 insertions(+), 19 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 86d9a9bbc5..67696f79a4 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 @@ -65,19 +65,19 @@ public class LocaleTypeDescriptor extends AbstractTypeDescriptor { 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 { } } - 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 0c1da5b205..411203b958 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,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.