Author: chris.laprun(a)jboss.com
Date: 2006-12-27 21:35:15 -0500 (Wed, 27 Dec 2006)
New Revision: 5936
Modified:
trunk/common/src/main/org/jboss/portal/common/util/LocalizedString.java
Log:
Added equals and hashCode methods (minimally tested).
Modified: trunk/common/src/main/org/jboss/portal/common/util/LocalizedString.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/LocalizedString.java 2006-12-27
01:02:13 UTC (rev 5935)
+++ trunk/common/src/main/org/jboss/portal/common/util/LocalizedString.java 2006-12-28
02:35:15 UTC (rev 5936)
@@ -24,11 +24,11 @@
import org.jboss.logging.Logger;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
-import java.util.Collections;
/**
* An immutable localized string.
@@ -52,7 +52,7 @@
/**
* Convenience constructor for simple localized strings with only one value using the
default locale.
*
- * @param defaultValue the localized value using the specified default locale
+ * @param defaultValue the localized value using the specified default locale
* @param defaultLocale the default locale
* @since 2.4
*/
@@ -229,9 +229,7 @@
}
}
- /**
- * Return the default locale of this description.
- */
+ /** Return the default locale of this description. */
public Locale getDefaultLocale()
{
return defaultLocale;
@@ -240,12 +238,11 @@
/**
* Retrieves the localized value most appropriate based on the given desired locales.
*
- * @param desiredLocales an array of compound language tags (as defined by
- * <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC 3066</a>) ordered
according to
- * locale preferences.
+ * @param desiredLocales an array of compound language tags (as defined by <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF
+ * RFC 3066</a>) ordered according to locale preferences.
* @return the most appropriate localized value based on locale preferences.
- * @throws IllegalArgumentException if the array is null or one of the array string
- * is null or invalid (see
#getLocaleFromRFC3066LanguageTag(String))
+ * @throws IllegalArgumentException if the array is null or one of the array string is
null or invalid (see
+ * #getLocaleFromRFC3066LanguageTag(String))
* @since 2.4
*/
public String getMostAppropriateValueFor(String[] desiredLocales) throws
IllegalArgumentException
@@ -258,13 +255,12 @@
* Retrieves the Locale-String mapping most appropriate based on the given desired
locales, which are ordered
* according to locale preferences.
*
- * @param desiredLocales an array of compound language tags (as defined by
- * <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF RFC 3066</a>) ordered
according to
- * locale preferences.
- * @return a Map.Entry representing the most appropriate mapping between Locale and
- * localized value, based on locale preferences.
- * @throws IllegalArgumentException if the array is null or one of the array string
- * is null or invalid (see {@link
LocaleInfo#decodeLocaleInfoFromRFC3066LanguageTag(String)}
+ * @param desiredLocales an array of compound language tags (as defined by <a
href="http://www.ietf.org/rfc/rfc3066.txt">IETF
+ * RFC 3066</a>) ordered according to locale preferences.
+ * @return a Map.Entry representing the most appropriate mapping between Locale and
localized value, based on locale
+ * preferences.
+ * @throws IllegalArgumentException if the array is null or one of the array string is
null or invalid (see {@link
+ *
LocaleInfo#decodeLocaleInfoFromRFC3066LanguageTag(String)}
* @since 2.4
*/
public Value getPreferredOrBestLocalizedMappingFor(String[] desiredLocales) throws
IllegalArgumentException
@@ -323,9 +319,7 @@
return value;
}
- /**
- * A localized value.
- */
+ /** A localized value. */
public static class Value
{
@@ -357,4 +351,30 @@
{
return "LocalizedString: '" + getMostAppropriateValueFor(new
String[0]) + "' default: " + getDefaultLocale();
}
+
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ LocalizedString that = (LocalizedString)o;
+
+ return getMostAppropriateValueFor(new
String[0]).equals(that.getMostAppropriateValueFor(new String[0]))
+ && defaultLocale.equals(that.defaultLocale);
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = getMostAppropriateValueFor(new String[0]).hashCode();
+ result = 31 * result + defaultLocale.hashCode();
+ return result;
+ }
}