AliasTemplateNumberFormatFactory (FreeMarker 2.3.35 API)
Description: declaration: package: freemarker.core, class: AliasTemplateNumberFormatFactory

Package freemarker.core

# Class AliasTemplateNumberFormatFactory

java.lang.Object
freemarker.core.TemplateValueFormatFactory
freemarker.core.TemplateNumberFormatFactory
freemarker.core.AliasTemplateNumberFormatFactory

public final class AliasTemplateNumberFormatFactory extends TemplateNumberFormatFactory
Creates an alias to another format, so that the format can be referred to with a simple name in the template, rather than as a concrete pattern or other kind of format string.

Since:
  2.3.24

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AliasTemplateNumberFormatFactory​(String targetFormatString)`
  `AliasTemplateNumberFormatFactory​(String defaultTargetFormatString, Map<Locale,​String> localizedTargetFormatStrings)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `TemplateNumberFormat`
  `get​(String params, Locale locale, Environment env)`
  Returns a formatter for the given parameters.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AliasTemplateNumberFormatFactory

    public AliasTemplateNumberFormatFactory​(String targetFormatString)
    Parameters:
      `targetFormatString` - The format string this format will be an alias to

  - ### AliasTemplateNumberFormatFactory

    public AliasTemplateNumberFormatFactory​(String defaultTargetFormatString, Map<Locale,​String> localizedTargetFormatStrings)
    Parameters:
      `defaultTargetFormatString` - The format string this format will be an alias to if there's no locale-specific format string for the requested locale in `localizedTargetFormatStrings`. Not `null`.
      `localizedTargetFormatStrings` - Maps `Locale`-s to format strings (maybe `null`). If the desired locale doesn't occur in the map, a less specific locale is tried, repeatedly until only the language part remains. For example, if locale is `new Locale("en", "US", "Linux")`, then these keys will be attempted until a match is found, in this order: `new Locale("en", "US", "Linux")`, `new Locale("en", "US")`, `new Locale("en")`. If there's still no matching key, the value of the `targetFormatString` will be used.

- ## Method Details

  - ### get

    public TemplateNumberFormat get​(String params, Locale locale, Environment env) throws TemplateValueFormatException
    Description copied from class: `TemplateNumberFormatFactory`
    Returns a formatter for the given parameters.

    The returned formatter can be a new instance or a reused (cached) instance. Note that `Environment` itself caches the returned instances, though that cache is lost with the `Environment` (i.e., when the top-level template execution ends), also it might flushes lot of entries if the locale or time zone is changed during template execution. So caching on the factory level is still useful, unless creating the formatters is sufficiently cheap.

    Specified by:
      `get` in class `TemplateNumberFormatFactory`
    Parameters:
      `params` - The string that further describes how the format should look. For example, when the `numberFormat` is `"@fooBar 1, 2"`, then it will be `"1, 2"` (and `"@fooBar"` selects the factory). The format of this string is up to the `TemplateNumberFormatFactory` implementation. Not `null`, often an empty string.
      `locale` - The locale to format for. Not `null`. The resulting format must be bound to this locale forever (i.e. locale changes in the `Environment` must not be followed).
      `env` - The runtime environment from which the formatting was called. This is mostly meant to be used for `Environment.setCustomState(Object, Object)`/`Environment.getCustomState(Object)`.
    Throws:
      `TemplateValueFormatException` - if any problem occurs while parsing/getting the format. Notable subclasses: `InvalidFormatParametersException` if the `params` is malformed.