Updated Branches:
  refs/heads/master fa2be0f06 -> 61122bab2

WICKET-5359 fixed equals for different locales

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/61122bab
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/61122bab
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/61122bab

Branch: refs/heads/master
Commit: 61122bab26db4ae3ad651f8d9794f4e0e865e6e2
Parents: fa2be0f
Author: svenmeier <[email protected]>
Authored: Fri Sep 20 21:10:46 2013 +0200
Committer: svenmeier <[email protected]>
Committed: Fri Sep 20 21:10:46 2013 +0200

----------------------------------------------------------------------
 .../apache/wicket/util/string/StringValue.java  | 102 ++++++++++---------
 .../wicket/util/string/StringValueTest.java     |  32 ++++--
 2 files changed, 81 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/61122bab/wicket-util/src/main/java/org/apache/wicket/util/string/StringValue.java
----------------------------------------------------------------------
diff --git 
a/wicket-util/src/main/java/org/apache/wicket/util/string/StringValue.java 
b/wicket-util/src/main/java/org/apache/wicket/util/string/StringValue.java
index fa5bbbd..2887f95 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/string/StringValue.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/string/StringValue.java
@@ -318,56 +318,56 @@ public class StringValue implements IClusterable
 
                if (type == String.class)
                {
-                       return (T) toString();
+                       return (T)toString();
                }
 
                if ((type == Integer.TYPE) || (type == Integer.class))
                {
-                       return (T) toInteger();
+                       return (T)toInteger();
                }
 
                if ((type == Long.TYPE) || (type == Long.class))
                {
-                       return (T) toLongObject();
+                       return (T)toLongObject();
                }
 
                if ((type == Boolean.TYPE) || (type == Boolean.class))
                {
-                       return (T) toBooleanObject();
+                       return (T)toBooleanObject();
                }
 
                if ((type == Double.TYPE) || (type == Double.class))
                {
-                       return (T) toDoubleObject();
+                       return (T)toDoubleObject();
                }
 
                if ((type == Character.TYPE) || (type == Character.class))
                {
-                       return (T) toCharacter();
+                       return (T)toCharacter();
                }
 
                if (type == Time.class)
                {
-                       return (T) toTime();
+                       return (T)toTime();
                }
 
                if (type == Duration.class)
                {
-                       return (T) toDuration();
+                       return (T)toDuration();
                }
 
                if (type.isEnum())
                {
-                       return (T) toEnum((Class) type);
+                       return (T)toEnum((Class)type);
                }
 
-               throw new StringValueConversionException("Cannot convert '" + 
toString() + "'to type " +
-                       type);
+               throw new StringValueConversionException("Cannot convert '" + 
toString() + "'to type "
+                       + type);
        }
 
        /**
         * Converts this StringValue to a given type or {@code null} if the 
value is empty.
-        *
+        * 
         * @param type
         *            The type to convert to
         * @return The converted value
@@ -377,7 +377,7 @@ public class StringValue implements IClusterable
        {
                return Strings.isEmpty(text) ? null : to(type);
        }
-       
+
        /**
         * Convert this text to a boolean.
         * 
@@ -394,8 +394,9 @@ public class StringValue implements IClusterable
         * 
         * @param defaultValue
         *            the default value
-        * @return the converted text as a boolean or the default value if text 
is empty or inconvertible
-        * @see Strings#isTrue(String) 
+        * @return the converted text as a boolean or the default value if text 
is empty or
+        *         inconvertible
+        * @see Strings#isTrue(String)
         */
        public final boolean toBoolean(final boolean defaultValue)
        {
@@ -410,7 +411,8 @@ public class StringValue implements IClusterable
                                if (LOG.isDebugEnabled())
                                {
                                        LOG.debug(String.format(
-                                               "An error occurred while 
converting '%s' to a boolean: %s", text, x.getMessage()), x);
+                                               "An error occurred while 
converting '%s' to a boolean: %s", text,
+                                               x.getMessage()), x);
                                }
                        }
                }
@@ -444,7 +446,8 @@ public class StringValue implements IClusterable
         * 
         * @param defaultValue
         *            the default value
-        * @return the converted text as a primitive char or the default value 
if text is not a single character
+        * @return the converted text as a primitive char or the default value 
if text is not a single
+        *         character
         */
        public final char toChar(final char defaultValue)
        {
@@ -459,7 +462,8 @@ public class StringValue implements IClusterable
                                if (LOG.isDebugEnabled())
                                {
                                        LOG.debug(String.format(
-                                               "An error occurred while 
converting '%s' to a character: %s", text, x.getMessage()), x);
+                                               "An error occurred while 
converting '%s' to a character: %s", text,
+                                               x.getMessage()), x);
                                }
                        }
                }
@@ -491,8 +495,8 @@ public class StringValue implements IClusterable
                }
                catch (ParseException e)
                {
-                       throw new StringValueConversionException("Unable to 
convert '" + text +
-                               "' to a double value", e);
+                       throw new StringValueConversionException("Unable to 
convert '" + text
+                               + "' to a double value", e);
                }
        }
 
@@ -516,7 +520,8 @@ public class StringValue implements IClusterable
                                if (LOG.isDebugEnabled())
                                {
                                        LOG.debug(String.format(
-                                               "An error occurred while 
converting '%s' to a double: %s", text, x.getMessage()), x);
+                                               "An error occurred while 
converting '%s' to a double: %s", text,
+                                               x.getMessage()), x);
                                }
                        }
                }
@@ -539,7 +544,7 @@ public class StringValue implements IClusterable
         * 
         * @return Converted text
         * @throws StringValueConversionException
-        * @see Duration#valueOf(String, java.util.Locale) 
+        * @see Duration#valueOf(String, java.util.Locale)
         */
        public final Duration toDuration() throws StringValueConversionException
        {
@@ -551,8 +556,9 @@ public class StringValue implements IClusterable
         * 
         * @param defaultValue
         *            the default value
-        * @return the converted text as a duration or the default value if 
text is empty or inconvertible
-        * @see Duration#valueOf(String, java.util.Locale) 
+        * @return the converted text as a duration or the default value if 
text is empty or
+        *         inconvertible
+        * @see Duration#valueOf(String, java.util.Locale)
         */
        public final Duration toDuration(final Duration defaultValue)
        {
@@ -567,7 +573,8 @@ public class StringValue implements IClusterable
                                if (LOG.isDebugEnabled())
                                {
                                        LOG.debug(String.format(
-                                               "An error occurred while 
converting '%s' to a Duration: %s", text, x.getMessage()), x);
+                                               "An error occurred while 
converting '%s' to a Duration: %s", text,
+                                               x.getMessage()), x);
                                }
                        }
                }
@@ -588,8 +595,8 @@ public class StringValue implements IClusterable
                }
                catch (NumberFormatException e)
                {
-                       throw new StringValueConversionException("Unable to 
convert '" + text +
-                               "' to an int value", e);
+                       throw new StringValueConversionException("Unable to 
convert '" + text
+                               + "' to an int value", e);
                }
        }
 
@@ -613,7 +620,8 @@ public class StringValue implements IClusterable
                                if (LOG.isDebugEnabled())
                                {
                                        LOG.debug(String.format(
-                                               "An error occurred while 
converting '%s' to an integer: %s", text, x.getMessage()), x);
+                                               "An error occurred while 
converting '%s' to an integer: %s", text,
+                                               x.getMessage()), x);
                                }
                        }
                }
@@ -634,8 +642,8 @@ public class StringValue implements IClusterable
                }
                catch (NumberFormatException e)
                {
-                       throw new StringValueConversionException("Unable to 
convert '" + text +
-                               "' to an Integer value", e);
+                       throw new StringValueConversionException("Unable to 
convert '" + text
+                               + "' to an Integer value", e);
                }
        }
 
@@ -653,8 +661,8 @@ public class StringValue implements IClusterable
                }
                catch (NumberFormatException e)
                {
-                       throw new StringValueConversionException("Unable to 
convert '" + text +
-                               "' to a long value", e);
+                       throw new StringValueConversionException("Unable to 
convert '" + text
+                               + "' to a long value", e);
                }
        }
 
@@ -663,7 +671,8 @@ public class StringValue implements IClusterable
         * 
         * @param defaultValue
         *            the default value
-        * @return the converted text as a long integer or the default value if 
text is empty or inconvertible
+        * @return the converted text as a long integer or the default value if 
text is empty or
+        *         inconvertible
         */
        public final long toLong(final long defaultValue)
        {
@@ -678,7 +687,8 @@ public class StringValue implements IClusterable
                                if (LOG.isDebugEnabled())
                                {
                                        LOG.debug(String.format(
-                                               "An error occurred while 
converting '%s' to a long: %s", text, x.getMessage()), x);
+                                               "An error occurred while 
converting '%s' to a long: %s", text,
+                                               x.getMessage()), x);
                                }
                        }
                }
@@ -699,8 +709,8 @@ public class StringValue implements IClusterable
                }
                catch (NumberFormatException e)
                {
-                       throw new StringValueConversionException("Unable to 
convert '" + text +
-                               "' to a Long value", e);
+                       throw new StringValueConversionException("Unable to 
convert '" + text
+                               + "' to a Long value", e);
                }
        }
 
@@ -826,8 +836,8 @@ public class StringValue implements IClusterable
                }
                catch (ParseException e)
                {
-                       throw new StringValueConversionException("Unable to 
convert '" + text +
-                               "' to a Time value", e);
+                       throw new StringValueConversionException("Unable to 
convert '" + text
+                               + "' to a Time value", e);
                }
        }
 
