
org.javafunk.funk.BigDecimals Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of funk-core Show documentation
Show all versions of funk-core Show documentation
Functional utilities for Java: core APIs
The newest version!
/*
* Copyright (C) 2011-Present Funk committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.javafunk.funk;
import org.javafunk.funk.functors.Mapper;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
public class BigDecimals {
private BigDecimals() {}
public static Mapper fromStringToBigDecimal() {
return new Mapper() {
@Override public BigDecimal map(String input) {
return new BigDecimal(input);
}
};
}
public static Mapper fromIntegerToBigDecimal() {
return new Mapper() {
@Override public BigDecimal map(Integer input) {
return new BigDecimal(input);
}
};
}
public static Mapper fromLongToBigDecimal() {
return new Mapper() {
@Override public BigDecimal map(Long input) {
return new BigDecimal(input);
}
};
}
public static Mapper fromBigIntegerToBigDecimal() {
return new Mapper() {
@Override public BigDecimal map(BigInteger input) {
return new BigDecimal(input);
}
};
}
public static Mapper fromDoubleToBigDecimal() {
return new Mapper() {
@Override public BigDecimal map(Double input) {
return new BigDecimal(input);
}
};
}
public static Mapper toPlainString() {
return new Mapper() {
@Override public String map(BigDecimal input) {
return input.toPlainString();
}
};
}
public static Mapper toScaled(final Integer scale, final RoundingMode roundingMode) {
return new Mapper() {
@Override public BigDecimal map(BigDecimal input) {
return input.setScale(scale, roundingMode);
}
};
}
public static BigDecimal bigDecimal(Integer value) {
return new BigDecimal(value);
}
public static BigDecimal bigDecimal(Long value) {
return new BigDecimal(value);
}
public static BigDecimal bigDecimal(Double value) {
return new BigDecimal(value);
}
public static BigDecimal bigDecimal(String value) {
return new BigDecimal(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy