diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/utils/Chooser.java b/client/src/main/java/com/alibaba/nacos/client/naming/utils/Chooser.java index 883402184..51e4e6b22 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/utils/Chooser.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/utils/Chooser.java @@ -99,13 +99,13 @@ public class Chooser { } public void refresh() { - Double originWeightSum = (double)0; + Double originWeightSum = (double) 0; for (Pair item : itemsWithWeight) { double weight = item.weight(); //ignore item which weight is zero.see test_randomWithWeight_weight0 in ChooserTest - if (!(weight > 0)) { + if (weight <= 0) { continue; } @@ -124,7 +124,7 @@ public class Chooser { for (Pair item : itemsWithWeight) { double singleWeight = item.weight(); //ignore item which weight is zero.see test_randomWithWeight_weight0 in ChooserTest - if (!(singleWeight > 0)) { + if (singleWeight <= 0) { continue; } exactWeights[index++] = singleWeight / originWeightSum; @@ -139,9 +139,9 @@ public class Chooser { double doublePrecisionDelta = 0.0001; if (index == 0 || (Math.abs(weights[index - 1] - 1) < doublePrecisionDelta)) { - throw new IllegalStateException( - "Cumulative Weight caculate wrong , the sum of probabilities does not equals 1."); + return; } + throw new IllegalStateException("Cumulative Weight caculate wrong , the sum of probabilities does not equals 1."); } @Override @@ -164,7 +164,7 @@ public class Chooser { if (!(other.getClass().getGenericInterfaces()[0].equals(this.getClass().getGenericInterfaces()[0]))) { return false; } - Ref otherRef = (Ref)other; + Ref otherRef = (Ref) other; if (itemsWithWeight == null) { if (otherRef.itemsWithWeight != null) { return false; @@ -197,7 +197,7 @@ public class Chooser { return false; } - Chooser otherChooser = (Chooser)other; + Chooser otherChooser = (Chooser) other; if (this.uniqueKey == null) { if (otherChooser.getUniqueKey() != null) { return false;