From 8b090e1fd20eb4c301996b5e1dfeb78353e595e4 Mon Sep 17 00:00:00 2001 From: ‭huajijam Date: Mon, 18 Mar 2019 20:52:30 +0800 Subject: fix a bug --- src/Java/gtPlusPlus/core/util/math/MathUtils.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util/math') diff --git a/src/Java/gtPlusPlus/core/util/math/MathUtils.java b/src/Java/gtPlusPlus/core/util/math/MathUtils.java index 40ac23a1b8..f9a4d8f548 100644 --- a/src/Java/gtPlusPlus/core/util/math/MathUtils.java +++ b/src/Java/gtPlusPlus/core/util/math/MathUtils.java @@ -463,14 +463,14 @@ public class MathUtils { return 0; } int divisor = aDataSet.length; - Logger.INFO("Calculating Average Short. Divisor: "+divisor); + Logger.WARNING("Calculating Average Short. Divisor: "+divisor); short total = 0; for (short i : aDataSet) { - Logger.INFO("Adding "+i); + Logger.WARNING("Adding "+i); total += i; } short result = safeShort((total/divisor)); - Logger.INFO("Average: "+result); + Logger.WARNING("Average: "+result); return result; } public static int getIntAverage(int[] aDataSet) { @@ -681,4 +681,15 @@ public class MathUtils { return i; } + /** + * Balances a number within a range. + * @param aInput - The number to balance + * @param aMin - The minimum bounds + * @param aMax - The maximum bounds + * @return - An Integer which will be between the bounds, or a boundary value. + */ + public static int balance(int aInput, int aMin, int aMax) { + return Math.max(Math.min(aInput, aMax), aMin); + } + } -- cgit