@@ -851,7 +861,8 @@ public class StringValue implements IClusterable
                                if (LOG.isDebugEnabled())
                                {
                                        LOG.debug(String.format(
-                                               "An error occurred while 
converting '%s' to a Time: %s", text, x.getMessage()), x);
+                                               "An error occurred while 
converting '%s' to a Time: %s", text,
+                                               x.getMessage()), x);
                                }
                        }
                }
@@ -860,7 +871,7 @@ public class StringValue implements IClusterable
 
        /**
         * Convert this text to an enum.
-        *
+        * 
         * @param eClass
         *            enum type
         * @return The value as an enum
@@ -874,7 +885,7 @@ public class StringValue implements IClusterable
 
        /**
         * Convert this text to an enum.
-        *
+        * 
         * @param defaultValue
         *            This will be returned if there is an error converting the 
value
         * @return The value as an enum
@@ -887,7 +898,7 @@ public class StringValue implements IClusterable
 
        /**
         * Convert this text to an enum.
-        *
+        * 
         * @param eClass
         *            enum type
         * @param defaultValue
@@ -916,10 +927,10 @@ public class StringValue implements IClusterable
 
        /**
         * Convert to enum, returning null if text is null or empty.
-        *
+        * 
         * @param eClass
         *            enum type
-        *
+        * 
         * @return converted
         * @throws StringValueConversionException
         */
@@ -968,8 +979,7 @@ public class StringValue implements IClusterable
                if (obj instanceof StringValue)
                {
                        StringValue stringValue = (StringValue)obj;
-                       return Objects.isEqual(text, stringValue.text) &&
-                               Objects.isEqual(locale, stringValue.locale);
+                       return Objects.isEqual(text, stringValue.text) && 
locale.equals(stringValue.locale);
                }
                else
                {

http://git-wip-us.apache.org/repos/asf/wicket/blob/61122bab/wicket-util/src/test/java/org/apache/wicket/util/string/StringValueTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-util/src/test/java/org/apache/wicket/util/string/StringValueTest.java 
b/wicket-util/src/test/java/org/apache/wicket/util/string/StringValueTest.java
index ef32462..4f0a60b 100644
--- 
a/wicket-util/src/test/java/org/apache/wicket/util/string/StringValueTest.java
+++ 
b/wicket-util/src/test/java/org/apache/wicket/util/string/StringValueTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.wicket.util.string;
 
+import java.util.Locale;
+
 import org.apache.wicket.util.time.Duration;
 import org.apache.wicket.util.time.Time;
 import org.junit.Assert;
@@ -27,6 +29,20 @@ import org.junit.Test;
 public class StringValueTest extends Assert
 {
        /**
+        * WICKET-5359 equals
+        */
+       @Test
+       public void equals()
+       {
+               assertFalse(StringValue.valueOf("bla", Locale.FRANCE).equals(
+                       StringValue.valueOf("bla", Locale.CANADA)));
+               assertTrue(StringValue.valueOf("bla", Locale.FRANCE).equals(
+                       StringValue.valueOf("bla", Locale.FRANCE)));
+               assertFalse(StringValue.valueOf("bla", Locale.FRANCE).equals(
+                       StringValue.valueOf("blo", Locale.FRANCE)));
+       }
+
+       /**
         * https://issues.apache.org/jira/browse/WICKET-4309
         */
        @Test
@@ -67,10 +83,10 @@ public class StringValueTest extends Assert
        public void defaultValues()
        {
                StringValue sv = new StringValue("unknown");
-               
+
                assertTrue(sv.toBoolean(true));
                assertFalse(sv.toBoolean(false));
-               
+
                assertEquals(4, sv.toInt(4));
                assertEquals(4.0, sv.toDouble(4.0), 0.005);
                assertEquals('c', sv.toChar('c'));
@@ -80,26 +96,28 @@ public class StringValueTest extends Assert
 
                assertEquals("unknown", sv.toString("def"));
        }
+
        @Test
        public void toType()
        {
                StringValue sv = new StringValue("4");
-               
+
                assertEquals(Long.valueOf(4), sv.to(Long.class));
                assertEquals(Integer.valueOf(4), sv.to(Integer.class));
                assertEquals(Double.valueOf(4), sv.to(Double.class));
                assertEquals(Character.valueOf('4'), sv.to(Character.class));
                assertEquals("4", sv.to(String.class));
-               
+
                try
                {
                        sv.to(String[].class);
                        fail("Should not be able to convert to unsupported 
type!");
-               } catch (StringValueConversionException svcx)
+               }
+               catch (StringValueConversionException svcx)
                {
                        assertTrue(true);
                }
-               
+
                sv = new StringValue(null);
                assertNull(sv.toOptional(String.class));
                assertNull(sv.toOptional(String[].class));
@@ -107,7 +125,7 @@ public class StringValueTest extends Assert
                sv = new StringValue("");
                assertNull(sv.toOptional(String.class));
                assertNull(sv.toOptional(String[].class));
-    }
+       }
 
        static enum TestEnum {
                FOO, BAR, BAZ

Reply via email to