net.sf.mmm.util.nls.impl.formatter
Class NlsFormatterChoice

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractComponent
      extended by net.sf.mmm.util.component.base.AbstractLoggableComponent
          extended by net.sf.mmm.util.nls.base.AbstractNlsFormatter<O>
              extended by net.sf.mmm.util.nls.base.AbstractNlsFormatterPlugin<Object>
                  extended by net.sf.mmm.util.nls.impl.formatter.NlsFormatterChoice
All Implemented Interfaces:
NlsFormatter<Object>, NlsFormatterPlugin<Object>

public final class NlsFormatterChoice
extends AbstractNlsFormatterPlugin<Object>

This is the implementation of NlsFormatter for choice-format.
Examples:

NlsMessage Example result
{deleteCount} {deleteCount,choice,(?==1)['files'](else)['file']} deleted. 1 file deleted.
{flag,choice,(?==true){date}(else){time}} 23:59:59

Since:
2.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Nested Class Summary
private static class NlsFormatterChoice.Choice
          This inner class represents a single choice.
private  class NlsFormatterChoice.Condition
          This inner class represents a single choice.
 
Field Summary
private  List<NlsFormatterChoice.Choice> choices
          The NlsFormatterChoice.Choices.
static String CONDITION_ELSE
          The value of a NlsFormatterChoice.Choice condition that matches always.
static char CONDITION_END
          The character used to indicate the end of a NlsFormatterChoice.Choice condition.
static char CONDITION_START
          The character used to indicate the start of a NlsFormatterChoice.Choice condition.
static char CONDITION_VAR
          The character used to indicate the variable object of a NlsFormatterChoice.Choice condition.
private static CharFilter FILTER_COMPARATOR
          The CharFilter for the comparator symbol .
private static CharFilter FILTER_COMPARATOR_ARGUMENT
          The CharFilter for the comparator argument.
private static Filter<Object> FILTER_ELSE
          The Filter for CONDITION_ELSE.
private  NlsDependencies nlsDependencies
          The NlsDependencies to use.
private static String REQUIRED_FORMAT_COMPARATOR
          The format of a comparator.
private static String REQUIRED_FORMAT_CONDITION
          The format of a condition.
 
Constructor Summary
NlsFormatterChoice(CharSequenceScanner scanner, NlsDependencies nlsDependencies)
          The constructor.
 
Method Summary
 void format(Object object, Locale locale, Map<String,Object> arguments, NlsTemplateResolver resolver, Appendable buffer)
          This method formats the given object according to the given locale.
 String getStyle()
          This method gets the style of this formatter.
 String getType()
          This method gets the type of this formatter.
private  NlsFormatterChoice.Choice parseChoice(CharSequenceScanner scanner)
          This method parses the NlsFormatterChoice.Choice.
private  Object parseComparatorArgument(CharSequenceScanner scanner)
          This method parses the comparator argument.
private  Filter<Object> parseCondition(CharSequenceScanner scanner)
          This method parses the NlsFormatterChoice.Condition.
 
Methods inherited from class net.sf.mmm.util.nls.base.AbstractNlsFormatterPlugin
toString
 
Methods inherited from class net.sf.mmm.util.nls.base.AbstractNlsFormatter
format
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent
doInitialize, getLogger, setLogger
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent
doInitialized, getInitializationState, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.mmm.util.nls.api.NlsFormatter
format
 

Field Detail

REQUIRED_FORMAT_COMPARATOR

private static final String REQUIRED_FORMAT_COMPARATOR
The format of a comparator.

See Also:
Constant Field Values

REQUIRED_FORMAT_CONDITION

private static final String REQUIRED_FORMAT_CONDITION
The format of a condition.

See Also:
Constant Field Values

CONDITION_START

public static final char CONDITION_START
The character used to indicate the start of a NlsFormatterChoice.Choice condition.

See Also:
Constant Field Values

CONDITION_END

public static final char CONDITION_END
The character used to indicate the end of a NlsFormatterChoice.Choice condition.

See Also:
Constant Field Values

CONDITION_VAR

public static final char CONDITION_VAR
The character used to indicate the variable object of a NlsFormatterChoice.Choice condition.

See Also:
Constant Field Values

CONDITION_ELSE

public static final String CONDITION_ELSE
The value of a NlsFormatterChoice.Choice condition that matches always.

See Also:
Constant Field Values

FILTER_ELSE

private static final Filter<Object> FILTER_ELSE
The Filter for CONDITION_ELSE.


FILTER_COMPARATOR

private static final CharFilter FILTER_COMPARATOR
The CharFilter for the comparator symbol .


FILTER_COMPARATOR_ARGUMENT

private static final CharFilter FILTER_COMPARATOR_ARGUMENT
The CharFilter for the comparator argument.


nlsDependencies

private final NlsDependencies nlsDependencies
The NlsDependencies to use.


choices

private final List<NlsFormatterChoice.Choice> choices
The NlsFormatterChoice.Choices.

Constructor Detail

NlsFormatterChoice

public NlsFormatterChoice(CharSequenceScanner scanner,
                          NlsDependencies nlsDependencies)
The constructor.

Parameters:
scanner - is the CharSequenceScanner pointing to the choice- formatStyle.
nlsDependencies - are the NlsDependencies to use.
Method Detail

parseChoice

private NlsFormatterChoice.Choice parseChoice(CharSequenceScanner scanner)
This method parses the NlsFormatterChoice.Choice.

Parameters:
scanner - is the CharSequenceScanner.
Returns:
the parsed NlsFormatterChoice.Choice.

parseCondition

private Filter<Object> parseCondition(CharSequenceScanner scanner)
This method parses the NlsFormatterChoice.Condition.

Parameters:
scanner - is the CharSequenceScanner.
Returns:
the parsed NlsFormatterChoice.Condition or FILTER_ELSE in case of CONDITION_ELSE.

parseComparatorArgument

private Object parseComparatorArgument(CharSequenceScanner scanner)
This method parses the comparator argument.

Parameters:
scanner - is the CharSequenceScanner.
Returns:
the parsed comparator argument.

format

public void format(Object object,
                   Locale locale,
                   Map<String,Object> arguments,
                   NlsTemplateResolver resolver,
                   Appendable buffer)
            throws IOException
This method formats the given object according to the given locale.

Parameters:
object - is the object to format.
locale - is the locale used for localized formatting.
arguments - is the Map of arguments.
resolver - is the NlsTemplateResolver.
buffer - is where to append the formatted object.
Throws:
IOException - if the given Appendable caused such exception.

getType

public String getType()
This method gets the type of this formatter. See TYPE_* constants of NlsFormatterManager e.g. NlsFormatterManager.TYPE_NUMBER.

Returns:
the type or null for the default formatter. If type is null then also style needs to be null.

getStyle

public String getStyle()
This method gets the style of this formatter. See STYLE_* constants of NlsFormatterManager e.g. NlsFormatterManager.STYLE_LONG.

Returns:
the style or null for no style.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.