net.sf.doolin.util
Class I18NString

java.lang.Object
  extended by net.sf.doolin.util.I18NString
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
I18NCode

public class I18NString
extends Object
implements Serializable

String that has different values according to a locale.

Author:
Damien Coraboeuf
See Also:
Serialized Form

Constructor Summary
I18NString()
          Constructor for no value
I18NString(I18NString name)
          Copy constructor
I18NString(Locale locale, String value)
          Constructor for a given locale and without any default value
I18NString(String value)
          Constructor with a default value.
I18NString(String defaultValue, Locale locale, String value)
          Constructor for a given locale and with a default value
 
Method Summary
 boolean equals(Object obj)
          Equality.
 String format()
          Formatted representation, used for encoding.
 String getDefaultValue()
          Get the default value
 Iterator<Locale> getKeys()
          Get all defined locales
 String getLocaleValue(Locale locale)
          Get value for a locale, returning null if not found
 String getValue()
          Value for the current locale.
 String getValue(Locale locale)
          Get value for a locale, returning default if not found
 int hashCode()
          Hash code
static I18NString parse(String value)
          Parses a formatted string.
 void setDefaultValue(String value)
          Set the default value
 void setValue(Locale locale, String value)
          Set value for a locale
 void setValue(String locale, String value)
          Utility method, whose purpose if for introspection tools.
 String toString()
          Value for the current locale
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

I18NString

public I18NString()
Constructor for no value


I18NString

public I18NString(String value)
Constructor with a default value.

Parameters:
value - Default value

I18NString

public I18NString(Locale locale,
                  String value)
Constructor for a given locale and without any default value

Parameters:
locale - Locale for the given value
value - Value to set for the given locale

I18NString

public I18NString(String defaultValue,
                  Locale locale,
                  String value)
Constructor for a given locale and with a default value

Parameters:
defaultValue - Default value
locale - Locale for the given value
value - Value to set for the given locale

I18NString

public I18NString(I18NString name)
Copy constructor

Parameters:
name - Object to copy
Method Detail

getValue

public String getValue(Locale locale)
Get value for a locale, returning default if not found

Parameters:
locale - Locale to get the value for
Returns:
Value for this locale, or default value

getLocaleValue

public String getLocaleValue(Locale locale)
Get value for a locale, returning null if not found

Parameters:
locale - Locale to get the value for
Returns:
Value for this locale, or null

getDefaultValue

public String getDefaultValue()
Get the default value

Returns:
Default value

setDefaultValue

public void setDefaultValue(String value)
Set the default value

Parameters:
value - Default value

setValue

public void setValue(Locale locale,
                     String value)
Set value for a locale

Parameters:
locale - Locale to get the value for
value - Value for this locale

setValue

public void setValue(String locale,
                     String value)
Utility method, whose purpose if for introspection tools.

Parameters:
locale - If null, set the default value.
value - Value to set.
See Also:
LocaleUtils.parseLocale(String)

toString

public String toString()
Value for the current locale

Overrides:
toString in class Object

getValue

public String getValue()
Value for the current locale. If not found, takes the first non-empty locale.

Returns:
A value

getKeys

public Iterator<Locale> getKeys()
Get all defined locales

Returns:
Iterator on all defined locales.

hashCode

public int hashCode()
Hash code

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Equality. All strings (default and localised ones) must be the same.

Overrides:
equals in class Object

format

public String format()
Formatted representation, used for encoding. The format is defined as below:
   <defaultValue>{\\<locale>=<value>}*
 

Returns:
Representation for this I18String.

parse

public static I18NString parse(String value)
Parses a formatted string. Expected format is the one which has been defined in format method.

Parameters:
value - Value to parse (it must be a result of a previous call to the format method
Returns:
Parsed I18String.


Copyright © 2011. All Rights Reserved.