don't return negative percentage when max < 0

This commit is contained in:
Michael McCandless 2015-04-11 06:02:59 -04:00 committed by mikemccand
parent 90e1775a2b
commit 3cc3390f17
1 changed files with 2 additions and 2 deletions

View File

@ -358,9 +358,9 @@ public class RestNodesAction extends AbstractCatAction {
* Calculate the percentage of {@code used} from the {@code max} number. * Calculate the percentage of {@code used} from the {@code max} number.
* @param used The currently used number. * @param used The currently used number.
* @param max The maximum number. * @param max The maximum number.
* @return 0 if {@code max} is 0. Otherwise 100 * {@code used} / {@code max}. * @return 0 if {@code max} is <= 0. Otherwise 100 * {@code used} / {@code max}.
*/ */
private short calculatePercentage(long used, long max) { private short calculatePercentage(long used, long max) {
return max == 0 ? 0 : (short)((100d * used) / max); return max <= 0 ? 0 : (short)((100d * used) / max);
} }
} }