org.pfsw.nls
Class TextContainer

java.lang.Object
  extended by org.pfsw.nls.TextContainer
All Implemented Interfaces:
IExtendedTextProvider, ITextProvider

public class TextContainer
extends java.lang.Object
implements IExtendedTextProvider

This is is a simple container for text strings associated with an identifying key. It also allows to set a default TextContainer which will be checked for a key if this container cannot find it.


Constructor Summary
TextContainer(java.util.Locale aLocale)
          Initialize the new instance with default values.
 
Method Summary
protected  void addText(java.lang.String key, java.lang.String text)
          Add the given text under the specified key.
 boolean containsKey(java.lang.String key)
          Returns true if this container or its default container can provide a text for the specified key.
 boolean containsNothing()
          Returns true if this container holds no text and also its default container contains nothing.
protected  java.util.Map createNewTextMap(int initialCapacity)
          Creates a new instance of a map implementation.
 IExtendedTextProvider getDefaultProvider()
          Returns the default container that will be used if a key cannot be found in this container.
protected  int getInitialCapacity()
          Returns the initial capacity for the entries in this container.
 java.lang.String[] getKeys()
          Returns an array with all keys of this container.
 java.util.Locale getLocale()
          Returns the locale for which this container holds the text strings
 java.util.Locale[] getLocales()
          Returns the locales for which this text provider has text
protected  java.lang.String getString(java.lang.String key)
          Returns the string or null from the internal map for the given key.
 java.lang.String getText(java.lang.String key)
          Returns the text associated with the given key or null if the key cannot be found.
protected  java.util.Map getTextMap()
           
protected  boolean hasDefaultContainer()
          Returns whether or not this container has a default container
 boolean hasKey(java.lang.String key)
          Returns true if this container can provide a text for the specified key.
 boolean isEmpty()
          Returns true if this container holds no text.
 void setDefaultProvider(IExtendedTextProvider textContainer)
          Sets the default container.
protected  void setLocale(java.util.Locale newLocale)
          Set the locale for which this container holds the text strings
protected  void setTextMap(java.util.Map newValue)
           
 int size()
          Returns the number of entries in this container.
protected  org.pfsw.text.StringUtil str()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextContainer

public TextContainer(java.util.Locale aLocale)
Initialize the new instance with default values.

Method Detail

getDefaultProvider

public IExtendedTextProvider getDefaultProvider()
Returns the default container that will be used if a key cannot be found in this container.

Returns:
A text container of null

setDefaultProvider

public void setDefaultProvider(IExtendedTextProvider textContainer)
Sets the default container.

Parameters:
textContainer - A new default container or null to remove any existing

getLocale

public java.util.Locale getLocale()
Returns the locale for which this container holds the text strings


getText

public java.lang.String getText(java.lang.String key)
Returns the text associated with the given key or null if the key cannot be found.
If the specified key is null then null will be returned.

Specified by:
getText in interface ITextProvider
Parameters:
key - The identifier for the text

getLocales

public java.util.Locale[] getLocales()
Returns the locales for which this text provider has text

Specified by:
getLocales in interface IExtendedTextProvider

getKeys

public java.lang.String[] getKeys()
Returns an array with all keys of this container. This does not include keys that might be additionally available through the default container.


containsKey

public boolean containsKey(java.lang.String key)
Returns true if this container or its default container can provide a text for the specified key.

Parameters:
key - The key to lookup
See Also:
hasKey(String)

hasKey

public boolean hasKey(java.lang.String key)
Returns true if this container can provide a text for the specified key. This method returns false even if the key is available in the default container.

Parameters:
key - The key to lookup
See Also:
containsKey(String)

isEmpty

public boolean isEmpty()
Returns true if this container holds no text. However, it might still have a default container which has text. In such case this method still returns true. To check all (including default containers) use method containsNothing().

See Also:
containsNothing()

containsNothing

public boolean containsNothing()
Returns true if this container holds no text and also its default container contains nothing. To only check this container disregarding any default container use method isEmpty().

Specified by:
containsNothing in interface IExtendedTextProvider
See Also:
isEmpty()

size

public int size()
Returns the number of entries in this container. This does not include any entries in a potentially existing default container.


getString

protected java.lang.String getString(java.lang.String key)
Returns the string or null from the internal map for the given key.


addText

protected void addText(java.lang.String key,
                       java.lang.String text)
Add the given text under the specified key. If either key or text is null nothing happens. If the key already exists the new text will replace the old one.


hasDefaultContainer

protected boolean hasDefaultContainer()
Returns whether or not this container has a default container


getInitialCapacity

protected int getInitialCapacity()
Returns the initial capacity for the entries in this container. Subclasses may override this method in order to return another value. Here it returns 50.


createNewTextMap

protected java.util.Map createNewTextMap(int initialCapacity)
Creates a new instance of a map implementation. Subclasses may override this method to use different implementation than java.util.HashMap which is used here.


setLocale

protected void setLocale(java.util.Locale newLocale)
Set the locale for which this container holds the text strings


getTextMap

protected java.util.Map getTextMap()

setTextMap

protected void setTextMap(java.util.Map newValue)

str

protected org.pfsw.text.StringUtil str()