blob: b5334b1b9903a32ede8293f83c92732baed37bf6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// © 2022 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
package com.ibm.icu.message2;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
/**
* Creates a {@link Formatter} that simply returns the String non-i18n aware representation of an object.
*/
class IdentityFormatterFactory implements FormatterFactory {
/**
* {@inheritDoc}
*/
@Override
public Formatter createFormatter(Locale locale, Map<String, Object> fixedOptions) {
return new IdentityFormatterImpl();
}
private static class IdentityFormatterImpl implements Formatter {
/**
* {@inheritDoc}
*/
@Override
public FormattedPlaceholder format(Object toFormat, Map<String, Object> variableOptions) {
return new FormattedPlaceholder(toFormat, new PlainStringFormattedValue(Objects.toString(toFormat)));
}
/**
* {@inheritDoc}
*/
@Override
public String formatToString(Object toFormat, Map<String, Object> variableOptions) {
return format(toFormat, variableOptions).toString();
}
}
}
|