com.google.visualization.datasource.datatable
Class ValueFormatter

java.lang.Object
  extended by com.google.visualization.datasource.datatable.ValueFormatter

public class ValueFormatter
extends java.lang.Object

Formats a Value, or parses a string to create a Value. An instance of this class can be created using the createFromPattern(ValueType, String, ULocale) method, and can then use the format and/or parse. The class also supplies a set of default patterns per ValueType. The default patterns can be used for parsing/formatting values when there is no specified pattern. Otherwise, create a class instance by specifying a pattern and locale. Note: This class is not thread safe since it uses UFormat.

Author:
Yonatan B.Y.

Method Summary
static ValueFormatter createDefault(ValueType type, com.ibm.icu.util.ULocale locale)
          Creates a default formatter for the specified value type and locale.
static java.util.Map<ValueType,ValueFormatter> createDefaultFormatters(com.ibm.icu.util.ULocale locale)
          Creates default formatters for all the value types for the specified locale.
static ValueFormatter createFromPattern(ValueType type, java.lang.String pattern, com.ibm.icu.util.ULocale locale)
          Creates a formatter for the given value type with the given pattern string and locale.
 java.lang.String format(Value value)
          Formats a value to a string, using the given pattern.
 com.ibm.icu.util.ULocale getLocale()
          Returns the ulocale.
 java.lang.String getPattern()
          Returns the pattern for this formatter.
 ValueType getType()
          Returns the type.
 com.ibm.icu.text.UFormat getUFormat()
          Returns the internal UFormat object.
 Value parse(java.lang.String val)
          Creates the corresponding Value from the given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createFromPattern

public static ValueFormatter createFromPattern(ValueType type,
                                               java.lang.String pattern,
                                               com.ibm.icu.util.ULocale locale)
Creates a formatter for the given value type with the given pattern string and locale. If the pattern is illegal returns null. If pattern is null, uses the first default pattern for the given type. If ulocale is null, uses the default locale return by LocaleUtil#getDefaultLocale.

Parameters:
type - The column value type.
pattern - The string pattern representing the formatter pattern.
locale - The ULocale of the formatter.
Returns:
A formatter for the given type, pattern and locale, or null if the pattern is illegal.

createDefault

public static ValueFormatter createDefault(ValueType type,
                                           com.ibm.icu.util.ULocale locale)
Creates a default formatter for the specified value type and locale. If locale is null, uses the default locale returned by LocaleUtil#getDefaultLocale.

Parameters:
type - The value type.
locale - The data table locale.
Returns:
A default formatter for the given type and locale.

createDefaultFormatters

public static java.util.Map<ValueType,ValueFormatter> createDefaultFormatters(com.ibm.icu.util.ULocale locale)
Creates default formatters for all the value types for the specified locale. Returns a map of default formatters by type. The map can be used for iterating over a data table and parsing/formatting its values.

Parameters:
locale - The data table locale.
Returns:
A map of default formatters by type with the given locale.

format

public java.lang.String format(Value value)
Formats a value to a string, using the given pattern.

Parameters:
value - The value to format.
Returns:
The formatted value.

parse

public Value parse(java.lang.String val)
Creates the corresponding Value from the given string. If parsing fails, returns a NULL_VALUE for the specified type. For example, if val="3" and type=ValueType.Number, then after successfully parsing the string "3" into the double 3.0 a new NumberValue would be returned with an internal double value = 3.

Parameters:
val - The string to parse.
Returns:
A corresponding Value for the given string. If parsing fails the value would be a NULL_VALUE of the correct ValueType.

getUFormat

public com.ibm.icu.text.UFormat getUFormat()
Returns the internal UFormat object.

Returns:
The internal UFormat object.

getPattern

public java.lang.String getPattern()
Returns the pattern for this formatter.

Returns:
The pattern for this formatter.

getLocale

public com.ibm.icu.util.ULocale getLocale()
Returns the ulocale.

Returns:
The ulocale.

getType

public ValueType getType()
Returns the type.

Returns:
The type.


Copyright © 2009 Google. All Rights Reserved.