From 490bdd11a562b665f1b8695d4b8f61f6bb7949a1 Mon Sep 17 00:00:00 2001 From: May Date: Sun, 12 Jul 2020 17:09:15 +0800 Subject: [PATCH] Use Math.min() in ExponentialBackOff Use Math.min() instead of doing it manually in ExponentialBackOff. Closes gh-25381 --- .../springframework/util/backoff/ExponentialBackOff.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java b/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java index b73c00fa69..0331699a5b 100644 --- a/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java +++ b/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -200,8 +200,7 @@ public class ExponentialBackOff implements BackOff { } else if (this.currentInterval < 0) { long initialInterval = getInitialInterval(); - this.currentInterval = (initialInterval < maxInterval - ? initialInterval : maxInterval); + this.currentInterval = Math.min(initialInterval, maxInterval); } else { this.currentInterval = multiplyInterval(maxInterval); @@ -212,7 +211,7 @@ public class ExponentialBackOff implements BackOff { private long multiplyInterval(long maxInterval) { long i = this.currentInterval; i *= getMultiplier(); - return (i > maxInterval ? maxInterval : i); + return Math.min(i, maxInterval); }