org.op4j.functions.FnBigDecimal Maven / Gradle / Ivy
/*
* =============================================================================
*
* Copyright (c) 2010, The OP4J team (http://www.op4j.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* =============================================================================
*/
package org.op4j.functions;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Locale;
import org.apache.commons.lang.Validate;
/**
*
* @since 1.0
*
* @author Soraya Sánchez
*
*/
@SuppressWarnings({"cast", "unchecked"})
public final class FnBigDecimal {
private static final Function, BigDecimal> MAX_FUNC = new Max();
private static final Function, BigDecimal> MIN_FUNC = new Min();
private static final Function, BigDecimal> SUM_FUNC = new Sum();
private static final Function, BigDecimal> AVG_FUNC = new Avg();
private static final Function MAX_ARRAY_FUNC = new MaxArray();
private static final Function MIN_ARRAY_FUNC = new MinArray();
private static final Function SUM_ARRAY_FUNC = new SumArray();
private static final Function AVG_ARRAY_FUNC = new AvgArray();
private static final Function ABS_FUNC = new Abs();
FnBigDecimal() {
super();
}
/**
*
* It rounds the input number with the given scale and {@link RoundingMode}. The input
* number will be converted into a {@link BigDecimal} with the given scale and
* roundingMode
*
*
* @param scale the scale
* @param roundingMode the {@link RoundingMode}
* @return the {@link BigDecimal} representation of the input rounded based on
* the given parameters
*/
public static final Function roundBigDecimal(final int scale, final RoundingMode roundingMode) {
return FnNumber.roundBigDecimal(scale, roundingMode);
}
/**
*
* It returns the {@link String} representation of the input number
*
*
* @return the {@link String} representation of the input
*/
public static final Function toStr() {
return (Function)((Function)FnNumber.toStr());
}
/**
*
* It returns the {@link String} representation of the input number either
* using or not using grouping
*
*
* @param groupingUsed whether or not grouping will be used
* @return the {@link String} representation of the input
*/
public static final Function toStr(boolean groupingUsed) {
return (Function)((Function)FnNumber.toStr(groupingUsed));
}
/**
*
* It returns the {@link String} representation of the target number in the given {@link Locale}
*
*
* @param locale the {@link Locale} to be used
* @return the {@link String} representation of the input
*/
public static final Function toStr(Locale locale) {
return (Function)((Function)FnNumber.toStr(locale));
}
/**
*
* It returns the {@link String} representation of the target number in the given locale
*
*
* @param locale the locale to be used
* @return the {@link String} representation of the input
*/
public static final Function toStr(String locale) {
return (Function)((Function)FnNumber.toStr(locale));
}
/**
*
* It returns the {@link String} representation of the target number in the given {@link Locale}. Grouping
* will be used depending on the value of the groupingUsed parameter
*
*
* @param locale the {@link Locale} to be used
* @param groupingUsed whether or not grouping will be used
* @return the {@link String} representation of the input
*/
public static final Function toStr(Locale locale, boolean groupingUsed) {
return (Function)((Function)FnNumber.toStr(locale, groupingUsed));
}
/**
*
* It returns the {@link String} representation of the target number in the given locale. Grouping
* will be used depending on the value of the groupingUsed parameter
*
*
* @param locale the locale to be used
* @param groupingUsed whether or not grouping will be used
* @return the {@link String} representation of the input
*/
public static final Function toStr(String locale, boolean groupingUsed) {
return (Function)((Function)FnNumber.toStr(locale, groupingUsed));
}
/**
*
* It returns the {@link String} representation of the target number in the given {@link Locale}.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toStr(Locale.ENGLISH, 3, 2, 2, true) would return 010.00 if target number is 10
*
* toStr(Locale.ENGLISH, 2, 2, 4, true) would return 00.00 if target number is 0
*
* @param locale the {@link Locale} to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @return the {@link String} representation of the input
*/
public static final Function toStr(Locale locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed) {
return (Function)((Function)FnNumber.toStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed));
}
/**
*
* It returns the {@link String} representation of the target number in the given locale.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toStr(Locale.ENGLISH.toString(), 3, 2, 2, true) would return 010.00 if target number is 10
*
* toStr(Locale.ENGLISH.toString(), 2, 2, 4, true) would return 00.00 if target number is 0
*
* @param locale the locale to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @return the {@link String} representation of the input
*/
public static final Function toStr(String locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed) {
return (Function)((Function)FnNumber.toStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed));
}
/**
*
* It returns the {@link String} representation of the target number in the given {@link Locale}.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toStr(Locale.ENGLISH, 3, 2, 2, ',', '.', true) would return 1,000.00 if target number is 1000
*
* toStr(Locale.ENGLISH, 2, 2, 4, ',', '.', true) would return 00.00 if target number is 0
*
* @param locale the {@link Locale} to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingSeparator grouping separator to be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
* @return the {@link String} representation of the input
*/
public static final Function toStr(Locale locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits,
char groupingSeparator, char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingSeparator, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* It returns the {@link String} representation of the target number in the given {@link Locale}.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toStr(Locale.ENGLISH, 3, 2, 2, true, ',', true) would return 1,000,00 if target number is 1000
*
* toStr(Locale.ENGLISH, 2, 2, 4, true, ',', true) would return 00,00 if target number is 0
*
* @param locale the {@link Locale} to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
* @return the {@link String} representation of the input
*/
public static final Function toStr(Locale locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed,
char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* It returns the {@link String} representation of the target number in the given locale.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toStr(Locale.ENGLISH.toString(), 3, 2, 2, ',', '.', true) would return 1,000.00 if target number is 1000
*
* toStr(Locale.ENGLISH.toString(), 2, 2, 4, ',', '.', true) would return 00.00 if target number is 0
*
* @param locale the locale to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingSeparator grouping separator to be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
* @return the {@link String} representation of the input
*/
public static final Function toStr(String locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits,
char groupingSeparator, char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingSeparator, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* It returns the {@link String} representation of the target number in the given locale.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toStr(Locale.ENGLISH.toString(), 3, 2, 2, true, ',', true) would return 1,000,00 if target number is 1000
*
* toStr(Locale.ENGLISH.toString(), 2, 2, 4, true, ',', true) would return 00,00 if target number is 0
*
* @param locale the locale to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
* @return the {@link String} representation of the input
*/
public static final Function toStr(String locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed,
char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* default {@link Locale}
*
*
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr() {
return (Function)((Function)FnNumber.toCurrencyStr());
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* default {@link Locale}
*
*
* @param groupingUsed whether or not grouping will be used
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(boolean groupingUsed) {
return (Function)((Function)FnNumber.toCurrencyStr(groupingUsed));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* given {@link Locale}
*
*
* @param locale the {@link Locale} to be used
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(Locale locale) {
return (Function)((Function)FnNumber.toCurrencyStr(locale));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* given locale
*
*
* @param locale the locale to be used
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(String locale) {
return (Function)((Function)FnNumber.toCurrencyStr(locale));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* given {@link Locale}
*
*
* @param locale the {@link Locale} to be used
* @param groupingUsed whether or not grouping will be used
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(Locale locale, boolean groupingUsed) {
return (Function)((Function)FnNumber.toCurrencyStr(locale, groupingUsed));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* given locale
*
*
* @param locale the locale to be used
* @param groupingUsed whether or not grouping will be used
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(String locale, boolean groupingUsed) {
return (Function)((Function)FnNumber.toCurrencyStr(locale, groupingUsed));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* given {@link Locale}.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toCurrencyStr(Locale.UK, 3, 2, 2, true) would return £1,000.00 if target number is 1000
*
* toCurrencyStr(Locale.UK, 2, 2, 4, true) would return £00.00 if target number is 0
*
*
* @param locale the {@link Locale} to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(Locale locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed) {
return (Function)((Function)FnNumber.toCurrencyStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* given locale taking into account the given parameters.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toCurrencyStr(Locale.UK.toString(), 3, 2, 2, true) would return £1,000.00 if target number is 1000
*
* toCurrencyStr(Locale.UK.toString(), 2, 2, 4, true) would return £00.00 if target number is 0
*
*
* @param locale the locale to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(String locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed) {
return (Function)((Function)FnNumber.toCurrencyStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* given {@link Locale} taking into account the given parameters.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toCurrencyStr(Locale.UK, 3, 2, 2, ',', ',', true) would return £1,000,00 if target number is 1000
*
* toCurrencyStr(Locale.UK, 2, 2, 4, ',', ',', true) would return £00,00 if target number is 0
*
* @param locale the {@link Locale} to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingSeparator grouping separator to be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
*
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(Locale locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits,
char groupingSeparator, char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toCurrencyStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingSeparator, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* given {@link Locale} taking into account the given parameters.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toCurrencyStr(Locale.UK.toString(), 3, 2, 2, ',', ',', true) would return £1,000,00 if target number is 1000
*
* toCurrencyStr(Locale.UK.toString(), 2, 2, 4, ',', ',', true) would return £00,00 if target number is 0
*
* @param locale the {@link Locale} to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
*
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(Locale locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed,
char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toCurrencyStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* given locale taking into account the given parameters.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toCurrencyStr(Locale.UK, 3, 2, 2, ',', ',', true) would return £1,000,00 if target number is 1000
*
* toCurrencyStr(Locale.UK, 2, 2, 4, ',', ',', true) would return £00,00 if target number is 0
*
* @param locale the locale to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingSeparator grouping separator to be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
*
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(String locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits,
char groupingSeparator, char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toCurrencyStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingSeparator, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* It returns the {@link String} representation of the target as a currency in the
* given locale taking into account the given parameters.
* If necessary, it will add leading or trailing zeros to the string based on the given parameters. So,
*
* toCurrencyStr(Locale.UK.toString(), 3, 2, 2, ',', ',', true) would return £1,000,00 if target number is 1000
*
* toCurrencyStr(Locale.UK.toString(), 2, 2, 4, ',', ',', true) would return £00,00 if target number is 0
*
* @param locale the locale to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
*
* @return the {@link String} representation of the input as a currency
*/
public static final Function toCurrencyStr(String locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed,
char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toCurrencyStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* A {@link String} representing a percentage is created from the target number.
*
*
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr() {
return (Function)((Function)FnNumber.toPercentStr());
}
/**
*
* A {@link String} representing a percentage is created from the target number
* either using grouping or not depending on the given parameter. So,
*
* toPercentStr(true) would return 100,000% if target number is 1000
*
* toPercentStr(false) would return 100000% if target number is 1000
*
* @param groupingUsed whether or not grouping will be used
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(boolean groupingUsed) {
return (Function)((Function)FnNumber.toPercentStr(groupingUsed));
}
/**
*
* A {@link String} representing a percentage is created from the target number
* in the given {@link Locale}
*
*
* @param locale the {@link Locale} to be used
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(Locale locale) {
return (Function)((Function)FnNumber.toPercentStr(locale));
}
/**
*
* A {@link String} representing a percentage is created from the target number
* in the given locale
*
*
* @param locale the locale to be used
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(String locale) {
return (Function)((Function)FnNumber.toPercentStr(locale));
}
/**
*
* A {@link String} representing a percentage is created from the target number
* in the given {@link Locale}. Grouping will be used depending on the value of the
* groupingUsed parameter.
*
*
* @param locale the {@link Locale} to be used
* @param groupingUsed whether or not grouping will be used
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(Locale locale, boolean groupingUsed) {
return (Function)((Function)FnNumber.toPercentStr(locale, groupingUsed));
}
/**
*
* A {@link String} representing a percentage is created from the target number
* in the given locale. Grouping will be used depending on the value of the
* groupingUsed parameter.
*
*
* @param locale the locale to be used
* @param groupingUsed whether or not grouping will be used
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(String locale, boolean groupingUsed) {
return (Function)((Function)FnNumber.toPercentStr(locale, groupingUsed));
}
/**
*
* A {@link String} representing a percentage is created from the target number
* in the given {@link Locale}.
* If necessary, it will add leading or trailing zeros to the string
* based on the given parameters.
*
*
* @param locale the {@link Locale} to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(Locale locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed) {
return (Function)((Function)FnNumber.toPercentStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed));
}
/**
*
* A {@link String} representing a percentage is created from the target number
* in the given locale.
* If necessary, it will add leading or trailing zeros to the string
* based on the given parameters.
*
*
* @param locale the locale to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(String locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed) {
return (Function)((Function)FnNumber.toPercentStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed));
}
/**
*
* A {@link String} representing a percentage is created from the target number
* in the given {@link Locale} and using the other given parameters as well.
* If necessary, it will add leading or trailing zeros to the string
* based on the given parameters.
*
*
* @param locale the {@link Locale} to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingSeparator grouping separator to be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(Locale locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits,
char groupingSeparator, char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toPercentStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingSeparator, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* A {@link String} representing a percentage is created from the target number
* in the given locale and using the other given parameters as well.
* If necessary, it will add leading or trailing zeros to the string
* based on the given parameters.
*
*
* @param locale the locale to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(Locale locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed,
char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toPercentStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* A {@link String} representing a percentage is created from the target number
* in the given locale and using the other given parameters as well.
* If necessary, it will add leading or trailing zeros to the string
* based on the given parameters.
*
*
* @param locale the locale to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingSeparator grouping separator to be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(String locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits,
char groupingSeparator, char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toPercentStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingSeparator, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* A {@link String} representing a percentage is created from the target number
* in the given locale and using the other given parameters as well.
* If necessary, it will add leading or trailing zeros to the string
* based on the given parameters.
*
*
* @param locale the locale to be used
* @param minIntegerDigits minimum number of integer digits so, if not enough in the
* target number, 0's will be added to the left of the integer part
* @param minFractionDigits minimum number of fraction digits so, if not enough in the
* target number, 0's will be added to the right of the decimal part
* @param maxFractionDigits maximum number of fraction digits
* @param groupingUsed whether or not grouping will be used
* @param decimalSeparator decimal separator to be used
* @param decimalSeparatorAlwaysShown whether decimal separator should be shown
* even if the decimal part is zero or not
* @return the string representation of the input number as a percentage
*/
public static final Function toPercentStr(String locale, int minIntegerDigits,
int minFractionDigits, int maxFractionDigits, boolean groupingUsed,
char decimalSeparator, boolean decimalSeparatorAlwaysShown) {
return (Function)((Function)FnNumber.toPercentStr(locale,
minIntegerDigits,
minFractionDigits, maxFractionDigits,
groupingUsed, decimalSeparator,
decimalSeparatorAlwaysShown));
}
/**
*
* Determines whether the target object and the specified object are equal
* by calling the equals method on the target object.
*
*
* @param object the {@link BigDecimal} to compare to the target
* @return true if both objects are equal, false if not.
*/
public static final Function eq(final BigDecimal object) {
return (Function)((Function)FnObject.eq(object));
}
/**
*
* Determines whether the target object and the specified object are equal
* in value, this is, whether target.compareTo(object) == 0. Both
* the target and the specified object have to implement {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return true if both objects are equal according to "compareTo", false if not.
*/
public static final Function eqValue(final BigDecimal object) {
return (Function)((Function)FnObject.eqValue(object));
}
/**
*
* Determines whether the target object and the specified object are NOT equal
* by calling the equals method on the target object.
*
*
* @param object the {@link BigDecimal} to compare to the target
* @return false if both objects are equal, true if not.
*/
public static final Function notEq(final BigDecimal object) {
return (Function)((Function)FnObject.notEq(object));
}
/**
*
* Determines whether the target object and the specified object are NOT equal
* in value, this is, whether target.compareTo(object) != 0. Both
* the target and the specified object have to implement {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return false if both objects are equal according to "compareTo", true if not.
*/
public static final Function notEqValue(final BigDecimal object) {
return (Function)((Function)FnObject.notEqValue(object));
}
/**
*
* Determines whether the target object is less than the specified object
* in value, this is, whether target.compareTo(object) < 0. Both
* the target and the specified object have to implement {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return true if target is less than the specified object, false if not
*/
public static final Function lessThan(final Number object) {
return (Function)((Function)FnObject.lessThan(object));
}
/**
*
* Determines whether the target object is less or equal to the specified object
* in value, this is, whether target.compareTo(object) <= 0. Both
* the target and the specified object have to implement {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return true if target is less or equal to the specified object, false if not
*/
public static final Function lessOrEqTo(final Number object) {
return (Function)((Function)FnObject.lessOrEqTo(object));
}
/**
*
* Determines whether the target object is greater than the specified object
* in value, this is, whether target.compareTo(object) > 0. Both
* the target and the specified object have to implement {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return true if target is greater than the specified object, false if not
*/
public static final Function greaterThan(final Number object) {
return (Function)((Function)FnObject.greaterThan(object));
}
/**
*
* Determines whether the target object is greater or equal to the specified object
* in value, this is, whether target.compareTo(object) >= 0. Both
* the target and the specified object have to implement {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return true if target is greater or equal to the specified object, false if not
*/
public static final Function greaterOrEqTo(final Number object) {
return (Function)((Function)FnObject.greaterOrEqTo(object));
}
/**
*
* Determines whether the result of executing the specified function
* on the target object and the specified object parameter are equal
* by calling the equals method.
*
*
* @param object the object to compare to the target
* @return true if both objects are equal, false if not.
*
* @since 1.1
*/
public static final Function eqBy(final IFunction by, final Object object) {
return (Function)((Function)FnObject.eqBy(by, object));
}
/**
*
* Determines whether the result of executing the specified function
* on the target object and the specified object parameter are equal
* in value, this is, whether functionResult.compareTo(object) == 0.
* Both the function result and the specified object have to implement
* {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return true if both objects are equal according to "compareTo", false if not.
*
* @since 1.1
*/
public static final Function eqValueBy(final IFunction by, final Object object) {
return FnObject.eqValueBy(by, object);
}
/**
*
* Determines whether the result of executing the specified function
* on the target object and the specified object parameter are NOT equal
* by calling the equals method.
*
*
* @param object the object to compare to the target
* @return false if both objects are equal, true if not.
*
* @since 1.1
*/
public static final Function notEqBy(final IFunction by, final Object object) {
return (Function)((Function)FnObject.notEqBy(by, object));
}
/**
*
* Determines whether the result of executing the specified function
* on the target object and the specified object parameter are NOT equal
* in value, this is, whether functionResult.compareTo(object) != 0.
* Both the function result and the specified object have to implement
* {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return false if both objects are equal according to "compareTo", true if not.
*
* @since 1.1
*/
public static final Function notEqValueBy(final IFunction by, final Object object) {
return FnObject.notEqValueBy(by, object);
}
/**
*
* Determines whether the result of executing the specified function
* on the target object is less than the specified object parameter
* in value, this is, whether functionResult.compareTo(object) < 0. Both
* the target and the specified object have to implement {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return true if function result is less than the specified object, false if not
*
* @since 1.1
*/
public static final Function lessThanBy(final IFunction by, final Object object) {
return (Function)((Function)FnObject.lessThanBy(by, object));
}
/**
*
* Determines whether the result of executing the specified function
* on the target object is less or equal to the specified object parameter
* in value, this is, whether functionResult.compareTo(object) <= 0. Both
* the target and the specified object have to implement {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return true if function result is less or equal to the specified object, false if not
*
* @since 1.1
*/
public static final Function lessOrEqToBy(final IFunction by, final Object object) {
return (Function)((Function)FnObject.lessOrEqToBy(by, object));
}
/**
*
* Determines whether the result of executing the specified function
* on the target object is greater than the specified object parameter
* in value, this is, whether functionResult.compareTo(object) > 0. Both
* the target and the specified object have to implement {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return true if function result is greater than the specified object, false if not
*
* @since 1.1
*/
public static final Function greaterThanBy(final IFunction by, final Object object) {
return (Function)((Function)FnObject.greaterThanBy(by, object));
}
/**
*
* Determines whether the result of executing the specified function
* on the target object is greater or equal to the specified object parameter
* in value, this is, whether functionResult.compareTo(object) >= 0. Both
* the target and the specified object have to implement {@link Comparable}.
*
*
* @param object the object to compare to the target
* @return true if function result is greater or equal to the specified object, false if not
*
* @since 1.1
*/
public static final Function greaterOrEqToBy(final IFunction by, final Object object) {
return (Function)((Function)FnObject.greaterOrEqToBy(by, object));
}
/**
*
* Determines whether the target object is null or not.
*
*
* @return true if the target object is null, false if not.
*/
public static final Function isNull() {
return (Function)((Function)FnObject.isNull());
}
/**
*
* Determines whether the target object is null or not.
*
*
* @return false if the target object is null, true if not.
*/
public static final Function isNotNull() {
return (Function)((Function)FnObject.isNotNull());
}
// End From FnNumber
/**
*
* It returns the maximum number from an {@link Iterable} input object
*
*
* @return the maximum number
*/
public final static Function, BigDecimal> max() {
return MAX_FUNC;
}
/**
*
* It returns the minimum number from an {@link Iterable} input object
*
*
* @return the minimum number
*/
public final static Function, BigDecimal> min() {
return MIN_FUNC;
}
/**
*
* It returns the sum of all the numbers in the {@link Iterable} input object
*
*
* @return a number equal to the sum of all the elements in the input {@link Iterable}
*/
public final static Function, BigDecimal> sum() {
return SUM_FUNC;
}
/**
*
* It returns the average of all the numbers in the {@link Iterable} input object
*
*
* @return a number representing the average of the input numbers
*/
public final static Function, BigDecimal> avg() {
return AVG_FUNC;
}
/**
*
* It returns the average of all the numbers in the {@link Iterable} input object. The
* given {@link MathContext} will be used to round and set the output precision
*
*
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* of the average
*
* @return a number representing the average
*/
public final static Function, BigDecimal> avg(MathContext mathContext) {
return new Avg(mathContext);
}
/**
*
* It returns the average of all the numbers in the {@link Iterable} input object. The
* given {@link RoundingMode} will be used to round the output
*
*
* @param roundingMode the {@link RoundingMode} to round the average
*
* @return a number representing the average
*/
public final static Function, BigDecimal> avg(RoundingMode roundingMode) {
return new Avg(roundingMode);
}
/**
*
* It returns the maximum number from the input array
*
*
* @return the maximum number
*/
public final static Function maxArray() {
return MAX_ARRAY_FUNC;
}
/**
*
* It returns the minimum number from the input array
*
*
* @return the minimum number
*/
public final static Function minArray() {
return MIN_ARRAY_FUNC;
}
/**
*
* It returns the sum of all the numbers in the input array
*
*
* @return a number equal to the sum of all the elements in the input array
*/
public final static Function sumArray() {
return SUM_ARRAY_FUNC;
}
/**
*
* It returns the average of all the numbers in the input array
*
*
* @return a number representing the average of the input numbers
*/
public final static Function avgArray() {
return AVG_ARRAY_FUNC;
}
/**
*
* It returns the average of all the numbers in the input array. The
* given {@link MathContext} will be used to round and set the output precision
*
*
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* of the average
*
* @return a number representing the average
*/
public final static Function avgArray(MathContext mathContext) {
return new AvgArray(mathContext);
}
/**
*
* It returns the average of all the numbers in the input array. The
* given {@link RoundingMode} will be used to round the output
*
*
* @param roundingMode the {@link RoundingMode} to round the average
*
* @return a number representing the average
*/
public final static Function avgArray(RoundingMode roundingMode) {
return new AvgArray(roundingMode);
}
/**
*
* It rounds the input number with the given {@link MathContext}
*
*
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the input rounded
*/
public final static Function round(MathContext mathContext) {
return new Round(mathContext);
}
/**
*
* It rounds the input number with the given {@link RoundingMode}
*
*
* @param roundingMode the {@link RoundingMode}
* @return the input rounded
*/
public final static Function round(RoundingMode roundingMode) {
return new Round(roundingMode);
}
/**
*
* It returns the absolute value of the input
*
*
* @return the absolute value of the input
*/
public final static Function abs() {
return ABS_FUNC;
}
/**
*
* It adds the given number to the target and returns the result
*
*
* @param add value to be added to the target
* @return the result of the addition of add to the target number
*/
public final static Function add(Number add) {
return new Add(fromNumber(add));
}
/**
*
* It adds the given number to the target and returns the result
*
*
* @param add value to be added to the target
* @return the result of the addition of add to the target number
*/
public final static Function add(byte add) {
return add(Byte.valueOf(add));
}
/**
*
* It adds the given number to the target and returns the result
*
*
* @param add value to be added to the target
* @return the result of the addition of add to the target number
*/
public final static Function add(short add) {
return add(Short.valueOf(add));
}
/**
*
* It adds the given number to the target and returns the result
*
*
* @param add value to be added to the target
* @return the result of the addition of add to the target number
*/
public final static Function add(int add) {
return add(Integer.valueOf(add));
}
/**
*
* It adds the given number to the target and returns the result
*
*
* @param add value to be added to the target
* @return the result of the addition of add to the target number
*/
public final static Function add(long add) {
return add(Long.valueOf(add));
}
/**
*
* It adds the given number to the target and returns the result
*
*
* @param add value to be added to the target
* @return the result of the addition of add to the target number
*/
public final static Function add(float add) {
return add(Float.valueOf(add));
}
/**
*
* It adds the given number to the target and returns the result
*
*
* @param add value to be added to the target
* @return the result of the addition of add to the target number
*/
public final static Function add(double add) {
return add(Double.valueOf(add));
}
/**
*
* It subtracts the given number from the target and returns the result
*
*
* @param subtract number to be subtracted from the target
* @return the result of the subtraction
*/
public final static Function subtract(Number subtract) {
return new Subtract(fromNumber(subtract));
}
/**
*
* It subtracts the given number from the target and returns the result
*
*
* @param subtract number to be subtracted from the target
* @return the result of the subtraction
*/
public final static Function subtract(byte subtract) {
return subtract(Byte.valueOf(subtract));
}
/**
*
* It subtracts the given number from the target and returns the result
*
*
* @param subtract number to be subtracted from the target
* @return the result of the subtraction
*/
public final static Function subtract(short subtract) {
return subtract(Short.valueOf(subtract));
}
/**
*
* It subtracts the given number from the target and returns the result
*
*
* @param subtract number to be subtracted from the target
* @return the result of the subtraction
*/
public final static Function subtract(int subtract) {
return subtract(Integer.valueOf(subtract));
}
/**
*
* It subtracts the given number from the target and returns the result
*
*
* @param subtract number to be subtracted from the target
* @return the result of the subtraction
*/
public final static Function subtract(long subtract) {
return subtract(Long.valueOf(subtract));
}
/**
*
* It subtracts the given number from the target and returns the result
*
*
* @param subtract number to be subtracted from the target
* @return the result of the subtraction
*/
public final static Function subtract(float subtract) {
return subtract(Float.valueOf(subtract));
}
/**
*
* It subtracts the given number from the target and returns the result
*
*
* @param subtract number to be subtracted from the target
* @return the result of the subtraction
*/
public final static Function subtract(double subtract) {
return subtract(Double.valueOf(subtract));
}
/**
*
* It divides the target element by the given divisor and returns its result
*
*
* @param divisor the divisor
* @return the result of target/divisor
*/
public final static Function divideBy(Number divisor) {
return new Divide(fromNumber(divisor));
}
/**
*
* It divides the target element by the given divisor and returns its result
*
*
* @param divisor the divisor
* @return the result of target/divisor
*/
public final static Function divideBy(byte divisor) {
return divideBy(Byte.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns its result
*
*
* @param divisor the divisor
* @return the result of target/divisor
*/
public final static Function divideBy(short divisor) {
return divideBy(Short.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns its result
*
*
* @param divisor the divisor
* @return the result of target/divisor
*/
public final static Function divideBy(int divisor) {
return divideBy(Integer.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns its result
*
*
* @param divisor the divisor
* @return the result of target/divisor
*/
public final static Function divideBy(long divisor) {
return divideBy(Long.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns its result
*
*
* @param divisor the divisor
* @return the result of target/divisor
*/
public final static Function divideBy(float divisor) {
return divideBy(Float.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns its result
*
*
* @param divisor the divisor
* @return the result of target/divisor
*/
public final static Function divideBy(double divisor) {
return divideBy(Double.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns its result with the
* precision and rounding mode specified by mathContext
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target/divisor
*/
public final static Function divideBy(Number divisor, MathContext mathContext) {
return new Divide(fromNumber(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns its result with the
* precision and rounding mode specified by mathContext
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target/divisor
*/
public final static Function divideBy(byte divisor, MathContext mathContext) {
return divideBy(Byte.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns its result with the
* precision and rounding mode specified by mathContext
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target/divisor
*/
public final static Function divideBy(short divisor, MathContext mathContext) {
return divideBy(Short.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns its result with the
* precision and rounding mode specified by mathContext
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target/divisor
*/
public final static Function divideBy(int divisor, MathContext mathContext) {
return divideBy(Integer.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns its result with the
* precision and rounding mode specified by mathContext
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target/divisor
*/
public final static Function divideBy(long divisor, MathContext mathContext) {
return divideBy(Long.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns its result with the
* precision and rounding mode specified by mathContext
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target/divisor
*/
public final static Function divideBy(float divisor, MathContext mathContext) {
return divideBy(Float.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns its result with the
* precision and rounding mode specified by mathContext
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target/divisor
*/
public final static Function divideBy(double divisor, MathContext mathContext) {
return divideBy(Double.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns its result rounded
* based on the specified rounding mode
*
*
* @param divisor the divisor
* @param roundingMode the {@link RoundingMode}
* @return the result of target/divisor
*/
public final static Function divideBy(Number divisor, RoundingMode roundingMode) {
return new Divide(fromNumber(divisor), roundingMode);
}
/**
*
* It divides the target element by the given divisor and returns its result rounded
* based on the specified rounding mode
*
*
* @param divisor the divisor
* @param roundingMode the {@link RoundingMode}
* @return the result of target/divisor
*/
public final static Function divideBy(byte divisor, RoundingMode roundingMode) {
return divideBy(Byte.valueOf(divisor), roundingMode);
}
/**
*
* It divides the target element by the given divisor and returns its result rounded
* based on the specified rounding mode
*
*
* @param divisor the divisor
* @param roundingMode the {@link RoundingMode}
* @return the result of target/divisor
*/
public final static Function divideBy(short divisor, RoundingMode roundingMode) {
return divideBy(Short.valueOf(divisor), roundingMode);
}
/**
*
* It divides the target element by the given divisor and returns its result rounded
* based on the specified rounding mode
*
*
* @param divisor the divisor
* @param roundingMode the {@link RoundingMode}
* @return the result of target/divisor
*/
public final static Function divideBy(int divisor, RoundingMode roundingMode) {
return divideBy(Integer.valueOf(divisor), roundingMode);
}
/**
*
* It divides the target element by the given divisor and returns its result rounded
* based on the specified rounding mode
*
*
* @param divisor the divisor
* @param roundingMode the {@link RoundingMode}
* @return the result of target/divisor
*/
public final static Function divideBy(long divisor, RoundingMode roundingMode) {
return divideBy(Long.valueOf(divisor), roundingMode);
}
/**
*
* It divides the target element by the given divisor and returns its result rounded
* based on the specified rounding mode
*
*
* @param divisor the divisor
* @param roundingMode the {@link RoundingMode}
* @return the result of target/divisor
*/
public final static Function divideBy(float divisor, RoundingMode roundingMode) {
return divideBy(Float.valueOf(divisor), roundingMode);
}
/**
*
* It divides the target element by the given divisor and returns its result rounded
* based on the specified rounding mode
*
*
* @param divisor the divisor
* @param roundingMode the {@link RoundingMode}
* @return the result of target/divisor
*/
public final static Function divideBy(double divisor, RoundingMode roundingMode) {
return divideBy(Double.valueOf(divisor), roundingMode);
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor)
*
*
* @param divisor the divisor
* @return the remainder of target/divisor
*/
public final static Function remainder(Number divisor) {
return new Remainder(fromNumber(divisor));
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor)
*
*
* @param divisor the divisor
* @return the remainder of target/divisor
*/
public final static Function remainder(byte divisor) {
return remainder(Byte.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor)
*
*
* @param divisor the divisor
* @return the remainder of target/divisor
*/
public final static Function remainder(short divisor) {
return remainder(Short.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor)
*
*
* @param divisor the divisor
* @return the remainder of target/divisor
*/
public final static Function remainder(int divisor) {
return remainder(Integer.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor)
*
*
* @param divisor the divisor
* @return the remainder of target/divisor
*/
public final static Function remainder(long divisor) {
return remainder(Long.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor)
*
*
* @param divisor the divisor
* @return the remainder of target/divisor
*/
public final static Function remainder(float divisor) {
return remainder(Float.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor)
*
*
* @param divisor the divisor
* @return the remainder of target/divisor
*/
public final static Function remainder(double divisor) {
return remainder(Double.valueOf(divisor));
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor). The remainder precision and {@link RoundingMode}
* is specified by the given {@link MathContext}
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the remainder of target/divisor
*/
public final static Function remainder(Number divisor, MathContext mathContext) {
return new Remainder(fromNumber(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor). The remainder precision and {@link RoundingMode}
* is specified by the given {@link MathContext}
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the remainder of target/divisor
*/
public final static Function remainder(byte divisor, MathContext mathContext) {
return remainder(Byte.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor). The remainder precision and {@link RoundingMode}
* is specified by the given {@link MathContext}
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the remainder of target/divisor
*/
public final static Function remainder(short divisor, MathContext mathContext) {
return remainder(Short.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor). The remainder precision and {@link RoundingMode}
* is specified by the given {@link MathContext}
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the remainder of target/divisor
*/
public final static Function remainder(int divisor, MathContext mathContext) {
return remainder(Integer.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor). The remainder precision and {@link RoundingMode}
* is specified by the given {@link MathContext}
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the remainder of target/divisor
*/
public final static Function remainder(long divisor, MathContext mathContext) {
return remainder(Long.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor). The remainder precision and {@link RoundingMode}
* is specified by the given {@link MathContext}
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the remainder of target/divisor
*/
public final static Function remainder(float divisor, MathContext mathContext) {
return remainder(Float.valueOf(divisor), mathContext);
}
/**
*
* It divides the target element by the given divisor and returns the
* remainder (target % divisor). The remainder precision and {@link RoundingMode}
* is specified by the given {@link MathContext}
*
*
* @param divisor the divisor
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the remainder of target/divisor
*/
public final static Function remainder(double divisor, MathContext mathContext) {
return remainder(Double.valueOf(divisor), mathContext);
}
/**
*
* It multiplies target by multiplicand and returns its value
*
*
* @param multiplicand the multiplicand
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(Number multiplicand) {
return new Multiply(fromNumber(multiplicand));
}
/**
*
* It multiplies target by multiplicand and returns its value
*
*
* @param multiplicand the multiplicand
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(byte multiplicand) {
return multiplyBy(Byte.valueOf(multiplicand));
}
/**
*
* It multiplies target by multiplicand and returns its value
*
*
* @param multiplicand the multiplicand
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(short multiplicand) {
return multiplyBy(Short.valueOf(multiplicand));
}
/**
*
* It multiplies target by multiplicand and returns its value
*
*
* @param multiplicand the multiplicand
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(int multiplicand) {
return multiplyBy(Integer.valueOf(multiplicand));
}
/**
*
* It multiplies target by multiplicand and returns its value
*
*
* @param multiplicand the multiplicand
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(long multiplicand) {
return multiplyBy(Long.valueOf(multiplicand));
}
/**
*
* It multiplies target by multiplicand and returns its value
*
*
* @param multiplicand the multiplicand
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(float multiplicand) {
return multiplyBy(Float.valueOf(multiplicand));
}
/**
*
* It multiplies target by multiplicand and returns its value
*
*
* @param multiplicand the multiplicand
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(double multiplicand) {
return multiplyBy(Double.valueOf(multiplicand));
}
/**
*
* It multiplies target by multiplicand and returns its value. The result precision
* and {@link RoundingMode} is specified by the given {@link MathContext}
*
*
* @param multiplicand the multiplicand
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(Number multiplicand, MathContext mathContext) {
return new Multiply(fromNumber(multiplicand), mathContext);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result precision
* and {@link RoundingMode} is specified by the given {@link MathContext}
*
*
* @param multiplicand the multiplicand
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(byte multiplicand, MathContext mathContext) {
return multiplyBy(Byte.valueOf(multiplicand), mathContext);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result precision
* and {@link RoundingMode} is specified by the given {@link MathContext}
*
*
* @param multiplicand the multiplicand
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(short multiplicand, MathContext mathContext) {
return multiplyBy(Short.valueOf(multiplicand), mathContext);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result precision
* and {@link RoundingMode} is specified by the given {@link MathContext}
*
*
* @param multiplicand the multiplicand
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(int multiplicand, MathContext mathContext) {
return multiplyBy(Integer.valueOf(multiplicand), mathContext);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result precision
* and {@link RoundingMode} is specified by the given {@link MathContext}
*
*
* @param multiplicand the multiplicand
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(long multiplicand, MathContext mathContext) {
return multiplyBy(Long.valueOf(multiplicand), mathContext);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result precision
* and {@link RoundingMode} is specified by the given {@link MathContext}
*
*
* @param multiplicand the multiplicand
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(float multiplicand, MathContext mathContext) {
return multiplyBy(Float.valueOf(multiplicand), mathContext);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result precision
* and {@link RoundingMode} is specified by the given {@link MathContext}
*
*
* @param multiplicand the multiplicand
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(double multiplicand, MathContext mathContext) {
return multiplyBy(Double.valueOf(multiplicand), mathContext);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result is
* rounded based on the given {@link RoundingMode}
*
*
* @param multiplicand the multiplicand
* @param roundingMode the {@link RoundingMode}
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(Number multiplicand, RoundingMode roundingMode) {
return new Multiply(fromNumber(multiplicand), roundingMode);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result is
* rounded based on the given {@link RoundingMode}
*
*
* @param multiplicand the multiplicand
* @param roundingMode the {@link RoundingMode}
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(byte multiplicand, RoundingMode roundingMode) {
return multiplyBy(Byte.valueOf(multiplicand), roundingMode);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result is
* rounded based on the given {@link RoundingMode}
*
*
* @param multiplicand the multiplicand
* @param roundingMode the {@link RoundingMode}
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(short multiplicand, RoundingMode roundingMode) {
return multiplyBy(Short.valueOf(multiplicand), roundingMode);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result is
* rounded based on the given {@link RoundingMode}
*
*
* @param multiplicand the multiplicand
* @param roundingMode the {@link RoundingMode}
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(int multiplicand, RoundingMode roundingMode) {
return multiplyBy(Integer.valueOf(multiplicand), roundingMode);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result is
* rounded based on the given {@link RoundingMode}
*
*
* @param multiplicand the multiplicand
* @param roundingMode the {@link RoundingMode}
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(long multiplicand, RoundingMode roundingMode) {
return multiplyBy(Long.valueOf(multiplicand), roundingMode);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result is
* rounded based on the given {@link RoundingMode}
*
*
* @param multiplicand the multiplicand
* @param roundingMode the {@link RoundingMode}
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(float multiplicand, RoundingMode roundingMode) {
return multiplyBy(Float.valueOf(multiplicand), roundingMode);
}
/**
*
* It multiplies target by multiplicand and returns its value. The result is
* rounded based on the given {@link RoundingMode}
*
*
* @param multiplicand the multiplicand
* @param roundingMode the {@link RoundingMode}
* @return the result of target * multiplicand
*/
public final static Function multiplyBy(double multiplicand, RoundingMode roundingMode) {
return multiplyBy(Double.valueOf(multiplicand), roundingMode);
}
/**
*
* It performs the operation targetpower and returns its value
*
*
* @param power the power to raise the target to
* @return the result of targetpower
*/
public final static Function pow(int power) {
return new Pow(power);
}
/**
*
* It performs the operation targetpower and returns its value. The result
* precision and rounding mode is specified by the given {@link MathContext}
*
*
* @param power the power to raise the target to
* @param mathContext the {@link MathContext} to specify precision and {@link RoundingMode}
* @return the result of targetpower
*/
public final static Function pow(int power, MathContext mathContext) {
return new Pow(power, mathContext);
}
/**
*
* It performs the operation targetpower and returns its value. The result
* rounding mode is specified by the given {@link RoundingMode}
*
*
* @param power the power to raise the target to
* @param roundingMode the {@link RoundingMode}
* @return the result of targetpower
*/
public final static Function pow(int power, RoundingMode roundingMode) {
return new Pow(power, roundingMode);
}
/**
*
* Determines whether the target object is between min and max
* in value, this is, whether
* target.compareTo(min) >= 0 && target.compareTo(max) <= 0.
* The target and the specified min and max have to implement {@link Comparable}.
*
*
* @param min the minimum value of the target
* @param max the maximum value of the target
* @return true if the target is between min and max (or it's equal to any of them)
*/
public static final Function between(final Number min, final Number max) {
return (Function)((Function)FnObject.between(min, max));
}
private static BigDecimal fromNumber(final Number number) {
if (number == null) {
return null;
}
if (number instanceof BigDecimal) {
return (BigDecimal) number;
}
if (number instanceof BigInteger) {
return new BigDecimal((BigInteger)number);
}
return BigDecimal.valueOf(number.doubleValue());
}
static final class Max extends AbstractNotNullFunction,BigDecimal> {
Max() {
super();
}
@Override
protected BigDecimal notNullExecute(final Iterable input, final ExecCtx ctx) throws Exception {
if (input.iterator().hasNext() == false) {
return null;
}
BigDecimal max = input.iterator().next();
for (BigDecimal number : input) {
if (number != null) {
if (number.compareTo(max) > 0) {
max = number;
}
}
}
return max;
}
}
static final class Min extends AbstractNotNullFunction,BigDecimal> {
Min() {
super();
}
@Override
protected BigDecimal notNullExecute(final Iterable input, final ExecCtx ctx) throws Exception {
if (input.iterator().hasNext() == false) {
return null;
}
BigDecimal min = input.iterator().next();
for (BigDecimal number : input) {
if (number != null) {
if (number.compareTo(min) < 0) {
min = number;
}
}
}
return min;
}
}
static final class Sum extends AbstractNotNullFunction,BigDecimal> {
Sum() {
super();
}
@Override
protected BigDecimal notNullExecute(final Iterable input, final ExecCtx ctx) throws Exception {
BigDecimal sum = BigDecimal.valueOf(0);
for (BigDecimal number : input) {
if (number != null) {
sum = sum.add(number);
}
}
return sum;
}
}
static final class Avg extends AbstractNotNullFunction,BigDecimal> {
private final RoundingMode roundingMode;
private final MathContext mathContext;
Avg() {
super();
this.roundingMode = null;
this.mathContext = null;
}
Avg(RoundingMode roundingMode) {
super();
Validate.notNull(roundingMode, "RoundingMode can't be null");
this.roundingMode = roundingMode;
this.mathContext = null;
}
Avg(MathContext mathContext) {
super();
Validate.notNull(mathContext, "MathContext can't be null");
this.roundingMode = null;
this.mathContext = mathContext;
}
@Override
protected BigDecimal notNullExecute(final Iterable input, final ExecCtx ctx) throws Exception {
int countNotNull = 0;
BigDecimal sum = BigDecimal.valueOf(0);
for (BigDecimal number : input) {
if (number != null) {
sum = sum.add(number);
countNotNull++;
}
}
if (this.roundingMode != null) {
return sum.divide(BigDecimal.valueOf(countNotNull), this.roundingMode);
}
if (this.mathContext != null) {
return sum.divide(BigDecimal.valueOf(countNotNull), this.mathContext);
}
return sum.divide(BigDecimal.valueOf(countNotNull), RoundingMode.DOWN);
}
}
static final class MaxArray extends AbstractNotNullFunction {
MaxArray() {
super();
}
@Override
protected BigDecimal notNullExecute(final BigDecimal[] input, final ExecCtx ctx) throws Exception {
if (input.length == 0) {
return null;
}
BigDecimal max = input[0];
for (BigDecimal number : input) {
if (number != null) {
if (number.compareTo(max) > 0) {
max = number;
}
}
}
return max;
}
}
static final class MinArray extends AbstractNotNullFunction {
MinArray() {
super();
}
@Override
protected BigDecimal notNullExecute(final BigDecimal[] input, final ExecCtx ctx) throws Exception {
if (input.length == 0) {
return null;
}
BigDecimal min = input[0];
for (BigDecimal number : input) {
if (number != null) {
if (number.compareTo(min) < 0) {
min = number;
}
}
}
return min;
}
}
static final class SumArray extends AbstractNotNullFunction {
SumArray() {
super();
}
@Override
protected BigDecimal notNullExecute(final BigDecimal[] input, final ExecCtx ctx) throws Exception {
BigDecimal sum = BigDecimal.valueOf(0);
for (BigDecimal number : input) {
if (number != null) {
sum = sum.add(number);
}
}
return sum;
}
}
static final class AvgArray extends AbstractNotNullFunction {
private final RoundingMode roundingMode;
private final MathContext mathContext;
AvgArray() {
super();
this.roundingMode = null;
this.mathContext = null;
}
AvgArray(RoundingMode roundingMode) {
super();
Validate.notNull(roundingMode, "RoundingMode can't be null");
this.roundingMode = roundingMode;
this.mathContext = null;
}
AvgArray(MathContext mathContext) {
super();
Validate.notNull(mathContext, "MathContext can't be null");
this.roundingMode = null;
this.mathContext = mathContext;
}
@Override
protected BigDecimal notNullExecute(final BigDecimal[] input, final ExecCtx ctx) throws Exception {
int countNotNull = 0;
BigDecimal sum = BigDecimal.valueOf(0);
for (BigDecimal number : input) {
if (number != null) {
sum = sum.add(number);
countNotNull++;
}
}
if (this.roundingMode != null) {
return sum.divide(BigDecimal.valueOf(countNotNull), this.roundingMode);
}
if (this.mathContext != null) {
return sum.divide(BigDecimal.valueOf(countNotNull), this.mathContext);
}
return sum.divide(BigDecimal.valueOf(countNotNull), RoundingMode.DOWN);
}
}
static final class Round extends AbstractNullAsNullFunction {
private final MathContext mathContext;
private final RoundingMode roundingMode;
Round(RoundingMode roundingMode) {
super();
Validate.notNull(roundingMode, "RoundingMode can't be null");
this.mathContext = null;
this.roundingMode = roundingMode;
}
Round(MathContext mathContext) {
super();
Validate.notNull(mathContext, "MathContext can't be null");
this.mathContext = mathContext;
this.roundingMode = null;
}
@Override
protected BigDecimal nullAsNullExecute(final BigDecimal input, final ExecCtx ctx) throws Exception {
BigDecimal result = input;
if (this.roundingMode != null) {
return result.setScale(0, this.roundingMode);
}
return result.round(this.mathContext);
}
}
static final class Abs extends AbstractNullAsNullFunction {
Abs() {
super();
}
@Override
protected BigDecimal nullAsNullExecute(final BigDecimal input, final ExecCtx ctx) throws Exception {
return input.abs();
}
}
static final class Add extends AbstractNullAsNullFunction {
private final BigDecimal add;
Add(BigDecimal add) {
super();
Validate.notNull(add, "Number to be added can't be null");
this.add = add;
}
@Override
protected BigDecimal nullAsNullExecute(final BigDecimal input, final ExecCtx ctx) throws Exception {
BigDecimal result = input;
result = result.add(this.add);
return result;
}
}
static final class Subtract extends AbstractNullAsNullFunction {
private final BigDecimal subtract;
Subtract(BigDecimal subtract) {
super();
Validate.notNull(subtract, "Number to be subtracted can't be null");
Validate.notNull(subtract, "Number to be added can't be null");
this.subtract = subtract;
}
@Override
protected BigDecimal nullAsNullExecute(final BigDecimal input, final ExecCtx ctx) throws Exception {
BigDecimal result = input;
result = result.subtract(this.subtract);
return result;
}
}
static final class Divide extends AbstractNullAsNullFunction {
private final BigDecimal divisor;
private final RoundingMode roundingMode;
private final MathContext mathContext;
Divide(BigDecimal divisor) {
super();
Validate.notNull(divisor, "Divisor can't be null");
this.divisor = divisor;
this.roundingMode = null;
this.mathContext = null;
}
Divide(BigDecimal divisor, RoundingMode roundingMode) {
super();
Validate.notNull(divisor, "Divisor can't be null");
Validate.notNull(roundingMode, "RoundingMode can't be null");
this.divisor = divisor;
this.roundingMode = roundingMode;
this.mathContext = null;
}
Divide(BigDecimal divisor, MathContext mathContext) {
super();
Validate.notNull(divisor, "Divisor can't be null");
Validate.notNull(mathContext, "MathContext can't be null");
this.divisor = divisor;
this.roundingMode = null;
this.mathContext = mathContext;
}
@Override
protected BigDecimal nullAsNullExecute(final BigDecimal input, final ExecCtx ctx) throws Exception {
BigDecimal result = input;
if (this.roundingMode != null) {
result = result.divide(this.divisor, this.roundingMode);
} else if (this.mathContext != null) {
result = result.divide(this.divisor, this.mathContext);
} else {
result = result.divide(this.divisor, RoundingMode.DOWN);
}
return result;
}
}
static final class Remainder extends AbstractNullAsNullFunction {
private final BigDecimal divisor;
private final MathContext mathContext;
Remainder(BigDecimal divisor) {
super();
this.divisor = divisor;
this.mathContext = null;
}
Remainder(BigDecimal divisor, MathContext mathContext) {
super();
this.divisor = divisor;
this.mathContext = mathContext;
}
@Override
protected BigDecimal nullAsNullExecute(final BigDecimal input, final ExecCtx ctx) throws Exception {
if (this.mathContext != null) {
return input.remainder(this.divisor, this.mathContext);
}
return input.remainder(this.divisor);
}
}
static final class Multiply extends AbstractNullAsNullFunction {
private final BigDecimal multiplicand;
private final MathContext mathContext;
private final RoundingMode roundingMode;
Multiply(BigDecimal multiplicand) {
super();
Validate.notNull(multiplicand, "Multiplicand can't be null");
this.multiplicand = multiplicand;
this.mathContext = null;
this.roundingMode = null;
}
Multiply(BigDecimal multiplicand, RoundingMode roundingMode) {
super();
Validate.notNull(multiplicand, "Multiplicand can't be null");
Validate.notNull(roundingMode, "RoundingMode can't be null");
this.multiplicand = multiplicand;
this.mathContext = null;
this.roundingMode = roundingMode;
}
Multiply(BigDecimal multiplicand, MathContext mathContext) {
super();
Validate.notNull(multiplicand, "Multiplicand can't be null");
Validate.notNull(mathContext, "MathContext can't be null");
this.multiplicand = multiplicand;
this.mathContext = mathContext;
this.roundingMode = null;
}
@Override
protected BigDecimal nullAsNullExecute(final BigDecimal input, final ExecCtx ctx) throws Exception {
BigDecimal result = input;
if (this.mathContext != null) {
result = result.multiply(this.multiplicand, this.mathContext);
} else if (this.roundingMode != null) {
result = result.multiply(this.multiplicand).setScale(0, this.roundingMode);
} else {
result = result.multiply(this.multiplicand);
}
return result;
}
}
static final class Pow extends AbstractNullAsNullFunction {
private final int power;
private final MathContext mathContext;
private final RoundingMode roundingMode;
Pow(int power) {
super();
this.power = power;
this.mathContext = null;
this.roundingMode = null;
}
Pow(int power, RoundingMode roundingMode) {
super();
Validate.notNull(roundingMode, "RoundingMode can't be null");
this.power = power;
this.mathContext = null;
this.roundingMode = roundingMode;
}
Pow(int power, MathContext mathContext) {
super();
Validate.notNull(mathContext, "MathContext can't be null");
this.power = power;
this.mathContext = mathContext;
this.roundingMode = null;
}
@Override
protected BigDecimal nullAsNullExecute(final BigDecimal input, final ExecCtx ctx) throws Exception {
BigDecimal result = input;
if (this.mathContext != null) {
result = result.pow(this.power, this.mathContext);
} else if (this.roundingMode != null) {
result = result.pow(this.power).setScale(0, this.roundingMode);
} else {
result = result.pow(this.power);
}
return result;
}
}
}