org.pf.nls
Class TextContainer

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

public class TextContainer
extends 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.

Version:
1.0
Author:
M.Duchrow

Constructor Summary
TextContainer(Locale aLocale)
          Initialize the new instance with default values.
 
Method Summary
 boolean containsKey(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.
 IExtendedTextProvider getDefaultProvider()
          Returns the default container that will be used if a key cannot be found in this container.
 String[] getKeys()
          Returns an array with all keys of this container.
 Locale getLocale()
          Returns the locale for which this container holds the text strings
 Locale[] getLocales()
          Returns the locales for which this text provider has text
 String getText(String key)
          Returns the text associated with the given key or null if the key cannot be found.
 boolean hasKey(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.
 int size()
          Returns the number of entries in this container.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextContainer

public TextContainer(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 Locale getLocale()
Returns the locale for which this container holds the text strings


getText

public String getText(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 Locale[] getLocales()
Returns the locales for which this text provider has text

Specified by:
getLocales in interface IExtendedTextProvider

getKeys

public 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(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(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.



Copyright © 2015 Manfred Duchrow Consulting & Software. All rights reserved.