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

com.softicar.platform.common.core.number.BigDecimalMapper 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.number;

import java.math.BigDecimal;
import java.util.function.Function;

/**
 * A class to map between {@link BigDecimal} and a {@link Number} based type.
 *
 * @author Oliver Richers
 */
public class BigDecimalMapper {

	public static final BigDecimalMapper BIG_DECIMAL = new BigDecimalMapper<>(Function.identity(), Function.identity());
	public static final BigDecimalMapper DOUBLE = new BigDecimalMapper<>(BigDecimal::valueOf, BigDecimal::doubleValue);
	public static final BigDecimalMapper FLOAT = new BigDecimalMapper<>(BigDecimal::valueOf, BigDecimal::floatValue);

	private final Function toMapper;
	private final Function fromMapper;

	public BigDecimalMapper(Function toMapper, Function fromMapper) {

		this.toMapper = toMapper;
		this.fromMapper = fromMapper;
	}

	public BigDecimal toBigDecimal(T value) {

		return toMapper.apply(value);
	}

	public T fromBigDecimal(BigDecimal value) {

		return fromMapper.apply(value);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy