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

com.softicar.platform.common.core.i18n.I18nFormatArgumentsLocalizer Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.i18n;

import com.softicar.platform.common.core.locale.CurrentLocale;
import com.softicar.platform.common.core.number.formatter.BigDecimalFormatter;
import java.math.BigDecimal;
import java.util.Objects;

/**
 * Transforms I18n formatting arguments according to {@link CurrentLocale}.
 *
 * @author Oliver Richers
 */
class I18nFormatArgumentsLocalizer {

	private final Object[] arguments;

	public I18nFormatArgumentsLocalizer(Object[] arguments) {

		this.arguments = Objects.requireNonNull(arguments);
	}

	public Object[] localize() {

		var result = new Object[arguments.length];
		for (int i = 0; i < arguments.length; i++) {
			result[i] = processArgument(arguments[i]);
		}
		return result;
	}

	private Object processArgument(Object argument) {

		if (argument instanceof BigDecimal) {
			return new BigDecimalFormatter().format((BigDecimal) argument);
		} else if (argument instanceof Double) {
			return new BigDecimalFormatter().format((Double) argument);
		} else if (argument instanceof Float) {
			return new BigDecimalFormatter().format((Float) argument);
		} else if (argument instanceof IDisplayable) {
			return ((IDisplayable) argument).toDisplay();
		} else {
			return argument;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy