org.op4j.functions.FnFloat 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.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 FnFloat {
private static final Function, Float> MAX_FUNC = new Max();
private static final Function, Float> MIN_FUNC = new Min();
private static final Function, Float> SUM_FUNC = new Sum();
private static final Function, Float> 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();
FnFloat() {
super();
}
// From FnNumber
/**
*
* 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 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));
}
/**
*
* 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));
}
/**
*
* Determines whether the target object and the specified object are equal
* by calling the equals method on the target object.
*
*
* @param object the {@link Float} to compare to the target
* @return true if both objects are equal, false if not.
*/
public static final Function eq(final Float object) {
return (Function)((Function)FnObject.eq(object));
}
/**
*
* Determines whether the target object and the specified object are equal
* by calling the equals method on the target object.
*
*
* @param object the object to compare to the target
* @return true if both objects are equal, false if not.
*/
public static final Function eq(final float 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 Number object) {
return (Function)((Function)FnObject.eqValue(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 float 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 Float} to compare to the target
* @return false if both objects are equal, true if not.
*/
public static final Function notEq(final Float object) {
return (Function)((Function)FnObject.notEq(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 object to compare to the target
* @return false if both objects are equal, true if not.
*/
public static final Function notEq(final float 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 Number object) {
return (Function)((Function)FnObject.notEqValue(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 float 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 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 float 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 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 float 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 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 float 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 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 float 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 (Function)((Function)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 (Function)((Function)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, Float> max() {
return MAX_FUNC;
}
/**
*
* It returns the minimum number from an {@link Iterable} input object
*
*
* @return the minimum number
*/
public final static Function, Float> 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, Float> 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, Float> 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, Float> 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, Float> 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 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 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));
}
/**
*
* 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 float min, final float max) {
return (Function)((Function)FnObject.between(min, max));
}
private static Float fromNumber(final Number number) {
if (number == null) {
return null;
}
return Float.valueOf(number.floatValue());
}
static final class Max extends AbstractNotNullFunction,Float> {
Max() {
super();
}
@Override
protected Float notNullExecute(final Iterable input, final ExecCtx ctx) throws Exception {
if (input.iterator().hasNext() == false) {
return null;
}
Float max = input.iterator().next();
for (Float number : input) {
if (number != null) {
if (number.compareTo(max) > 0) {
max = number;
}
}
}
return max;
}
}
static final class Min extends AbstractNotNullFunction,Float> {
Min() {
super();
}
@Override
protected Float notNullExecute(final Iterable input, final ExecCtx ctx) throws Exception {
if (input.iterator().hasNext() == false) {
return null;
}
Float min = input.iterator().next();
for (Float number : input) {
if (number != null) {
if (number.compareTo(min) < 0) {
min = number;
}
}
}
return min;
}
}
static final class Sum extends AbstractNotNullFunction,Float> {
Sum() {
super();
}
@Override
protected Float notNullExecute(final Iterable input, final ExecCtx ctx) throws Exception {
BigDecimal sum = BigDecimal.valueOf(0);
for (Float number : input) {
if (number != null) {
sum = sum.add(BigDecimal.valueOf(number.floatValue()));
}
}
return Float.valueOf(sum.floatValue());
}
}
static final class Avg extends AbstractNotNullFunction,Float> {
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 Float notNullExecute(final Iterable input, final ExecCtx ctx) throws Exception {
int countNotNull = 0;
BigDecimal sum = BigDecimal.valueOf(0);
for (Float number : input) {
if (number != null) {
sum = sum.add(BigDecimal.valueOf(number.floatValue()));
countNotNull++;
}
}
if (this.roundingMode != null) {
return Float.valueOf(sum.divide(BigDecimal.valueOf(countNotNull), this.roundingMode).floatValue());
}
if (this.mathContext != null) {
return Float.valueOf(sum.divide(BigDecimal.valueOf(countNotNull), this.mathContext).floatValue());
}
return Float.valueOf(sum.divide(BigDecimal.valueOf(countNotNull), RoundingMode.DOWN).floatValue());
}
}
static final class MaxArray extends AbstractNotNullFunction {
MaxArray() {
super();
}
@Override
protected Float notNullExecute(final Float[] input, final ExecCtx ctx) throws Exception {
if (input.length == 0) {
return null;
}
Float max = input[0];
for (Float number : input) {
if (number != null) {
if (number.compareTo(max) > 0) {
max = number;
}
}
}
return max;
}
}
static final class MinArray extends AbstractNotNullFunction {
MinArray() {
super();
}
@Override
protected Float notNullExecute(final Float[] input, final ExecCtx ctx) throws Exception {
if (input.length == 0) {
return null;
}
Float min = input[0];
for (Float number : input) {
if (number != null) {
if (number.compareTo(min) < 0) {
min = number;
}
}
}
return min;
}
}
static final class SumArray extends AbstractNotNullFunction {
SumArray() {
super();
}
@Override
protected Float notNullExecute(final Float[] input, final ExecCtx ctx) throws Exception {
BigDecimal sum = BigDecimal.valueOf(0);
for (Float number : input) {
if (number != null) {
sum = sum.add(BigDecimal.valueOf(number.floatValue()));
}
}
return Float.valueOf(sum.floatValue());
}
}
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 Float notNullExecute(final Float[] input, final ExecCtx ctx) throws Exception {
int countNotNull = 0;
BigDecimal sum = BigDecimal.valueOf(0);
for (Float number : input) {
if (number != null) {
sum = sum.add(BigDecimal.valueOf(number.floatValue()));
countNotNull++;
}
}
if (this.roundingMode != null) {
return Float.valueOf(sum.divide(BigDecimal.valueOf(countNotNull), this.roundingMode).floatValue());
}
if (this.mathContext != null) {
return Float.valueOf(sum.divide(BigDecimal.valueOf(countNotNull), this.mathContext).floatValue());
}
return Float.valueOf(sum.divide(BigDecimal.valueOf(countNotNull), RoundingMode.DOWN).floatValue());
}
}
static final class Abs extends AbstractNullAsNullFunction {
Abs() {
super();
}
@Override
protected Float nullAsNullExecute(final Float input, final ExecCtx ctx) throws Exception {
return Float.valueOf(Math.abs(input.floatValue()));
}
}
static final class Add extends AbstractNullAsNullFunction {
private final Float add;
Add(Float add) {
super();
Validate.notNull(add, "Number to be added can't be null");
this.add = add;
}
@Override
protected Float nullAsNullExecute(final Float input, final ExecCtx ctx) throws Exception {
BigDecimal result = BigDecimal.valueOf(input.floatValue());
result = result.add(BigDecimal.valueOf(this.add.floatValue()));
return Float.valueOf(result.floatValue());
}
}
static final class Subtract extends AbstractNullAsNullFunction {
private final Float subtract;
Subtract(Float 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 Float nullAsNullExecute(final Float input, final ExecCtx ctx) throws Exception {
BigDecimal result = BigDecimal.valueOf(input.floatValue());
result = result.subtract(BigDecimal.valueOf(this.subtract.floatValue()));
return Float.valueOf(result.floatValue());
}
}
static final class Divide extends AbstractNullAsNullFunction {
private final Float divisor;
private final RoundingMode roundingMode;
private final MathContext mathContext;
Divide(Float divisor) {
super();
Validate.notNull(divisor, "Divisor can't be null");
this.divisor = divisor;
this.roundingMode = null;
this.mathContext = null;
}
Divide(Float 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(Float 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 Float nullAsNullExecute(final Float input, final ExecCtx ctx) throws Exception {
BigDecimal result = BigDecimal.valueOf(input.floatValue());
if (this.roundingMode != null) {
result = result.divide(BigDecimal.valueOf(this.divisor.floatValue()), this.roundingMode);
} else if (this.mathContext != null) {
result = result.divide(BigDecimal.valueOf(this.divisor.floatValue()), this.mathContext);
} else {
result = result.divide(BigDecimal.valueOf(this.divisor.floatValue()), RoundingMode.DOWN);
}
return Float.valueOf(result.floatValue());
}
}
static final class Remainder extends AbstractNullAsNullFunction {
private final Float divisor;
Remainder(Float divisor) {
super();
this.divisor = divisor;
}
@Override
protected Float nullAsNullExecute(final Float input, final ExecCtx ctx) throws Exception {
return Float.valueOf(BigDecimal.valueOf(input.doubleValue())
.remainder(BigDecimal.valueOf(this.divisor.doubleValue())).floatValue());
}
}
static final class Multiply extends AbstractNullAsNullFunction {
private final Float multiplicand;
private final MathContext mathContext;
private final RoundingMode roundingMode;
Multiply(Float multiplicand) {
super();
Validate.notNull(multiplicand, "Multiplicand can't be null");
this.multiplicand = multiplicand;
this.mathContext = null;
this.roundingMode = null;
}
Multiply(Float 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(Float 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 Float nullAsNullExecute(final Float input, final ExecCtx ctx) throws Exception {
BigDecimal result = BigDecimal.valueOf(input.floatValue());
if (this.mathContext != null) {
result = result.multiply(BigDecimal.valueOf(this.multiplicand.floatValue()), this.mathContext);
} else if (this.roundingMode != null) {
result = result.multiply(BigDecimal.valueOf(this.multiplicand.floatValue())).setScale(0, this.roundingMode);
} else {
result = result.multiply(BigDecimal.valueOf(this.multiplicand.floatValue()));
}
return Float.valueOf(result.floatValue());
}
}
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 Float nullAsNullExecute(final Float input, final ExecCtx ctx) throws Exception {
BigDecimal result = BigDecimal.valueOf(input.floatValue());
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 Float.valueOf(result.floatValue());
}
}
}