All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.icu.message2.IdentityFormatterFactory Maven / Gradle / Ivy

Go to download

International Component for Unicode for Java (ICU4J) is a mature, widely used Java library providing Unicode and Globalization support

There is a newer version: 76.1
Show newest version
// © 2022 and later: Unicode, Inc. and others.
// License & terms of use: https://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 fixedOptions) {
        return new IdentityFormatterImpl();
    }

    private static class IdentityFormatterImpl implements Formatter {
        /**
         * {@inheritDoc}
         */
        @Override
        public FormattedPlaceholder format(Object toFormat, Map variableOptions) {
            return new FormattedPlaceholder(
                    toFormat, new PlainStringFormattedValue(Objects.toString(toFormat)));
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String formatToString(Object toFormat, Map variableOptions) {
            return format(toFormat, variableOptions).toString();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy