Updated Branches: refs/heads/wicket-6.x abd0bc5db -> 556587dfe
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/556587df Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/556587df Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/556587df Branch: refs/heads/wicket-6.x Commit: 556587dfe5ebaf9499812fe08f273e7f75c56da4 Parents: abd0bc5 Author: svenmeier <[email protected]> Authored: Fri Sep 20 21:11:09 2013 +0200 Committer: svenmeier <[email protected]> Committed: Fri Sep 20 21:11:09 2013 +0200 ---------------------------------------------------------------------- .../apache/wicket/util/string/StringValue.java | 74 +++++++++++--------- .../wicket/util/string/StringValueTest.java | 32 +++++++-- 2 files changed, 67 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/556587df/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..ae07c68 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,47 +318,47 @@ 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 " + @@ -367,7 +367,7 @@ public class StringValue implements IClusterable /** * 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); } } } @@ -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); } } } @@ -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); } } } @@ -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); } } } @@ -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/556587df/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
