org.geotools.util
Class GrowableInternationalString

java.lang.Object
  extended byorg.geotools.util.AbstractInternationalString
      extended byorg.geotools.util.GrowableInternationalString
All Implemented Interfaces:
java.lang.CharSequence, java.lang.Comparable, org.opengis.util.InternationalString, java.io.Serializable

public class GrowableInternationalString
extends AbstractInternationalString
implements java.io.Serializable

An implementation of international string using a map of strings for different locales. Strings for new locales can be added, but existing strings can't be removed or modified. This behavior is a compromise between making constructionss easier, and being suitable for use in immutable objects.

Since:
2.1
Version:
$Id: GrowableInternationalString.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Serialized Form

Constructor Summary
GrowableInternationalString()
          Constructs an initially empty international string.
GrowableInternationalString(java.lang.String string)
          Constructs an international string initialized with the specified string.
 
Method Summary
 void add(java.util.Locale locale, java.lang.String string)
          Add a string for the given locale.
 boolean add(java.lang.String prefix, java.lang.String key, java.lang.String string)
          Add a string for the given property key.
 boolean equals(java.lang.Object object)
          Compares this international string with the specified object for equality.
 java.util.Set getLocales()
          Returns the set of locales defined in this international string.
 int hashCode()
          Returns a hash code value for this international text.
 java.lang.String toString(java.util.Locale locale)
          Returns a string in the specified locale.
 
Methods inherited from class org.geotools.util.AbstractInternationalString
charAt, compareTo, length, subSequence, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GrowableInternationalString

public GrowableInternationalString()
Constructs an initially empty international string. Localized strings can been added using one of add(...) methods.


GrowableInternationalString

public GrowableInternationalString(java.lang.String string)
Constructs an international string initialized with the specified string. Additional localized strings can been added using one of add(...) methods. The string specified to this constructor is the one that will be returned if no localized string is found for the Locale argument in a call to toString(Locale).

Parameters:
string - The string in no specific locale.
Method Detail

add

public void add(java.util.Locale locale,
                java.lang.String string)
         throws java.lang.IllegalArgumentException
Add a string for the given locale.

Parameters:
locale - The locale for the value, or .
string - The localized string.
Throws:
java.lang.IllegalArgumentException - if a different string value was already set for the given locale.

add

public boolean add(java.lang.String prefix,
                   java.lang.String key,
                   java.lang.String string)
            throws java.lang.IllegalArgumentException
Add a string for the given property key. This is a convenience method for constructing an during iteration through the entries in a Map. It infers the Locale from the property , using the following steps:

For example if the prefix is "remarks", then the "remarks_fr" property key stands for remarks in French while the "remarks_fr_CA" property key stands for remarks in French Canadian.

Parameters:
prefix - The prefix to skip at the begining of the .
key - The property key.
string - The localized string for the specified .
Returns:
if the key has been recognized, or otherwise.
Throws:
java.lang.IllegalArgumentException - if the locale after the prefix is an illegal code, or a different string value was already set for the given locale.

getLocales

public java.util.Set getLocales()
Returns the set of locales defined in this international string.


toString

public java.lang.String toString(java.util.Locale locale)
Returns a string in the specified locale. If there is no string for the specified , then this method search for a locale without the variant part. If no string are found, then this method search for a locale without the country part. For example if the "fr_CA" locale was requested but not found, then this method looks for the "fr" locale. The locale (which stand for unlocalized message) is tried last.

Specified by:
toString in interface org.opengis.util.InternationalString
Specified by:
toString in class AbstractInternationalString
Parameters:
locale - The locale to look for, or .
Returns:
The string in the specified locale, or in a default locale.

equals

public boolean equals(java.lang.Object object)
Compares this international string with the specified object for equality.


hashCode

public int hashCode()
Returns a hash code value for this international text.



Copyright © GeoTools. All Rights Reserved.